net.minecraft.block.BlockLiquid Java Examples

The following examples show how to use net.minecraft.block.BlockLiquid. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NukerModule.java    From seppuku with GNU General Public License v3.0 8 votes vote down vote up
private BlockPos getClosestBlockAll() {
    final Minecraft mc = Minecraft.getMinecraft();
    float maxDist = this.distance.getValue();

    BlockPos ret = null;

    for (float x = maxDist; x >= -maxDist; x--) {
        for (float y = maxDist; y >= -maxDist; y--) {
            for (float z = maxDist; z >= -maxDist; z--) {
                final BlockPos pos = new BlockPos(mc.player.posX + x, mc.player.posY + y, mc.player.posZ + z);
                final double dist = mc.player.getDistance(pos.getX(), pos.getY(), pos.getZ());
                if (dist <= maxDist && (mc.world.getBlockState(pos).getBlock() != Blocks.AIR && !(mc.world.getBlockState(pos).getBlock() instanceof BlockLiquid)) && canBreak(pos)) {
                    if (pos.getY() >= mc.player.posY) {
                        maxDist = (float) dist;
                        ret = pos;
                    }
                }
            }
        }
    }

    return ret;
}
 
Example #2
Source File: GTTileRockBreaker.java    From GT-Classic with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void checkStructure() {
	if (world.getTotalWorldTime() % 60 == 0) {
		EnumFacing foundSide = null;
		for (EnumFacing side : EnumFacing.VALUES) {
			IBlockState x = world.getBlockState(pos.offset(side));
			IBlockState z = world.getBlockState(pos.offset(side.getOpposite()));
			if (x.getMaterial() == Material.WATER && x.getValue(BlockLiquid.LEVEL) == 0
					&& z.getMaterial() == Material.LAVA && z.getValue(BlockLiquid.LEVEL) == 0) {
				foundSide = side;
				break;
			}
		}
		if (foundSide == null) {
			this.rockMode = RockMode.INVALID;
			return;
		}
		this.rockMode = foundSide.getAxis().isHorizontal() ? RockMode.COBBLE : RockMode.STONE;
	}
}
 
Example #3
Source File: SurfaceRockPopulator.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Set<Material> findUndergroundMaterials(Collection<IBlockState> generatedBlocks) {
    HashSet<Material> result = new HashSet<>();
    for (IBlockState blockState : generatedBlocks) {
        Material resultMaterial;
        if (blockState.getBlock() instanceof IFluidBlock || blockState.getBlock() instanceof BlockLiquid) {
            Fluid fluid = FluidRegistry.lookupFluidForBlock(blockState.getBlock());
            resultMaterial = fluid == null ? null : MetaFluids.getMaterialFromFluid(fluid);
        } else {
            ItemStack itemStack = new ItemStack(blockState.getBlock(), 1, blockState.getBlock().damageDropped(blockState));
            UnificationEntry entry = OreDictUnifier.getUnificationEntry(itemStack);
            resultMaterial = entry == null ? null : entry.material;
        }
        if (resultMaterial != null) {
            result.add(resultMaterial);
        }
    }
    return result;
}
 
Example #4
Source File: Jesus.java    From ForgeHax with MIT License 6 votes vote down vote up
@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);
  }
}
 
Example #5
Source File: EntityUtils.java    From ForgeHax with MIT License 6 votes vote down vote up
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;
}
 
Example #6
Source File: EntityUtils.java    From ForgeHax with MIT License 6 votes vote down vote up
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;
}
 
Example #7
Source File: ReverseStep.java    From LiquidBounce with GNU General Public License v3.0 6 votes vote down vote up
@EventTarget(ignoreCondition = true)
public void onUpdate(UpdateEvent event) {
    if(mc.thePlayer.onGround)
        jumped = false;

    if(mc.thePlayer.motionY > 0)
        jumped = true;

    if(!getState())
        return;

    if(BlockUtils.collideBlock(mc.thePlayer.getEntityBoundingBox(), block -> block instanceof BlockLiquid) || BlockUtils.collideBlock(new AxisAlignedBB(mc.thePlayer.getEntityBoundingBox().maxX, mc.thePlayer.getEntityBoundingBox().maxY, mc.thePlayer.getEntityBoundingBox().maxZ, mc.thePlayer.getEntityBoundingBox().minX, mc.thePlayer.getEntityBoundingBox().minY - 0.01D, mc.thePlayer.getEntityBoundingBox().minZ), block -> block instanceof BlockLiquid))
        return;

    if(!mc.gameSettings.keyBindJump.isKeyDown() && !mc.thePlayer.onGround && !mc.thePlayer.movementInput.jump && mc.thePlayer.motionY <= 0D && mc.thePlayer.fallDistance <= 1F && !jumped)
        mc.thePlayer.motionY = -motionValue.get();
}
 
