public static BlockPos getTopBlock(World world, BlockPos pos) { Chunk chunk = world.getChunkFromBlockCoords(pos); BlockPos blockpos; BlockPos blockpos1; for (blockpos = new BlockPos(pos.getX(), chunk.getTopFilledSegment() + 16, pos.getZ()); blockpos.getY() >= 0; blockpos = blockpos1) { blockpos1 = blockpos.down(); IBlockState state = chunk.getBlockState(blockpos1); if ((state.getMaterial().blocksMovement() && !state.getBlock().isLeaves(state, world, blockpos1) && !state.getBlock().isFoliage(world, blockpos1) && state.getBlock() != Blocks.LOG && state.getBlock() != Blocks.LOG2) || state.getBlock() instanceof BlockLiquid) break; } return blockpos; }
@Override public void delayForHardBlocks(BlockPos pos, Consumer<BlockPos> nextJob) { World world = entity.getEntityWorld(); if (world.isAirBlock(pos)) { return; } IBlockState state = world.getBlockState(pos); if (!allowedToHarvest(state, world, pos, GeneralTools.getHarvester())) { return; } Block block = state.getBlock(); if (block instanceof BlockLiquid) { nextJob.accept(pos); } else { float hardness = state.getBlockHardness(world, pos); if (hardness < Config.delayAtHardness) { nextJob.accept(pos); } else { delay((int) (hardness * Config.delayFactor), () -> nextJob.accept(pos)); } } }
@SubscribeEvent public void onAddCollisionBox(AddCollisionBoxToListEvent event) { if (getLocalPlayer() != null && (event.getBlock() instanceof BlockLiquid) && (EntityUtils.isDrivenByPlayer(event.getEntity()) || EntityUtils.isLocalPlayer(event.getEntity())) && !(event.getEntity() instanceof EntityBoat) && !getLocalPlayer().isSneaking() && getLocalPlayer().fallDistance < 3 && !isInWater(getLocalPlayer()) && (isAboveWater(getLocalPlayer(), false) || isAboveWater(getRidingEntity(), false)) && isAboveBlock(getLocalPlayer(), event.getPos())) { AxisAlignedBB axisalignedbb = WATER_WALK_AA.offset(event.getPos()); if (event.getEntityBox().intersects(axisalignedbb)) event.getCollidingBoxes().add(axisalignedbb); // cancel event, which will stop it from calling the original code event.setCanceled(true); } }
/** * Checks if the current block the entity is within of the specified material type */ public boolean isInsideOfMaterial(Material materialIn) { double d0 = this.posY + (double)this.getEyeHeight(); BlockPos blockpos = new BlockPos(this.posX, d0, this.posZ); IBlockState iblockstate = this.worldObj.getBlockState(blockpos); Block block = iblockstate.getBlock(); if (block.getMaterial() == materialIn) { float f = BlockLiquid.getLiquidHeightPercent(iblockstate.getBlock().getMetaFromState(iblockstate)) - 0.11111111F; float f1 = (float)(blockpos.getY() + 1) - f; boolean flag = d0 < (double)f1; return !flag && this instanceof EntityPlayer ? false : flag; } else { return false; } }
public static Block getBlockAtEntityViewpoint(World worldIn, Entity p_180786_1_, float p_180786_2_) { Vec3 vec3 = projectViewFromEntity(p_180786_1_, (double)p_180786_2_); BlockPos blockpos = new BlockPos(vec3); IBlockState iblockstate = worldIn.getBlockState(blockpos); Block block = iblockstate.getBlock(); if (block.getMaterial().isLiquid()) { float f = 0.0F; if (iblockstate.getBlock() instanceof BlockLiquid) { f = BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue()) - 0.11111111F; } float f1 = (float)(blockpos.getY() + 1) - f; if (vec3.yCoord >= (double)f1) { block = worldIn.getBlockState(blockpos.up()).getBlock(); } } return block; }
public static IBlockState getBlockStateAtEntityViewpoint(World worldIn, Entity entityIn, float p_186703_2_) { Vec3d vec3d = projectViewFromEntity(entityIn, (double)p_186703_2_); BlockPos blockpos = new BlockPos(vec3d); IBlockState iblockstate = worldIn.getBlockState(blockpos); if (iblockstate.getMaterial().isLiquid()) { float f = 0.0F; if (iblockstate.getBlock() instanceof BlockLiquid) { f = BlockLiquid.getLiquidHeightPercent(((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue()) - 0.11111111F; } float f1 = (float)(blockpos.getY() + 1) - f; if (vec3d.yCoord >= (double)f1) { iblockstate = worldIn.getBlockState(blockpos.up()); } } return iblockstate; }
public BlockData getTarget(BlockPos pos) { EnumFacing[] orderedFacingValues = new EnumFacing[] { EnumFacing.UP, EnumFacing.EAST, EnumFacing.NORTH, EnumFacing.WEST, EnumFacing.SOUTH, EnumFacing.DOWN }; for (EnumFacing facing : orderedFacingValues) { BlockPos alteredPos = pos.add(facing.getOpposite().getDirectionVec()); if (!mc.theWorld.getBlockState(alteredPos).getBlock().isReplaceable(mc.theWorld, alteredPos) && !(mc.theWorld.getBlockState(alteredPos).getBlock() instanceof BlockLiquid) && !(mc.theWorld.getBlockState(alteredPos).getBlock() instanceof BlockAir)) { return new BlockData(alteredPos, facing); } } return null; }
public static boolean isTouchingLiquid() { Minecraft mc = Minecraft.getMinecraft(); boolean inLiquid = false; int y = (int) mc.player.boundingBox.minY; for (int x = floor_double(mc.player.boundingBox.minX); x < floor_double(mc.player.boundingBox.maxX) + 1; x++) { for (int z = floor_double(mc.player.boundingBox.minZ); z < floor_double(mc.player.boundingBox.maxZ) + 1; z++) { net.minecraft.block.Block block = mc.world.getBlockState(new BlockPos(x, y, z)).getBlock(); if ((block != null) && (!(block instanceof BlockAir))) { if (!(block instanceof BlockLiquid)) { return false; } inLiquid = true; } } } return inLiquid; }
@Override public AxisAlignedBB onAddCollisionBox(Block block, BlockPos pos, AxisAlignedBB box) { if (!isEnabled() || Wrapper.getPlayer() == null || !(block instanceof BlockLiquid)) { return box; } if (isInWater(Wrapper.getPlayer()) || Wrapper.getPlayer().isSneaking() || Wrapper.getPlayer().fallDistance > 3) { return box; } if (Wrapper.getPlayer().ridingEntity != null) { return box; } return new AxisAlignedBB(0, 0, 0, 1, 0.99, 1); }
/** * Checks if the current block the entity is within of the specified material type */ public boolean isInsideOfMaterial(Material materialIn) { if (this.getRidingEntity() instanceof EntityBoat) { return false; } else { double d0 = this.posY + (double)this.getEyeHeight(); BlockPos blockpos = new BlockPos(this.posX, d0, this.posZ); IBlockState iblockstate = this.world.getBlockState(blockpos); if (iblockstate.getMaterial() == materialIn) { float f = BlockLiquid.getLiquidHeightPercent(iblockstate.getBlock().getMetaFromState(iblockstate)) - 0.11111111F; float f1 = (float)(blockpos.getY() + 1) - f; boolean flag = d0 < (double)f1; return !flag && this instanceof EntityPlayer ? false : flag; } else { return false; } } }
/** * Helper method to get an IFluidHandler for at a block position. * * Returns null if there is no valid fluid handler. */ @Nullable public static IFluidHandler getFluidHandler(World world, BlockPos blockPos, @Nullable EnumFacing side) { IBlockState state = world.getBlockState(blockPos); Block block = state.getBlock(); if (block.hasTileEntity(state)) { TileEntity tileEntity = world.getTileEntity(blockPos); if (tileEntity != null && tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) { return tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); } } else if (block instanceof IFluidBlock) { return new FluidBlockWrapper((IFluidBlock) block, world, blockPos); } else if (block instanceof BlockLiquid) { return new BlockLiquidWrapper((BlockLiquid) block, world, blockPos); } return null; }
/** * Attempts to pick up a fluid in the world and put it in an empty container item. * * @param emptyContainer The empty container to fill. Will not be modified. * @param playerIn The player filling the container. Optional. * @param worldIn The world the fluid is in. * @param pos The position of the fluid in the world. * @param side The side of the fluid that is being drained. * @return a filled container if it was successful. returns null on failure. */ @Nullable public static ItemStack tryPickUpFluid(ItemStack emptyContainer, @Nullable EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side) { if (emptyContainer == null || worldIn == null || pos == null) { return null; } IBlockState state = worldIn.getBlockState(pos); Block block = state.getBlock(); if (block instanceof IFluidBlock || block instanceof BlockLiquid) { IFluidHandler targetFluidHandler = FluidUtil.getFluidHandler(worldIn, pos, side); if (targetFluidHandler != null) { return FluidUtil.tryFillContainer(emptyContainer, targetFluidHandler, Integer.MAX_VALUE, playerIn, true); } } return null; }
public float getFluidHeightForRender(IBlockAccess world, BlockPos pos) { IBlockState here = world.getBlockState(pos); IBlockState up = world.getBlockState(pos.down(densityDir)); if (here.getBlock() == this) { if (up.getMaterial().isLiquid() || up.getBlock() instanceof IFluidBlock) { return 1; } if (getMetaFromState(here) == getMaxRenderHeightMeta()) { return 0.875F; } } if (here.getBlock() instanceof BlockLiquid) { return Math.min(1 - BlockLiquid.getLiquidHeightPercent(here.getValue(BlockLiquid.LEVEL)), 14f / 16); } return !here.getMaterial().isSolid() && up.getBlock() == this ? 1 : this.getQuantaPercentage(world, pos) * 0.875F; }
@Nullable @Override public FluidStack drain(FluidStack resource, boolean doDrain) { if (resource == null || resource.amount < Fluid.BUCKET_VOLUME) { return null; } IBlockState blockState = world.getBlockState(blockPos); if (blockState.getBlock() == blockLiquid && blockState.getValue(BlockLiquid.LEVEL) == 0) { FluidStack containedStack = getStack(blockState); if (containedStack != null && resource.containsFluid(containedStack)) { if (doDrain) { world.setBlockState(blockPos, Blocks.AIR.getDefaultState(), 11); } return containedStack; } } return null; }
@Nullable private FluidStack getStack(IBlockState blockState) { Material material = blockState.getMaterial(); if (material == Material.WATER && blockState.getValue(BlockLiquid.LEVEL) == 0) { return new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME); } else if (material == Material.LAVA && blockState.getValue(BlockLiquid.LEVEL) == 0) { return new FluidStack(FluidRegistry.LAVA, Fluid.BUCKET_VOLUME); } else { return null; } }
/** * Check if the given blockpos contains a fluid source block. * * @param world the world * @param pos the blockpos * @return true if there is a fluid source block at the given blockpos, false otherwise */ public static boolean isSourceBlock(World world, BlockPos pos) { IBlockState state = world.getBlockState(pos); if (state.getProperties().containsKey(BlockLiquid.LEVEL)) { return state.getValue(BlockLiquid.LEVEL) == 0; } else return state.getProperties().containsKey(BlockFluidBase.LEVEL) && state.getValue(BlockFluidBase.LEVEL) == 0; }
@Override public boolean matches(World world, BlockPos pos) { IBlockState state = world.getBlockState(pos); Block block = state.getBlock(); switch (this.plantType) { case Desert: return block == Blocks.SAND || block == Blocks.HARDENED_CLAY || block == Blocks.STAINED_HARDENED_CLAY || block == Blocks.DIRT; case Nether: return block == Blocks.SOUL_SAND; case Crop: return block == Blocks.FARMLAND; case Cave: return block.isSideSolid(state, world, pos, EnumFacing.UP); case Plains: return block == Blocks.GRASS || block == Blocks.DIRT || block == Blocks.FARMLAND || block == Blocks.MYCELIUM; case Water: return state.getMaterial() == Material.WATER && state.getValue(BlockLiquid.LEVEL) == 0; case Beach: boolean isBeach = block == Blocks.GRASS || block == Blocks.DIRT || block == Blocks.SAND || block == Blocks.MYCELIUM; boolean hasWater = (world.getBlockState(pos.east()).getMaterial() == Material.WATER || world.getBlockState(pos.west()).getMaterial() == Material.WATER || world.getBlockState(pos.north()).getMaterial() == Material.WATER || world.getBlockState(pos.south()).getMaterial() == Material.WATER); return isBeach && hasWater; default: return false; } }
public static ItemStack phaseBucket(Block block) { if(block instanceof BlockLiquid || block instanceof IFluidBlock) { Fluid fluid = block instanceof BlockLiquid ? FluidRegistry.lookupFluidForBlock(block) : ((IFluidBlock)block).getFluid(); if(fluid == null) return new ItemStack(block); ItemStack stack = FluidUtil.getFilledBucket(new FluidStack(fluid, 1000)); return stack.isEmpty() ? new ItemStack(block) : stack; } return new ItemStack(block); }
public static void renderGhostBlock(IBlockState state, BlockPos position, Color color, boolean noDepth, float partialTicks) { if(!(state.getBlock() instanceof BlockLiquid) && !(state.getBlock() instanceof BlockFluidBase)) { renderGhostModel(Minecraft.getMinecraft().getBlockRendererDispatcher().getModelForState(state), position, color, noDepth, partialTicks); return; } GlStateManager.enableBlend(); GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE_MINUS_DST_COLOR); BufferBuilder vb; if(noDepth) { GlStateManager.depthFunc(519); vb = prepRenderBlockDepth(partialTicks, true); } else vb = prepRender(partialTicks, true); vb.begin(7, DefaultVertexFormats.BLOCK); World world = Minecraft.getMinecraft().world; Minecraft.getMinecraft().getBlockRendererDispatcher().renderBlock(state, position.add(0, noDepth ? 500 : 0, 0), world, vb); for(int i = 0; i < vb.getVertexCount(); i++) vb.putColorMultiplier(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, i); vb.color(1, 1, 1, 0.1f); postRender(); GlStateManager.disableBlend(); GlStateManager.depthFunc(515); }
@SubscribeEvent public void onClientTick(TickEvent.ClientTickEvent event) { if (getLocalPlayer() == null || getLocalPlayer().fallDistance < settingFallHeight.getAsDouble() || !getLocalPlayer().inventory.hasItemStack(WATER_BUCKET) || isInWater(getLocalPlayer()) || isAboveWater(getLocalPlayer())) return; Vec3d playerPos = getLocalPlayer().getPositionVector(); Vec3d rayTraceBucket = new Vec3d(playerPos.x, playerPos.y-5, playerPos.z); Vec3d rayTracePre = new Vec3d(playerPos.x, playerPos.y-preHeight.getAsDouble(), playerPos.z); // find the ground before the player is ready to water bucket RayTraceResult result = MC.world.rayTraceBlocks(playerPos, rayTraceBucket, true); RayTraceResult resultPre = MC.world.rayTraceBlocks(playerPos, rayTracePre, true); if (resultPre != null && resultPre.typeOfHit.equals(Type.BLOCK) && !(getWorld().getBlockState(resultPre.getBlockPos()).getBlock() instanceof BlockLiquid)) { // set the pitch early to not get cucked by ncp getLocalPlayer().prevRotationPitch = 90f; getLocalPlayer().rotationPitch = 90f; int bucketSlot = findBucketHotbar(); if (bucketSlot == -1) bucketSlot = findBucketInv(); if (bucketSlot > 8) { swap(bucketSlot, getLocalPlayer().inventory.currentItem); // move bucket from inventory to hotbar } else { MC.player.inventory.currentItem = bucketSlot; } } if (result != null && result.typeOfHit.equals(Type.BLOCK) && !(getWorld().getBlockState(result.getBlockPos()).getBlock() instanceof BlockLiquid)) { getNetworkManager().sendPacket(new CPacketPlayer.Rotation(getLocalPlayer().rotationYaw, 90, getLocalPlayer().onGround)); // probably unnecessary but doing it anyways getLocalPlayer().prevRotationPitch = 90f; getLocalPlayer().rotationPitch = 90f; //printMessage("Attempted to place water bucket"); MC.playerController.processRightClick(getLocalPlayer(), getWorld(), EnumHand.MAIN_HAND); } }
public static boolean isAboveWater(Entity entity, boolean packet){ if (entity == null) return false; double y = entity.posY - (packet ? 0.03 : (EntityUtils.isPlayer(entity) ? 0.2 : 0.5)); // increasing this seems to flag more in NCP but needs to be increased so the player lands on solid water for(int x = MathHelper.floor(entity.posX); x < MathHelper.ceil(entity.posX); x++) for (int z = MathHelper.floor(entity.posZ); z < MathHelper.ceil(entity.posZ); z++) { BlockPos pos = new BlockPos(x, MathHelper.floor(y), z); if (getWorld().getBlockState(pos).getBlock() instanceof BlockLiquid) return true; } return false; }
public static boolean isInWater(Entity entity) { if(entity == null) return false; double y = entity.posY + 0.01; for(int x = MathHelper.floor(entity.posX); x < MathHelper.ceil(entity.posX); x++) for (int z = MathHelper.floor(entity.posZ); z < MathHelper.ceil(entity.posZ); z++) { BlockPos pos = new BlockPos(x, (int) y, z); if (getWorld().getBlockState(pos).getBlock() instanceof BlockLiquid) return true; } return false; }
/** * Checks to see if a given block is both water and cold enough to freeze. */ public boolean canBlockFreeze(BlockPos pos, boolean noWaterAdj) { BiomeGenBase biomegenbase = this.getBiomeGenForCoords(pos); float f = biomegenbase.getFloatTemperature(pos); if (f > 0.15F) { return false; } else { if (pos.getY() >= 0 && pos.getY() < 256 && this.getLightFor(EnumSkyBlock.BLOCK, pos) < 10) { IBlockState iblockstate = this.getBlockState(pos); Block block = iblockstate.getBlock(); if ((block == Blocks.water || block == Blocks.flowing_water) && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0) { if (!noWaterAdj) { return true; } boolean flag = this.isWater(pos.west()) && this.isWater(pos.east()) && this.isWater(pos.north()) && this.isWater(pos.south()); if (!flag) { return true; } } } return false; } }
@Override public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) { init(stack); if (getFluidStored(stack) >= FLUID_CAPACITY) { return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack); } RayTraceResult ray = rayTrace(worldIn, playerIn, true); if (ray == null || ray.typeOfHit == null || hand == null) { return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack); } if (ray.typeOfHit == RayTraceResult.Type.BLOCK && hand == EnumHand.MAIN_HAND && !worldIn.isRemote) { BlockPos blockpos = ray.getBlockPos(); IBlockState iblockstate = worldIn.getBlockState(blockpos); Material material = iblockstate.getMaterial(); if (material == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL).intValue() == 0) { worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11); playerIn.addStat(StatList.getObjectUseStats(this)); playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F); addFluid(stack, 1000); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack); } else if (iblockstate.getBlock().hasTileEntity(iblockstate) && worldIn.getTileEntity(blockpos).hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, ray.sideHit)) { IFluidHandler fluidHandler = worldIn.getTileEntity(blockpos).getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, ray.sideHit); for (IFluidTankProperties property : fluidHandler.getTankProperties()) { if (property.getContents().getFluid() == FluidRegistry.WATER && property.getContents().amount >= 1000 && property.canDrain()) { fluidHandler.drain(new FluidStack(FluidRegistry.WATER, 1000), true); addFluid(stack, 1000); } } } } return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack); }
public static boolean isOnLiquid() { AxisAlignedBB par1AxisAlignedBB = Minecraft.getMinecraft().thePlayer.boundingBox.offset(0.0, -0.01, 0.0).contract(0.001, 0.001, 0.001); int var4 = MathHelper.floor_double((double)par1AxisAlignedBB.minX); int var5 = MathHelper.floor_double((double)(par1AxisAlignedBB.maxX + 1.0)); int var6 = MathHelper.floor_double((double)par1AxisAlignedBB.minY); int var7 = MathHelper.floor_double((double)(par1AxisAlignedBB.maxY + 1.0)); int var8 = MathHelper.floor_double((double)par1AxisAlignedBB.minZ); int var9 = MathHelper.floor_double((double)(par1AxisAlignedBB.maxZ + 1.0)); Vec3 var11 = new Vec3(0.0, 0.0, 0.0); int var12 = var4; while (var12 < var5) { int var13 = var6; while (var13 < var7) { int var14 = var8; while (var14 < var9) { Block var15 = Minecraft.getMinecraft().theWorld.getBlockState(new BlockPos(var12, var13, var14)).getBlock(); if (!(var15 instanceof BlockAir) && !(var15 instanceof BlockLiquid)) { return false; } ++var14; } ++var13; } ++var12; } return true; }
public static boolean isInLiquid() { AxisAlignedBB par1AxisAlignedBB = Minecraft.getMinecraft().thePlayer.boundingBox.contract(0.001, 0.001, 0.001); int var4 = MathHelper.floor_double((double)par1AxisAlignedBB.minX); int var5 = MathHelper.floor_double((double)(par1AxisAlignedBB.maxX + 1.0)); int var6 = MathHelper.floor_double((double)par1AxisAlignedBB.minY); int var7 = MathHelper.floor_double((double)(par1AxisAlignedBB.maxY + 1.0)); int var8 = MathHelper.floor_double((double)par1AxisAlignedBB.minZ); int var9 = MathHelper.floor_double((double)(par1AxisAlignedBB.maxZ + 1.0)); Vec3 var11 = new Vec3(0.0, 0.0, 0.0); int var12 = var4; while (var12 < var5) { int var13 = var6; while (var13 < var7) { int var14 = var8; while (var14 < var9) { Block var15 = Minecraft.getMinecraft().theWorld.getBlockState(new BlockPos(var12, var13, var14)).getBlock(); if (var15 instanceof BlockLiquid) { return true; } ++var14; } ++var13; } ++var12; } return false; }
public static boolean isFluid(IBlockState state) { boolean flag1 = state.getBlock() instanceof BlockLiquid; boolean flag2 = state.getBlock().getMaterial(state).isLiquid(); boolean flag3 = state.getBlock() instanceof BlockFluidBase; return flag1 || flag2 || flag3; }
@Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) { if (world.isRemote) return stack; else { MovingObjectPosition movingobjectposition = getMovingObjectPositionFromPlayer(world, player, true); if (movingobjectposition == null) return stack; else { if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { int i = movingobjectposition.blockX; int j = movingobjectposition.blockY; int k = movingobjectposition.blockZ; if (!world.canMineBlock(player, i, j, k)) return stack; if (!player.canPlayerEdit(i, j, k, movingobjectposition.sideHit, stack)) return stack; if (world.getBlock(i, j, k) instanceof BlockLiquid) { Entity entity = spawnEntity(world, stack.getItemDamage(), i, j, k); if (entity != null) { if (entity instanceof EntityLivingBase && stack.hasDisplayName()) ((EntityLiving) entity).setCustomNameTag(stack.getDisplayName()); if (!player.capabilities.isCreativeMode) stack.stackSize--; } } } return stack; } } }
public Smasher() { super("Smasher", 0xFCC6FF, ModuleCategory.WORLD); NukerEngine nukerEngine = new NukerEngine((pos, block) -> { boolean blockChecks = BlockHelper.canSeeBlock(pos.getX(), pos.getY(), pos.getZ()) && !(block instanceof BlockAir) && !(block instanceof BlockLiquid); return blockChecks && block.getBlockHardness(mc.theWorld, pos) == 0; }); listeners.addAll(nukerEngine.getListeners()); }
private BlockPos[] getFloor() { Set<BlockPos> positions = new HashSet<>(); int highestY = -1; for (double d = 0; d <= mc.thePlayer.posY; d += 0.5) { for (int x = MathHelper.floor_double(mc.thePlayer.getEntityBoundingBox().minX - 0.5); x < MathHelper .floor_double(mc.thePlayer.getEntityBoundingBox().maxX + 0.5) + 1; x++) { for (int z = MathHelper.floor_double(mc.thePlayer.getEntityBoundingBox().minZ - 0.5); z < MathHelper .floor_double(mc.thePlayer.getEntityBoundingBox().maxZ + 0.5) + 1; z++) { BlockPos pos = new BlockPos(x, mc.thePlayer.posY - d, z); IBlockState state = mc.theWorld.getBlockState(pos); Block block = state.getBlock(); List<AxisAlignedBB> boundingBoxes = new ArrayList<>(); state.getBlock().addCollisionBoxesToList(mc.theWorld, pos, state, INFINITY_BB, boundingBoxes, mc.thePlayer); if (!boundingBoxes.isEmpty() && !(block instanceof BlockLiquid) && !(block instanceof BlockAir)) { if (pos.getY() == highestY) { positions.add(pos); } if (pos.getY() > highestY) { positions.clear(); highestY = pos.getY(); } } } } } return positions.toArray(new BlockPos[positions.size()]); }
@Override public boolean canBlockStay(World world, BlockPos pos, IBlockState state) { IBlockState lavasource = world.getBlockState(pos.add(0, -1, 0)); Material material = lavasource.getMaterial(); boolean flag = ((Integer)lavasource.getValue(BlockLiquid.LEVEL)).intValue() == 0; return pos.getY() >= 0 && pos.getY() < 256 ? material == Material.LAVA && flag : false; }
@Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { RayTraceResult raytraceresult = this.rayTrace(worldIn, playerIn, true); if (raytraceresult == null) { return new ActionResult(EnumActionResult.PASS, itemStackIn); } else { if (raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) { BlockPos blockpos = raytraceresult.getBlockPos(); if (!worldIn.isBlockModifiable(playerIn, blockpos) || !playerIn.canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, itemStackIn)) { return new ActionResult(EnumActionResult.FAIL, itemStackIn); } BlockPos blockpos1 = blockpos.up(); IBlockState iblockstate = worldIn.getBlockState(blockpos); if (iblockstate.getMaterial() == Material.LAVA && ((Integer)iblockstate.getValue(BlockLiquid.LEVEL)).intValue() == 0 && worldIn.isAirBlock(blockpos1)) { worldIn.setBlockState(blockpos1, UCBlocks.lavalily.getDefaultState(), 11); if (!playerIn.capabilities.isCreativeMode) --itemStackIn.stackSize; worldIn.playSound(playerIn, blockpos, SoundEvents.BLOCK_WATERLILY_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F); return new ActionResult(EnumActionResult.SUCCESS, itemStackIn); } } return new ActionResult(EnumActionResult.FAIL, itemStackIn); } }