private Block createWrapper() { try { if (wrapperClass == null) wrapperClass = ClassMangler.mangle(WaterWrapper.class, waterBlock.getClass()); Constructor<?> cons = wrapperClass.getConstructor(BlockStaticLiquid.class); return (Block) cons.newInstance((BlockStaticLiquid) waterBlock); } catch (Exception ex) { // Here we're going to blanket-catch a whole bunch of exceptions // of which only one has an actual chance of occurring, which is the // invalid mangling exception throw new RuntimeException(ex.getMessage(), ex); } }
private boolean place(World world, boolean isSecondTry) { if (this.isInValid) return false; IBlockState oldState = world.getBlockState(pos); if (!this.onlyEffect) { if (oldState == null) { put(world); return true; } else if (oldState.getBlock() == null) { put(world); return true; } else if (oldState.getBlock().isReplaceable(world, pos)) { put(world); return true; } else if (effect.hasSponge && !isSecondTry) { if (oldState != null && (oldState.getBlock() instanceof BlockStaticLiquid || oldState.getBlock() instanceof IFluidBlock)) { world.setBlockToAir(pos); } return this.place(world, true); } else if (effect.hasBlockBreakingUpgrade && !isSecondTry && oldState.getBlock() != DefenseInit.blockForce) { TomsModUtils.breakBlockWithDrops(world, pos); return this.place(world, true); } else return false; } else if (effect.hasSponge) { if (oldState != null && (oldState.getBlock() instanceof BlockLiquid || oldState.getBlock() instanceof IFluidBlock)) { world.setBlockToAir(pos); } return true; } else if (effect.hasBlockBreakingUpgrade && oldState.getBlock() != DefenseInit.blockForce) { TomsModUtils.breakBlockWithDrops(world, pos); return true; } else return false; }
@Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if (!world.isRemote) { if (stack.getItemDamage() == 0) { int xCoord = NBTHelper.getInt(stack, "xCoord"); int yCoord = NBTHelper.getInt(stack, "yCoord"); int zCoord = NBTHelper.getInt(stack, "zCoord"); int dimNum = NBTHelper.getInt(stack, "dimNum"); World worldTo = DimensionManager.getWorld(dimNum); Block block1 = worldTo.getBlock(xCoord, yCoord, zCoord); Block block2 = worldTo.getBlock(xCoord, yCoord + 1, zCoord); stack.damageItem(499, player); if (yCoord > 0) { if (!block1.isOpaqueCube() && !block2.isOpaqueCube()) { if ((!(block1 instanceof BlockStaticLiquid) && !(block2 instanceof BlockStaticLiquid))) { if (worldTo.equals(world)) { player.worldObj = worldTo; player.setPositionAndUpdate(xCoord + .5, yCoord, zCoord + .5); } else { if (player.timeUntilPortal > 0) player.addChatComponentMessage(new ChatComponentText("Teleport failed: Please wait " + TimeHelper.ticksToSeconds(player.timeUntilPortal) + " second(s) to teleport").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); else TeleportHelper.teleportPlayerToDim(world, dimNum, xCoord + .5, yCoord, zCoord + .5, player); } return stack; } } player.addChatComponentMessage(new ChatComponentText("Teleport failed").setChatStyle(new ChatStyle().setColor(EnumChatFormatting.RED))); } } else { player.addChatComponentMessage(new ChatComponentText("Teleport failed: Cooldown in progress, please wait " + TimeHelper.ticksToSeconds(stack.getItemDamage()) + " second(s)")); } } return stack; }
@Override public ItemStack[] harvestBlock(World world, int x, int y, int z, EntityPlayer player, IToggleController controller) { Block block = world.getBlock(x, y, z); System.out.println(block.getClass().getSimpleName()); if (block instanceof IFluidBlock) { IToggleStorage storage = controller.getStorageHandler(); IFluidBlock fluidBlock = (IFluidBlock) block; FluidStack containing = fluidBlock.drain(world, x, y, z, true); ItemStack emptyContainer = null; for (int s = 0; s < storage.getStorageSlots(); s++) { ItemStack inSlot = storage.getItemFromSlot(s); if (FluidContainerRegistry.isEmptyContainer(inSlot)) { emptyContainer = inSlot; break; } } if (emptyContainer == null) return null; ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(containing, emptyContainer); emptyContainer.stackSize--; return new ItemStack[]{filledContainer}; } else if (block instanceof BlockStaticLiquid) { ItemStack emptyBucket = controller.getStorageHandler().getItemFromStorage(new ItemStack(Items.bucket)); if (emptyBucket != null) { emptyBucket.stackSize--; ItemStack filledBucket = null; if (block == Blocks.water) filledBucket = new ItemStack(Items.water_bucket); else if (block == Blocks.lava) filledBucket = new ItemStack(Items.lava_bucket); world.setBlockToAir(x, y, z); return filledBucket != null ? new ItemStack[]{filledBucket} : null; } } return null; }
@Override public boolean canHarvestBlock(World world, int x, int y, int z, IToggleController controller) { Block block = world.getBlock(x, y, z); System.out.println(block.getClass().getSimpleName()); return (block instanceof IFluidBlock && ((IFluidBlock) block).getFilledPercentage(world, x, y, z) > 0) || block instanceof BlockStaticLiquid; // Block block = world.getBlock(x, y, z); // return block != null && (block == Blocks.water || block == Blocks.lava); /*Block block = world.getBlock(x, y, z); if (block == null) return false; Fluid fromBlock = FluidRegistry.lookupFluidForBlock(block); if (fromBlock == null) return false; if (!FluidRegistry.isFluidRegistered(fromBlock)) return false; ItemStack[] storage = controller.getAllStorage(); ItemStack fluidContainer = null; for (ItemStack stack : storage) if (stack != null) if (FluidContainerRegistry.isEmptyContainer(stack)) if (FluidContainerRegistry.fillFluidContainer(new FluidStack(fromBlock, 1000), stack) != null) fluidContainer = stack.copy(); return fluidContainer != null;*/ }
public static BlockStaticLiquid getStaticBlock(Material materialIn) { if (materialIn == Material.WATER) return SCContent.bogusWater; else if (materialIn == Material.LAVA) return SCContent.bogusLava; else throw new IllegalArgumentException("Invalid material"); }
public static BlockStaticLiquid getStaticBlock(Material materialIn) { if (materialIn == Material.water) return SCContent.bogusWater; else if (materialIn == Material.lava) return SCContent.bogusLava; else throw new IllegalArgumentException("Invalid material"); }
private boolean isLiquid(BlockPos p) { IMeeCreep entity = helper.getMeeCreep(); Block block = entity.getWorld().getBlockState(p).getBlock(); return block instanceof BlockLiquid || block instanceof BlockDynamicLiquid || block instanceof BlockStaticLiquid; }
@SuppressWarnings("deprecation") public void breakBlock(EnumFacing facing) { BlockPos newPos = pos.offset(facing, 1); IBlockState state = this.world.getBlockState(newPos); Block block = state.getBlock(); if (!block.isAir(state, this.world, newPos) && block.getBlockHardness(state, this.world, newPos) >= 0 && !(block instanceof BlockDynamicLiquid) && !(block instanceof BlockStaticLiquid)) { // Creates a fake player which will berak the block EntityPlayer player = new EntityPlayer(world, new GameProfile(null, "BlockBreaker")) { @Override public boolean isSpectator() { return true; } @Override public boolean isCreative() { return false; } }; List<ItemStack> drops = new ArrayList<ItemStack>(); boolean customDrops = false; if (this.handler.getStackInSlot(9).getItem() == Items.ENCHANTED_BOOK) { ItemStack enchantedBook = this.handler.getStackInSlot(9); Map<Enchantment, Integer> enchantments = EnchantmentHelper.getEnchantments(enchantedBook); if (enchantments.containsKey(Enchantments.FORTUNE)) { int fortune = enchantments.get(Enchantments.FORTUNE); drops.add(new ItemStack(block.getItemDropped(state, this.random, fortune), block.quantityDroppedWithBonus(fortune, this.random), block.damageDropped(state))); customDrops = true; } if (enchantments.containsKey(Enchantments.SILK_TOUCH) && block.canSilkHarvest(world, newPos, state, player)) { // HARD FIX FOR LAPIS if (block == Blocks.LAPIS_ORE) drops.add(new ItemStack(block, 1)); else drops.add(new ItemStack(block, 1, block.damageDropped(state))); customDrops = true; } } if (!customDrops) drops = block.getDrops(world, newPos, state, 0); for (ItemStack stack : drops) { Utils.addStackToInventory(this.handler, 9, stack, false); } if (!Utils.isInventoryFull(this.handler, 9)) { this.world.playEvent(2001, pos, Block.getStateId(state)); this.world.playSound(null, pos, block.getSoundType(state, world, newPos, player).getBreakSound(), SoundCategory.BLOCKS, 1, 1); this.world.setBlockToAir(newPos); if (block == Blocks.ICE) this.world.setBlockState(newPos, Blocks.FLOWING_WATER.getDefaultState()); } } }
@SuppressWarnings("unchecked") private static void examineBlock(IBitAccess bits, Minecraft mc, String[][][] textures, String[][][] tints, Features features, boolean sneaking) { for(int x=0; x<16; x++) { for(int y=0; y<16; y++) { for(int z=0; z<16; z++) { IBlockState state = bits.getBitAt(x,y,z).getState(); if (state != null) { String texture = "error"; String tint = "FFFFFF"; IBakedModel model = mc.getBlockRendererDispatcher().getBlockModelShapes().getModelForState(state); if (model != null && model.getParticleTexture() != null && model.getParticleTexture().getIconName() != null) { texture = model.getParticleTexture().getIconName(); } Block tBlock = state.getBlock(); if (tBlock != null) { Fluid fluid = null; if (state.getLightValue() > features.lightLevel) features.lightLevel = state.getLightValue(); if (tBlock instanceof IFluidBlock) { fluid = ((IFluidBlock) tBlock).getFluid(); } else if (tBlock instanceof BlockStaticLiquid) { if (tBlock.getUnlocalizedName().equals("tile.water")) fluid = FluidRegistry.getFluid("water"); else if (tBlock.getUnlocalizedName().equals("tile.lava")) fluid = FluidRegistry.getFluid("lava"); } if (fluid != null) { features.hasFluids = true; texture = sneaking?fluid.getFlowing().toString():fluid.getStill().toString(); tint = colorToString(fluid.getColor()); } if (tBlock.getClass().getCanonicalName().startsWith("mod.flatcoloredblocks.block.BlockFlatColored")) { // Ugh... Class c = tBlock.getClass(); Method m = null; Class pTypes[] = new Class[1]; pTypes[0] = IBlockState.class; try { m = c.getMethod("colorFromState", pTypes); } catch (NoSuchMethodException e) {} if (m != null) { Object params[] = new Object[1]; params[0] = state; try { //String col = (String)(m.invoke(tblock, params)); int col = (int) (m.invoke(tBlock, params)); tint = colorToString(col); } catch (InvocationTargetException ite) {} catch (IllegalAccessException iae) {} catch (ClassCastException ce) {} } } } textures[x][y][z] = texture; tints[x][y][z] = tint; } } } } }
protected void dropInventory(World world, int x, int y, int z) { TileEntity tileEntity = world.getTileEntity(x, y, z); if (!(tileEntity instanceof IInventory)) { return; } IInventory inventory = (IInventory) tileEntity; for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack itemStack = inventory.getStackInSlot(i); if (itemStack != null && itemStack.stackSize > 0) { if (itemStack.getItem() instanceof ItemBlock) { if (((ItemBlock) itemStack.getItem()).field_150939_a instanceof BlockFluidBase || ((ItemBlock) itemStack.getItem()).field_150939_a instanceof BlockStaticLiquid || ((ItemBlock) itemStack.getItem()).field_150939_a instanceof BlockDynamicLiquid) { return; } } Random rand = new Random(); float dX = rand.nextFloat() * 0.8F + 0.1F; float dY = rand.nextFloat() * 0.8F + 0.1F; float dZ = rand.nextFloat() * 0.8F + 0.1F; EntityItem entityItem = new EntityItem(world, x + dX, y + dY, z + dZ, itemStack.copy()); if (itemStack.hasTagCompound()) { entityItem.getEntityItem().setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy()); } float factor = 0.05F; entityItem.motionX = rand.nextGaussian() * factor; entityItem.motionY = rand.nextGaussian() * factor + 0.2F; entityItem.motionZ = rand.nextGaussian() * factor; world.spawnEntityInWorld(entityItem); itemStack.stackSize = 0; } } }
private int getTopBlock( World pWorld, int pLocX, int pLocZ ) { Chunk tChunk = pWorld.getChunkFromBlockCoords( pLocX, pLocZ ); int y = tChunk.getTopFilledSegment() + 15; int trimmedX = pLocX & 0xF; int trimmedZ = pLocZ & 0xF; for( ; y > 0; y-- ) { Block tBlock = tChunk.getBlock( trimmedX, y, trimmedZ ); if( !tBlock.isAir( pWorld, pLocX, y, pLocZ ) ) { if(tBlock instanceof BlockStaticLiquid) { return y; } if(tBlock instanceof BlockFluidBase) { return y; } if(tBlock instanceof IFluidBlock) { return y; } if( tBlock.getMaterial().blocksMovement() ) { if( !( tBlock instanceof BlockFlower ) ) { return y - 1; } } } } return -1; }
/** * Attempts to get a fluid stack from a block pos. * * @param world The world. * @param pos The position. * @return The fluid stack. */ public static FluidStack getFluid (World world, BlockPos pos) { final IBlockState state = getActualState(world, pos); final Block block = state.getBlock(); if (block instanceof IFluidBlock && ((IFluidBlock) block).canDrain(world, pos)) { return ((IFluidBlock) block).drain(world, pos, true); } else if (block instanceof BlockStaticLiquid && isFluidFull(state)) { final Fluid fluid = block == Blocks.WATER ? FluidRegistry.WATER : block == Blocks.LAVA ? FluidRegistry.LAVA : null; if (fluid != null) { return new FluidStack(fluid, 1000); } } return null; }
public WaterWrapper(BlockStaticLiquid water) { super(water.getMaterial()); this.water = water; }
@SubscribeEvent public void tick( TickEvent.PlayerTickEvent event ) { if ( !event.phase.equals( TickEvent.Phase.END ) ) return; EntityPlayer player = event.player; if ( player.ridingEntity != null ) return; ItemStack boots = player.getEquipmentInSlot( 1 ); if ( boots == null || !( boots.getItem() instanceof ArmorItem ) ) { return; } ArmorItem armor = ( ArmorItem ) boots.getItem(); if ( armor.armor.getModifierLevel( boots, "waterWalk" ) < 1 ) { return; } // Terminal velocity of a player is 4 blocks a second? for ( int iy = ( int ) player.prevPosY; iy >= ( int ) player.posY; --iy) { int x = ( int ) player.posX; int y = ( int )( iy - player.yOffset + player.ySize ); int z = ( int ) player.posZ; Block block = player.worldObj.getBlock( x, y , z ); Block above = player.worldObj.getBlock( x, y + 1, z ); boolean still = ( block instanceof BlockStaticLiquid ); if ( block instanceof BlockFluidBase ) { still = ( ( ( BlockFluidBase ) block ).getFilledPercentage( player.worldObj, x, y, z ) >= 1.0 ); } if ( !player.isSneaking() && still && ( !( above instanceof BlockStaticLiquid ) && !( above instanceof BlockFluidBase ) ) ) { double yDiff = player.yOffset + player.ySize; player.setPosition( player.posX, ( y + 1 ) + yDiff /*- 0.01*/, player.posZ ); player.onGround = true; player.setVelocity( player.motionX, 0, player.motionZ ); player.fallDistance = 0; player.isAirBorne = false; break; } } }
@Override public boolean shouldSideBeRendered(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing side) { Block adjacent = world.getBlockState(pos.offset(side)).getBlock(); return adjacent != state.getBlock() && (adjacent instanceof IFluidBlock || adjacent instanceof BlockStaticLiquid || super.shouldSideBeRendered(state, world, pos, side)); }