Example #8
Source File: MetaTileEntityPump.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void tryPumpFirstBlock() {
    BlockPos fluidBlockPos = fluidSourceBlocks.poll();
    if (fluidBlockPos == null) return;
    IBlockState blockHere = getWorld().getBlockState(fluidBlockPos);
    if (blockHere.getBlock() instanceof BlockLiquid ||
        blockHere.getBlock() instanceof IFluidBlock) {
        IFluidHandler fluidHandler = FluidUtil.getFluidHandler(getWorld(), fluidBlockPos, null);
        FluidStack drainStack = fluidHandler.drain(Integer.MAX_VALUE, false);
        if (drainStack != null && exportFluids.fill(drainStack, false) == drainStack.amount) {
            exportFluids.fill(drainStack, true);
            fluidHandler.drain(drainStack.amount, true);
            this.fluidSourceBlocks.remove(fluidBlockPos);
            energyContainer.changeEnergy(-GTValues.V[getTier()]);
        }
    }
}
 
Example #9
Source File: JesusModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
public static boolean isInLiquid() {
    final Minecraft mc = Minecraft.getMinecraft();

    if (mc.player.fallDistance >= 3.0f) {
        return false;
    }

    if (mc.player != null) {
        boolean inLiquid = false;
        final AxisAlignedBB bb = mc.player.getRidingEntity() != null ? mc.player.getRidingEntity().getEntityBoundingBox() : mc.player.getEntityBoundingBox();
        int y = (int) bb.minY;
        for (int x = MathHelper.floor(bb.minX); x < MathHelper.floor(bb.maxX) + 1; x++) {
            for (int z = MathHelper.floor(bb.minZ); z < MathHelper.floor(bb.maxZ) + 1; z++) {
                final Block block = mc.world.getBlockState(new BlockPos(x, y, z)).getBlock();
                if (!(block instanceof BlockAir)) {
                    if (!(block instanceof BlockLiquid)) {
                        return false;
                    }
                    inLiquid = true;
                }
            }
        }
        return inLiquid;
    }
    return false;
}
 
Example #10
Source File: Projectiles.java    From ehacks-pro with GNU General Public License v3.0 6 votes vote down vote up
private boolean isInMaterial(AxisAlignedBB axisalignedBB, Material material) {
    int chunkMinX = MathHelper.floor_double(axisalignedBB.minX);
    int chunkMaxX = MathHelper.floor_double((axisalignedBB.maxX + 1.0));
    int chunkMinY = MathHelper.floor_double(axisalignedBB.minY);
    int chunkMaxY = MathHelper.floor_double((axisalignedBB.maxY + 1.0));
    int chunkMinZ = MathHelper.floor_double(axisalignedBB.minZ);
    int chunkMaxZ = MathHelper.floor_double((axisalignedBB.maxZ + 1.0));
    if (!Wrapper.INSTANCE.world().checkChunksExist(chunkMinX, chunkMinY, chunkMinZ, chunkMaxX, chunkMaxY, chunkMaxZ)) {
        return false;
    }
    boolean isWithin = false;
    for (int x = chunkMinX; x < chunkMaxX; ++x) {
        for (int y = chunkMinY; y < chunkMaxY; ++y) {
            for (int z = chunkMinZ; z < chunkMaxZ; ++z) {
                Block block = Block.getBlockById(Wrapper.INSTANCE.world().getBlockMetadata(x, y, z));
                if (block == null || block.getMaterial() != material || chunkMaxY < ((y + 1) - BlockLiquid.getLiquidHeightPercent(Wrapper.INSTANCE.world().getBlockMetadata(x, y, z)))) {
                    continue;
                }
                isWithin = true;
            }
        }
    }
    return isWithin;
}
 
