private boolean spreadWaterFromCenter(World world, EntityPlayer player, BlockPos posCenter) { int count = 0; for (BlockPos pos : UtilWorld.findBlocks(world, posCenter, Blocks.WATER, RADIUS)) { // world.setBlockState(pos, Blocks.FLOWING_WATER.getDefaultState()); // , state.withProperty(LEVEL, 0) //instead of just setBlockState, get the correct state for max level and for this fluid material, then schedule a tick update. //this way, it sends correct block update and avoids 'stuck' water that doesnt flow BlockDynamicLiquid blockdynamicliquid = BlockLiquid.getFlowingBlock(Material.WATER); IBlockState state = blockdynamicliquid.getDefaultState(); world.setBlockState(pos, blockdynamicliquid.getDefaultState().withProperty(BlockLiquid.LEVEL, state.getValue(BlockLiquid.LEVEL)), 2); world.scheduleUpdate(pos, blockdynamicliquid, blockdynamicliquid.tickRate(world)); UtilParticle.spawnParticle(world, EnumParticleTypes.WATER_SPLASH, pos); UtilParticle.spawnParticle(world, EnumParticleTypes.WATER_SPLASH, pos.up()); count++; } boolean success = count > 0; if (success) {//particles are on each location, sound is just once player.getCooldownTracker().setCooldown(this, COOLDOWN); UtilSound.playSound(player, SoundEvents.ENTITY_PLAYER_SPLASH); } return success; }
private void handleFallingBlocks(World worldIn, BlockPos pos, IBlockState state) { if(worldIn.isRemote) return; final BlockPos upPos = pos.up(); final IBlockState upState = worldIn.getBlockState(upPos); final Block upBlock = upState.getBlock(); if(upBlock instanceof BlockFalling) { worldIn.setBlockToAir(upPos); } else if(upBlock == Blocks.FLOWING_WATER || upBlock == Blocks.FLOWING_LAVA) { if(upBlock instanceof BlockDynamicLiquid) { int level = upState.getValue(BlockLiquid.LEVEL); if( level < 8) { worldIn.setBlockToAir(upPos); } } } }
public static boolean onFlowIntoBlockFrom(BlockDynamicLiquid flowingBlock, World world, int x, int y, int z, int newFlowDecay, int flowDirection) { if (world == null) return false; TileEntity tile = world.getTileEntity(x, y, z); if (tile != null && tile instanceof IFluidFlowHandler) { return ((IFluidFlowHandler) tile).handleFlowIntoBlock(FluidHelper.getFluidTypeOfBlock(flowingBlock), newFlowDecay, ForgeDirection.getOrientation(flowDirection).getOpposite()); } try { Wrappers.flowIntoBlock(flowingBlock, world, x, y, z, newFlowDecay); return false; } catch (Exception e) { e.printStackTrace(); return true; } }
public static boolean doesFlowGetBlockedBy(BlockDynamicLiquid flowingBlock, World world, int x, int y, int z, int flowDirection) { TileEntity tile = world.getTileEntity(x, y, z); if (tile != null && tile instanceof IFluidFlowHandler) { return ((IFluidFlowHandler) tile).doesFlowGetBlockedBySide(FluidHelper.getFluidTypeOfBlock(flowingBlock), ForgeDirection.getOrientation(flowDirection).getOpposite()); } try { return Wrappers.doesFlowGetBlockedBy(flowingBlock, world, x, y, z); } catch (Exception e) { e.printStackTrace(); return true; } }
public static int getSmallestFlowDecayTo(BlockDynamicLiquid flowingBlock, World world, int x, int y, int z, int curSmallest, int fromSide) { int flowDecay = Hooks.getFlowDecayTo(flowingBlock, world, x, y, z, fromSide); if (flowDecay < 0) { return curSmallest; } else { if (flowDecay == 0) { int numAdjacentSources = ReflectionHelper.getPrivateValue(BlockDynamicLiquid.class, flowingBlock, "field_149815_a", "a"); ReflectionHelper.setPrivateValue(BlockDynamicLiquid.class, flowingBlock, numAdjacentSources+1, "field_149815_a", "a"); } if (flowDecay >= 8) { flowDecay = 0; } return curSmallest >= 0 && flowDecay >= curSmallest ? curSmallest : flowDecay; } }
public static int getEffectiveFlowDecay(BlockLiquid liquidBlock, World world, int x, int y, int z) { try { if (getEffectiveFlowDecay == null) { getEffectiveFlowDecay = BlockDynamicLiquid.class.getDeclaredMethod("getEffectiveFlowDecay", World.class, Integer.TYPE, Integer.TYPE, Integer.TYPE); getEffectiveFlowDecay.setAccessible(true); } return (Integer) getEffectiveFlowDecay.invoke(liquidBlock, world, x, y, z); } catch (Exception e) { e.printStackTrace(); return -1; } }
public static boolean canLiquidDisplaceBlock(BlockDynamicLiquid flowingBlock, World world, int x, int y, int z) { try { if (canLiquidDisplaceBlock == null) { canLiquidDisplaceBlock = BlockDynamicLiquid.class.getDeclaredMethod("func_149809_q", World.class, Integer.TYPE, Integer.TYPE, Integer.TYPE); canLiquidDisplaceBlock.setAccessible(true); } return (Boolean) canLiquidDisplaceBlock.invoke(flowingBlock, world, x, y, z); } catch (Exception e) { e.printStackTrace(); return false; } }
public static int getSmallestFlowDecay(BlockDynamicLiquid flowingBlock, World world, int x, int y, int z, int curSmallest) { try { if (getSmallestFlowDecay == null) { getSmallestFlowDecay = BlockDynamicLiquid.class.getDeclaredMethod("func_149810_a", World.class, Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE); getSmallestFlowDecay.setAccessible(true); } return (Integer) getSmallestFlowDecay.invoke(flowingBlock, world, x, y, z, curSmallest); } catch (Exception e) { e.printStackTrace(); return curSmallest; } }
public static boolean isValidSpawnBlock(final BlockStateProvider provider, final BlockPos pos) { if (provider.getBlockState(pos).getMaterial() != Material.WATER) return false; if (isUnboundedLiquid(provider, pos)) { final BlockPos down = pos.down(); if (provider.getBlockState(down).getMaterial().isSolid()) return true; return !isUnboundedLiquid(provider, down); } return provider.getBlockState(pos.up()).getBlock() instanceof BlockDynamicLiquid; }
private boolean isSourceBlock( BlockPos coord){ IBlockState bs = getWorld().getBlockState(coord); if(bs.getBlock() instanceof BlockLiquid){ return (Integer)bs.getValue(BlockDynamicLiquid.LEVEL) == 0; } else if(bs.getBlock() instanceof BlockFluidClassic){ return ((BlockFluidClassic)bs.getBlock()).isSourceBlock(getWorld(), coord); }else{ return false; } }
public static BlockDynamicLiquid getFlowingBlock(Material materialIn) { if (materialIn == Material.WATER) return (BlockDynamicLiquid) SCContent.bogusWaterFlowing; else if (materialIn == Material.LAVA) return (BlockDynamicLiquid) SCContent.bogusLavaFlowing; else throw new IllegalArgumentException("Invalid material"); }
public static BlockDynamicLiquid getFlowingBlock(Material materialIn) { if (materialIn == Material.water) return (BlockDynamicLiquid) SCContent.bogusWaterFlowing; else if (materialIn == Material.lava) return (BlockDynamicLiquid) SCContent.bogusLavaFlowing; else throw new IllegalArgumentException("Invalid material"); }
public void outputFluidFlowOnSide(FluidFlow flow, ForgeDirection side) { int x = xCoord + side.offsetX, y = yCoord + side.offsetY, z = zCoord + side.offsetZ; int newFlowDecay = FluidHelper.getNextFlowDecay(flow.getFluid(), flow.getFlowDecay(), side); if (newFlowDecay < 0) return; Hooks.onFlowIntoBlockFrom((BlockDynamicLiquid) FluidHelper.getFlowingFluidBlock(flow.getFluid()), worldObj, x, y, z, newFlowDecay, side.ordinal()); onFluidFlowOutOfSide(flow.getFluid(), side, flow.getFlowDecay()); }
public void onLiquidFlowFrom(Block block, int flowDecay, ForgeDirection flowDirection) { // TODO: Water has no fluid for BlockDynamicFluid? Fluid fluid = FluidRegistry.lookupFluidForBlock(block); liquidFlows[flowDirection.ordinal()] = new LiquidFlowInfo(fluid, flowDecay); Hooks.onFlowIntoBlockFrom((BlockDynamicLiquid) block, crate.getWorldObj(), crate.xCoord+flowDirection.offsetX, crate.yCoord+flowDirection.offsetY, crate.zCoord+flowDirection.offsetZ, flowDecay, flowDirection.ordinal()); recalculateFlowVector(); }
public static int getFlowDecayTo(BlockDynamicLiquid flowingBlock, World world, int x, int y, int z, int fromSide) { TileEntity tile = world.getTileEntity(x, y, z); if (tile != null && tile instanceof IFluidFlowHandler) { return ((IFluidFlowHandler) tile).getFlowDecayTo(FluidHelper.getFluidTypeOfBlock(flowingBlock), ForgeDirection.getOrientation(fromSide).getOpposite()); } return Wrappers.getFlowDecay(flowingBlock, world, x, y, z); }
public static boolean canLiquidDisplaceBlockFrom(BlockDynamicLiquid flowingBlock, World world, int x, int y, int z, int flowDirection) { TileEntity tile = world.getTileEntity(x, y, z); if (tile != null && tile instanceof IFluidFlowHandler) { boolean canDisplace = !((IFluidFlowHandler) tile).doesFlowGetBlockedBySide(FluidHelper.getFluidTypeOfBlock(flowingBlock), ForgeDirection.getOrientation(flowDirection).getOpposite()); ModEarliestOfGames.Log.info("canDisplace: " + canDisplace + " side: " + ForgeDirection.getOrientation(flowDirection).getOpposite()); return canDisplace; } return Wrappers.canLiquidDisplaceBlock(flowingBlock, world, x, y, z); }
public static boolean canLiquidDisplaceBlock(BlockDynamicLiquid flowingBlock, World world, int x, int y, int z) { TileEntity tile = world.getTileEntity(x, y, z); if (tile != null && tile instanceof IFluidFlowHandler) { return true; } return false; }
public static boolean doesFlowGetBlockedBy(BlockDynamicLiquid flowingBlock, World world, int x, int y, int z) { try { if (doesFlowGetBlockedBy == null) doesFlowGetBlockedBy = BlockDynamicLiquid.class.getDeclaredMethod("func_149807_p", World.class, Integer.TYPE, Integer.TYPE, Integer.TYPE); return (Boolean) doesFlowGetBlockedBy.invoke(flowingBlock, world, x, y, z); } catch (Exception e) { e.printStackTrace(); return true; } }
public static void flowIntoBlock(BlockDynamicLiquid flowingBlock, World world, int x, int y, int z, int newFlowDecay) { try { if (flowIntoBlock == null) flowIntoBlock = BlockDynamicLiquid.class.getDeclaredMethod("func_149813_h", World.class, Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE); flowIntoBlock.invoke(flowingBlock, world, x, y, z, newFlowDecay); } catch (Exception e) { e.printStackTrace(); } }
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()); } } }
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 void updateLiquid(World worldIn, BlockPos p_176370_2_, IBlockState p_176370_3_) { BlockDynamicLiquid blockdynamicliquid = getFlowingBlock(blockMaterial); worldIn.setBlockState(p_176370_2_, blockdynamicliquid.getDefaultState().withProperty(LEVEL, p_176370_3_.getValue(LEVEL)), 2); worldIn.scheduleUpdate(p_176370_2_, blockdynamicliquid, tickRate(worldIn)); }