Example #11
Source File: ScaffoldModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
private void placeBlock(BlockPos pos) {
    final Minecraft mc = Minecraft.getMinecraft();
    
    BlockPos[][] posit = {{pos.add(0, 0, 1), pos.add(0, 0, -1)}, {pos.add(0, 1, 0), pos.add(0, -1, 0)}, {pos.add(1, 0, 0),pos.add(-1, 0, 0)}};
    EnumFacing[][] facing = {{EnumFacing.NORTH, EnumFacing.SOUTH}, {EnumFacing.DOWN, EnumFacing.UP}, {EnumFacing.WEST, EnumFacing.EAST}}; // Facing reversed as blocks are placed while facing in the opposite direction

    for (int i=0; i<6; i++) {
        final Block block = mc.world.getBlockState(posit[i/2][i%2]).getBlock();
        final boolean activated = block.onBlockActivated(mc.world, pos, mc.world.getBlockState(pos), mc.player, EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0);
        if (block != null && block != Blocks.AIR && !(block instanceof BlockLiquid)) {
            if (activated)
                mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.START_SNEAKING));
            if (mc.playerController.processRightClickBlock(mc.player, mc.world, posit[i/2][i%2], facing[i/2][i%2], new Vec3d(0d, 0d, 0d), EnumHand.MAIN_HAND) != EnumActionResult.FAIL)
                mc.player.swingArm(EnumHand.MAIN_HAND);
            if (activated)
                mc.player.connection.sendPacket(new CPacketEntityAction(mc.player, CPacketEntityAction.Action.STOP_SNEAKING));
        }
    }
}
 
Example #12
Source File: MovementHandlerFluid.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
@Override
@Priority(PriorityEnum.OVERRIDE)
public BlockMovementType getMovementType(World world, int x, int y, int z, ForgeDirection side, IMovement movement) {

    Block b = world.getBlock(x, y, z);

    if (b instanceof BlockFluidBase) {
        if (((BlockFluidBase) b).getFilledPercentage(world, x, y, z) == 1F)
            return BlockMovementType.SEMI_MOVABLE;
        return BlockMovementType.UNMOVABLE;
    }
    if (b instanceof BlockLiquid) {
        if (BlockLiquid.getLiquidHeightPercent(world.getBlockMetadata(x, y, z)) == 1 / 9F)
            return BlockMovementType.SEMI_MOVABLE;
        return BlockMovementType.UNMOVABLE;
    }

    return null;
}
 
Example #13
Source File: NukerModule.java    From seppuku with GNU General Public License v3.0 6 votes vote down vote up
private BlockPos getClosestBlockSelection() {
    final Minecraft mc = Minecraft.getMinecraft();
    float maxDist = this.distance.getValue();

    BlockPos ret = null;

    for (float x = maxDist; x >= -maxDist; x--) {
        for (float y = maxDist; y >= -maxDist; y--) {
            for (float z = maxDist; z >= -maxDist; z--) {
                final BlockPos pos = new BlockPos(mc.player.posX + x, mc.player.posY + y, mc.player.posZ + z);
                final double dist = mc.player.getDistance(pos.getX(), pos.getY(), pos.getZ());
                if (dist <= maxDist && (mc.world.getBlockState(pos).getBlock() != Blocks.AIR && !(mc.world.getBlockState(pos).getBlock() instanceof BlockLiquid)) && mc.world.getBlockState(pos).getBlock() == this.selected && canBreak(pos)) {
                    if (pos.getY() >= mc.player.posY) {
                        maxDist = (float) dist;
                        ret = pos;
                    }
                }
            }
        }
    }

    return ret;
}
 
Example #14
Source File: WaterWalk.java    From ehacks-pro with GNU General Public License v3.0 6 votes vote down vote up
public static boolean isOnLiquid(AxisAlignedBB boundingBox) {
    boundingBox = boundingBox.contract(0.01, 0.0, 0.01).offset(0.0, -0.01, 0.0);
    boolean onLiquid = false;
    int y = (int) boundingBox.minY;
    for (int x = MathHelper.floor_double(boundingBox.minX); x < MathHelper.floor_double((boundingBox.maxX + 1.0)); ++x) {
        for (int z = MathHelper.floor_double(boundingBox.minZ); z < MathHelper.floor_double((boundingBox.maxZ + 1.0)); ++z) {
            Block block = Wrapper.INSTANCE.world().getBlock(x, y, z);
            if (block == Blocks.air) {
                continue;
            }
            if (!(block instanceof BlockLiquid)) {
                return false;
            }
            onLiquid = true;
        }
    }
    return onLiquid;
}
 
Example #15
Source File: WaterWalk.java    From ehacks-pro with GNU General Public License v3.0 6 votes vote down vote up
private static boolean isInLiquid() {
    AxisAlignedBB par1AxisAlignedBB = Wrapper.INSTANCE.player().boundingBox.contract(0.001, 0.001, 0.001);
    int minX = MathHelper.floor_double(par1AxisAlignedBB.minX);
    int maxX = MathHelper.floor_double((par1AxisAlignedBB.maxX + 1.0));
    int minY = MathHelper.floor_double(par1AxisAlignedBB.minY);
    int maxY = MathHelper.floor_double((par1AxisAlignedBB.maxY + 1.0));
    int minZ = MathHelper.floor_double(par1AxisAlignedBB.minZ);
    int maxZ = MathHelper.floor_double((par1AxisAlignedBB.maxZ + 1.0));
    if (!Wrapper.INSTANCE.world().checkChunksExist(minX, minY, minZ, maxX, maxY, maxZ)) {
        return false;
    }
    for (int X = minX; X < maxX; ++X) {
        for (int Y = minY; Y < maxY; ++Y) {
            for (int Z = minZ; Z < maxZ; ++Z) {
                Block block = Wrapper.INSTANCE.world().getBlock(X, Y, Z);
                if (!(block instanceof BlockLiquid)) {
                    continue;
                }
                return true;
            }
        }
    }
    return false;
}
 
Example #16
Source File: ItemSyringe.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void onUsingTick(ItemStack stack, EntityLivingBase player, int count) {
	if (!(player instanceof EntityPlayer)) return;
	if (player.world.isRemote) return;

	if (count <= 1) {
		player.swingArm(player.getActiveHand());
		((EntityPlayer) player).getCooldownTracker().setCooldown(this, 30);

		if (stack.getItemDamage() == 2) {
			player.addPotionEffect(new PotionEffect(ModPotions.STEROID, 500, 0, true, false));
			stack.setItemDamage(0);
		} else if (stack.getItemDamage() == 1) {
			ManaManager.forObject(player)
					.addMana(ManaManager.getMaxMana(player))
					.close();
			player.attackEntityFrom(DamageSourceMana.INSTANCE, 2);
			stack.setItemDamage(0);
		} else if (stack.getItemDamage() == 0) {

			RayTraceResult raytraceresult = this.rayTrace(player.world, (EntityPlayer) player, true);

			if (raytraceresult != null && raytraceresult.typeOfHit != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK) {
				BlockPos blockpos = raytraceresult.getBlockPos();
				if (raytraceresult.sideHit == null) raytraceresult.sideHit = EnumFacing.UP;

				if (player.world.isBlockModifiable((EntityPlayer) player, blockpos)
						&& ((EntityPlayer) player).canPlayerEdit(blockpos.offset(raytraceresult.sideHit), raytraceresult.sideHit, stack)) {

					IBlockState iblockstate = player.world.getBlockState(blockpos);

					Fluid fluid = FluidRegistry.lookupFluidForBlock(iblockstate.getBlock());
					if (fluid != null && fluid == ModFluids.MANA && iblockstate.getValue(BlockLiquid.LEVEL) == 0) {
						stack.setItemDamage(1);
					}
				}
			}
		}
	}
}
 
Example #17
Source File: GlideHack.java    From ForgeWurst with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onUpdate(WUpdateEvent event)
{
	EntityPlayerSP player = event.getPlayer();
	World world = WPlayer.getWorld(player);
	
	if(!player.isAirBorne || player.isInWater() || player.isInLava()
		|| player.isOnLadder() || player.motionY >= 0)
		return;
	
	if(minHeight.getValue() > 0)
	{
		AxisAlignedBB box = player.getEntityBoundingBox();
		box = box.union(box.offset(0, -minHeight.getValue(), 0));
		// Using expand() with negative values doesn't work in 1.10.2.
		if(world.collidesWithAnyBlock(box))
			return;
		
		BlockPos min =
			new BlockPos(new Vec3d(box.minX, box.minY, box.minZ));
		BlockPos max =
			new BlockPos(new Vec3d(box.maxX, box.maxY, box.maxZ));
		Stream<BlockPos> stream = StreamSupport
			.stream(BlockPos.getAllInBox(min, max).spliterator(), true);
		
		// manual collision check, since liquids don't have bounding boxes
		if(stream.map(BlockUtils::getBlock)
			.anyMatch(b -> b instanceof BlockLiquid))
			return;
	}
	
	player.motionY = Math.max(player.motionY, -fallSpeed.getValue());
	player.jumpMovementFactor *= moveSpeed.getValueF();
}
 
Example #18
Source File: MobSpawnEspHack.java    From ForgeWurst with GNU General Public License v3.0 5 votes vote down vote up
private void scan()
{
	BlockPos min = new BlockPos(WChunk.getX(chunk) << 4, 0,
		WChunk.getZ(chunk) << 4);
	BlockPos max = new BlockPos((WChunk.getX(chunk) << 4) + 15, 255,
		(WChunk.getZ(chunk) << 4) + 15);
	
	Stream<BlockPos> stream = StreamSupport
		.stream(BlockPos.getAllInBox(min, max).spliterator(), false);
	
	WorldClient world = WMinecraft.getWorld();
	List<BlockPos> blocks = stream.filter(pos -> {
		return !BlockUtils.getMaterial(pos).blocksMovement()
			&& !(BlockUtils.getBlock(pos) instanceof BlockLiquid)
			&& BlockUtils.getState(pos.down()).isSideSolid(world,
				pos.down(), EnumFacing.UP);
	}).collect(Collectors.toList());
	
	if(Thread.interrupted())
		return;
	
	red.addAll(blocks.stream()
		.filter(pos -> world.getLightFor(EnumSkyBlock.BLOCK, pos) < 8)
		.filter(pos -> world.getLightFor(EnumSkyBlock.SKY, pos) < 8)
		.collect(Collectors.toList()));
	
	if(Thread.interrupted())
		return;
	
	yellow.addAll(blocks.stream().filter(pos -> !red.contains(pos))
		.filter(pos -> world.getLightFor(EnumSkyBlock.BLOCK, pos) < 8)
		.collect(Collectors.toList()));
	doneScanning = true;
}
 
Example #19
Source File: Nuker.java    From ForgeHax with MIT License 5 votes vote down vote up
private boolean isNeighborsLiquid(UniqueBlock ub) {
  return filter_liquids.get()
      && Arrays.stream(EnumFacing.values())
      .map(side -> ub.getPos().offset(side))
      .map(pos -> getWorld().getBlockState(pos).getBlock())
      .anyMatch(BlockLiquid.class::isInstance);
}
 
Example #20
Source File: WorldGenIronSand.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
	public void generate(Random rand, int chunkX, int chunkZ, World worldIn, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
		  for (int i = 0; i < block_count; i++) {
	            int rX = (chunkX  * 16) + rand.nextInt(16) + 8;
	            int rY = 48 + rand.nextInt(19);
	            int rZ = (chunkZ  * 16) + rand.nextInt(16) + 8;
	            BlockPos pos = new BlockPos(rX, rY, rZ);
	            IBlockState stateAt = worldIn.getBlockState(pos);
	            if(!stateAt.getBlock().equals(Blocks.SAND)) {
	                continue;
	            }

	            boolean canSpawn = false;
	            for (int yy = 0; yy < 2; yy++) {
	                BlockPos check = pos.offset(EnumFacing.UP, yy);
	                IBlockState bs = worldIn.getBlockState(check);
	                Block block = bs.getBlock();
	                if(worldIn.getBiome(pos) instanceof BiomeBeach|| worldIn.getBiome(pos) instanceof BiomeRiver)
	                if((worldIn.isAirBlock(pos.up())||block instanceof BlockLiquid && bs.getMaterial() == Material.WATER)) {
	                    canSpawn = true;
	                    break;
	                }
	            }
	            if(!canSpawn)
	                continue;
	            worldIn.setBlockState(pos, BlockLoader.IRON_SAND.getDefaultState());
//	            SakuraMain.logger.info(String.format("Iron Sand in: %d %d %d", pos.getX(),pos.getY(),pos.getZ()));
	        }
	}
 
Example #21
Source File: BlockPhysicsDetails.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
private static double getMassOfBlock(Block block) {
    if (block instanceof BlockLiquid) {
        return 0D;
    } else if (blockToMass.get(block) != null) {
        return blockToMass.get(block);
    } else {
        return getMassOfMaterial(block.material);
    }
}
 
Example #22
Source File: TileEntityQBlock.java    From qcraft-mod with Apache License 2.0 5 votes vote down vote up
private boolean isTouchingLiquid()
{
    for( int i = 1; i < 6; ++i ) // ignore down
    {
        int x = xCoord + Facing.offsetsXForSide[ i ];
        int y = yCoord + Facing.offsetsYForSide[ i ];
        int z = zCoord + Facing.offsetsZForSide[ i ];
        Block block = worldObj.getBlock( x, y, z );
        if( block != null && block instanceof BlockLiquid )
        {
            return true;
        }
    }
    return false;
}
 
Example #23
Source File: BlockWaterHyacinth.java    From Production-Line with MIT License 5 votes vote down vote up
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) {
    if (pos.getY() >= 0 && pos.getY() < 256) {
        IBlockState iblockstate = worldIn.getBlockState(pos.down());
        Material material = iblockstate.getMaterial();
        return material == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL) == 0 || material == Material.ICE;
    } else {
        return false;
    }
}
 
Example #24
Source File: ItemEntityEgg.java    From Et-Futurum with The Unlicense 5 votes vote down vote up
@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;
		}
	}
}
 
Example #25
Source File: SchematicBlock.java    From Framez with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BuildingStage getBuildStage () {
	if (block instanceof BlockFalling) {
		return BuildingStage.SUPPORTED;
	} else if (block instanceof BlockFluidBase || block instanceof BlockLiquid) {
		return BuildingStage.EXPANDING;
	} else if (block.isOpaqueCube()) {
		return BuildingStage.STANDALONE;
	} else {
		return BuildingStage.SUPPORTED;
	}
}
 
Example #26
Source File: BlockTerra.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Determines if this block can support the passed in plant, allowing it to be planted and grow.
 * Some examples:
 *   Reeds check if its a reed, or if its sand/dirt/grass and adjacent to water
 *   Cacti checks if its a cacti, or if its sand
 *   Nether types check for soul sand
 *   Crops check for tilled soil
 *   Caves check if it's a solid surface
 *   Plains check if its grass or dirt
 *   Water check if its still water
 *
 * @param world The current world
 * @param pos Block position in world
 * @param direction The direction relative to the given position the plant wants to be, typically its UP
 * @param plantable The plant that wants to check
 * @return True to allow the plant to be planted/stay.
 */
@Override
public boolean canSustainPlant(IBlockState state, IBlockAccess world, BlockPos pos, EnumFacing direction, net.minecraftforge.common.IPlantable plantable)
{
	IBlockState plant = plantable.getPlant(world, pos.offset(direction));
	net.minecraftforge.common.EnumPlantType plantType = plantable.getPlantType(world, pos.offset(direction));

	/*if (plantable instanceof BlockBush)
	{
		return true;
	}*/

	switch (plantType)
	{
	case Desert: return this == TFCBlocks.Sand || this == net.minecraft.init.Blocks.HARDENED_CLAY || this == net.minecraft.init.Blocks.STAINED_HARDENED_CLAY || this == TFCBlocks.Dirt;
	case Nether: return this == Blocks.SOUL_SAND;
	case Crop:   return this == TFCBlocks.Farmland;
	case Cave:   return isSideSolid(state, world, pos, EnumFacing.UP);
	case Plains: return this == TFCBlocks.Grass || this == TFCBlocks.Dirt || this == TFCBlocks.Farmland;
	case Water:  return getMaterial(state) == Material.WATER && ((Integer)state.getValue(BlockLiquid.LEVEL)) == 0;
	case Beach:
		boolean isBeach = this == TFCBlocks.Grass || this == TFCBlocks.Dirt || this == TFCBlocks.Sand;
		boolean hasWater = (world.getBlockState(pos.east()).getBlock().getMaterial(world.getBlockState(pos.east())) == Material.WATER ||
				world.getBlockState(pos.west()).getBlock().getMaterial(world.getBlockState(pos.west())) == Material.WATER ||
				world.getBlockState(pos.north()).getBlock().getMaterial(world.getBlockState(pos.north())) == Material.WATER ||
				world.getBlockState(pos.south()).getBlock().getMaterial(world.getBlockState(pos.south())) == Material.WATER);
		return isBeach && hasWater;
	}

	return false;
}
 
Example #27
Source File: MetaTileEntityPump.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void checkFluidBlockAt(BlockPos pumpHeadPos, BlockPos checkPos) {
    IBlockState blockHere = getWorld().getBlockState(checkPos);
    boolean shouldCheckNeighbours = isStraightInPumpRange(checkPos);

    if (blockHere.getBlock() instanceof BlockLiquid ||
        blockHere.getBlock() instanceof IFluidBlock) {
        IFluidHandler fluidHandler = FluidUtil.getFluidHandler(getWorld(), checkPos, null);
        FluidStack drainStack = fluidHandler.drain(Integer.MAX_VALUE, false);
        if (drainStack != null && drainStack.amount > 0) {
            this.fluidSourceBlocks.add(checkPos);
        }
        shouldCheckNeighbours = true;
    }

    if (shouldCheckNeighbours) {
        int maxPumpRange = getMaxPumpRange();
        for (EnumFacing facing : EnumFacing.VALUES) {
            BlockPos offsetPos = checkPos.offset(facing);
            if (offsetPos.distanceSq(pumpHeadPos) > maxPumpRange * maxPumpRange)
                continue; //do not add blocks outside bounds
            if (!fluidSourceBlocks.contains(offsetPos) &&
                !blocksToCheck.contains(offsetPos)) {
                this.blocksToCheck.add(offsetPos);
            }
        }
    }
}
 
Example #28
Source File: MetaTileEntityFisher.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void update() {
    super.update();
    ItemStack baitStack = importItems.getStackInSlot(0);
    if (!getWorld().isRemote && energyContainer.getEnergyStored() >= energyAmountPerFish && getTimer() % fishingTicks == 0L && !baitStack.isEmpty()) {
        WorldServer world = (WorldServer) this.getWorld();
        int waterCount = 0;
        int edgeSize = (int) Math.sqrt(WATER_CHECK_SIZE);
        for (int x = 0; x < edgeSize; x++){
            for (int z = 0; z < edgeSize; z++){
                BlockPos waterCheckPos = getPos().down().add(x - edgeSize / 2, 0, z - edgeSize / 2);
                if (world.getBlockState(waterCheckPos).getBlock() instanceof BlockLiquid &&
                    world.getBlockState(waterCheckPos).getMaterial() == Material.WATER) {
                    waterCount++;
                }
            }
        }
        if (waterCount == WATER_CHECK_SIZE) {
            LootTable table = world.getLootTableManager().getLootTableFromLocation(LootTableList.GAMEPLAY_FISHING);
            NonNullList<ItemStack> itemStacks = NonNullList.create();
            itemStacks.addAll(table.generateLootForPools(world.rand, new LootContext.Builder(world).build()));
            if(addItemsToItemHandler(exportItems, true, itemStacks)) {
                addItemsToItemHandler(exportItems, false, itemStacks);
                energyContainer.removeEnergy(energyAmountPerFish);
                baitStack.shrink(1);
            }
        }
    }
    if(!getWorld().isRemote && getTimer() % 5 == 0) {
        pushItemsIntoNearbyHandlers(getFrontFacing());
    }
}
 
Example #29
Source File: LiquidWalk.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@EventTarget
public void onJump(final JumpEvent event) {
    if (mc.thePlayer == null)
        return;

    final Block block = BlockUtils.getBlock(new BlockPos(mc.thePlayer.posX, mc.thePlayer.posY - 0.01, mc.thePlayer.posZ));

    if (noJumpValue.get() && block instanceof BlockLiquid)
        event.cancelEvent();
}
 
Example #30
Source File: LiquidWalk.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@EventTarget
public void onPacket(final PacketEvent event) {
    if(mc.thePlayer == null || !modeValue.get().equalsIgnoreCase("NCP"))
        return;

    if(event.getPacket() instanceof C03PacketPlayer) {
        final C03PacketPlayer packetPlayer = (C03PacketPlayer) event.getPacket();

        if(BlockUtils.collideBlock(new AxisAlignedBB(mc.thePlayer.getEntityBoundingBox().maxX, mc.thePlayer.getEntityBoundingBox().maxY, mc.thePlayer.getEntityBoundingBox().maxZ, mc.thePlayer.getEntityBoundingBox().minX, mc.thePlayer.getEntityBoundingBox().minY - 0.01D, mc.thePlayer.getEntityBoundingBox().minZ), block -> block instanceof BlockLiquid)) {
            nextTick = !nextTick;

            if(nextTick) packetPlayer.y -= 0.001D;
        }
    }
}