Java Code Examples for net.minecraft.util.math.BlockPos#down()
The following examples show how to use
net.minecraft.util.math.BlockPos#down() .
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: QuestEnemyEncampment.java From ToroQuest with GNU General Public License v3.0 | 6 votes |
private BlockPos findSurface(QuestData data, int x, int z, boolean force) { World world = data.getPlayer().getEntityWorld(); BlockPos pos = new BlockPos(x, world.getActualHeight(), z); IBlockState blockState; while (pos.getY() > 0) { blockState = world.getBlockState(pos); if (!force && isLiquid(blockState)) { return null; } if (isGroundBlock(blockState)) { break; } pos = pos.down(); } return pos.up(); }
Example 2
Source File: BlockEngineeringTable.java From Cyberware with MIT License | 6 votes |
@Override public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player) { BlockPos blockpos = pos.down(); BlockPos blockpos1 = pos.up(); if (player.capabilities.isCreativeMode && state.getValue(HALF) == EnumEngineeringHalf.UPPER && worldIn.getBlockState(blockpos).getBlock() == this) { worldIn.setBlockToAir(blockpos); } if (state.getValue(HALF) == EnumEngineeringHalf.LOWER && worldIn.getBlockState(blockpos1).getBlock() == this) { if (player.capabilities.isCreativeMode) { worldIn.setBlockToAir(pos); } worldIn.setBlockToAir(blockpos1); } }
Example 3
Source File: BlockGravity.java From TFC2 with GNU General Public License v3.0 | 6 votes |
protected void fall(World worldIn, BlockPos pos, IBlockState state) { int i = 32; if ((!BlockFalling.fallInstantly) && (worldIn.isAreaLoaded(pos.add(-i, -i, -i), pos.add(i, i, i)))) { if (!worldIn.isRemote) { EntityFallingBlockTFC entityfallingblock = new EntityFallingBlockTFC(worldIn, pos.getX() + 0.5D, pos.getY(), pos.getZ() + 0.5D, state); onStartFalling(entityfallingblock); worldIn.spawnEntity(entityfallingblock); } } else { ((World)worldIn).setBlockToAir(pos); BlockPos blockpos; for (blockpos = pos.down(); (canFallInto(worldIn, blockpos)) && (blockpos.getY() > 0); blockpos = blockpos.down()) {} if (blockpos.getY() > 0) { worldIn.setBlockState(blockpos.up(), getDefaultState()); } } }
Example 4
Source File: BlockSurgeryChamber.java From Cyberware with MIT License | 6 votes |
public void toggleDoor(boolean top, IBlockState state, BlockPos pos, World worldIn) { state = state.cycleProperty(OPEN); worldIn.setBlockState(pos, state, 2); BlockPos otherPos = pos.up(); if (top) { otherPos = pos.down(); } IBlockState otherState = worldIn.getBlockState(otherPos); if (otherState.getBlock() == this) { otherState = otherState.cycleProperty(OPEN); worldIn.setBlockState(otherPos, otherState, 2); } }
Example 5
Source File: BlockMetalDoor.java From BaseMetals with GNU Lesser General Public License v2.1 | 6 votes |
@Override public boolean onBlockActivated(final World world, final BlockPos coord, IBlockState blockstate, final EntityPlayer player, final EnumHand hand, ItemStack heldItem, final EnumFacing face, final float partialX, final float partialY, final float partialZ) { if (this.metal.getToolHarvestLevel() > 1) { return false; } final BlockPos pos = (blockstate.getValue(BlockDoor.HALF) == EnumDoorHalf.LOWER) ? coord : coord.down(); final IBlockState bs = coord.equals(pos) ? blockstate : world.getBlockState(pos); if (bs.getBlock() != this) { return false; } blockstate = bs.cycleProperty(BlockDoor.OPEN); world.setBlockState(pos, blockstate, 2); world.markBlockRangeForRenderUpdate(pos, coord); world.playEvent(player, ((Boolean)blockstate.getValue(BlockDoor.OPEN)) ? 1003 : 1006, coord, 0); return true; }
Example 6
Source File: TofuCastlePiece.java From TofuCraftReload with MIT License | 5 votes |
private static void generateUnderGround(TemplateManager templateManager, BlockPos pos, Rotation rotation, List<TofuCastleTemplate> list, Random random) { BlockPos pos1 = new BlockPos(pos.down(19)); BlockPos pos2 = new BlockPos(pos1.south(23).east(4)); BlockPos pos3 = new BlockPos(pos1.south(-15).east(4)); BlockPos pos4 = new BlockPos(pos1.south(23 + 15).down(11)); generateUnderSub(templateManager, pos2, rotation, list, random); generateUnderSub(templateManager, pos3, rotation, list, random); list.add(new TofuCastlePiece.TofuCastleTemplate(templateManager, pos1, rotation, "tofucastle_undermain")); list.add(new TofuCastlePiece.TofuCastleTemplate(templateManager, pos4, rotation, "tofucastle_bossroom")); }
Example 7
Source File: SmallDeadwoodTreeFeature.java From the-hallow with MIT License | 5 votes |
private void makeVines(ModifiableTestableWorld world, BlockPos pos, BooleanProperty boolProp) { BlockState state = HallowedBlocks.DEADWOOD_VINES.getDefaultState().with(boolProp, true); this.setBlockState(world, pos, state); int yOffset = 4; for (pos = pos.down(); isAir(world, pos) && yOffset > 0; --yOffset) { this.setBlockState(world, pos, state); pos = pos.down(); } }
Example 8
Source File: BlockApricotSapling.java From TofuCraftReload with MIT License | 5 votes |
@Override public boolean canBlockStay(World world, BlockPos pos, IBlockState state) { BlockPos down = pos.down(); IBlockState soil = world.getBlockState(down); return soil.getBlock().canSustainPlant(soil, world, down, EnumFacing.UP, this); }
Example 9
Source File: Job.java From CommunityMod with GNU Lesser General Public License v2.1 | 5 votes |
/** * Alters the location's y-coordinate to be on the next air block touching a non-air block below it, * using the same x- and z-coordinates * searches up first, then down * ALTERS THE PASSED INTLOC. Also returns it. */ public static BlockPos groundify(World world, BlockPos loc) { if (loc == null) { return null; } int ytemp = loc.getY(); if (ytemp < 2) { ytemp = 2; } if (ytemp > 255) { ytemp = 255; } BlockPos tempLoc = new BlockPos(loc.getX(), ytemp, loc.getZ()); //System.out.println("Groundifying " + tempLoc); // go down until found ground while (WorldHelper.isAirLikeBlock(world, tempLoc) && tempLoc.getY() > 2) { //System.out.println("Block at " + tempLoc + " is airblock, moving down"); tempLoc = tempLoc.down(); } // go up until found air while (!WorldHelper.isAirLikeBlock(world, tempLoc) && tempLoc.getY() < 255) { //System.out.println("Block at " + tempLoc + " is NOT airblock, moving up"); tempLoc = tempLoc.up(); } //System.out.println("Grounded to " + tempLoc); return tempLoc; }
Example 10
Source File: BlockCactus.java From TFC2 with GNU General Public License v3.0 | 5 votes |
public boolean canBlockStay(World worldIn, BlockPos pos, IBlockState state) { BlockPos down = pos.down(); IBlockState soil = worldIn.getBlockState(down); if (state.getBlock() != this) return canPlaceBlockOn(state, soil); return soil.getBlock().canSustainPlant(soil, worldIn, down, EnumFacing.UP, this); }
Example 11
Source File: BlockMapleSaplingGreen.java From Sakura_mod with MIT License | 5 votes |
@Override public boolean canBlockStay(World world, BlockPos pos, IBlockState state) { BlockPos down = pos.down(); IBlockState soil = world.getBlockState(down); return soil.getBlock().canSustainPlant(soil, world, down, EnumFacing.UP, this); }
Example 12
Source File: GraveyardGenerator.java From ToroQuest with GNU General Public License v3.0 | 5 votes |
private void placeDownward(BlockPos pos, IBlockState block) { IBlockState blockState = null; while (pos.getY() > 0 && !isGroundBlock(blockState)) { place(pos, block); pos = pos.down(); blockState = world.getBlockState(pos); } }
Example 13
Source File: BreadCrumbsBlock.java From the-hallow with MIT License | 4 votes |
@SuppressWarnings("deprecation") @Override public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { BlockPos down = pos.down(); return Block.isFaceFullSquare(world.getBlockState(down).getCollisionShape(world, down), Direction.UP); }
Example 14
Source File: BlockRiceCrop.java From Sakura_mod with MIT License | 4 votes |
protected float getRiceGrowthChance(Block blockIn, World worldIn, BlockPos pos) { float f = 1.0F; BlockPos blockpos = pos.down(); for (int i = -1; i <= 1; ++i) { for (int j = -1; j <= 1; ++j) { float f1 = 0.0F; IBlockState iblockstate = worldIn.getBlockState(blockpos.add(i, 0, j)); if (iblockstate.getBlock().canSustainPlant(iblockstate, worldIn, blockpos.add(i, 0, j), net.minecraft.util.EnumFacing.UP, (net.minecraftforge.common.IPlantable) blockIn)) { f1 = 1.0F; if (this.isWater(worldIn, blockpos.add(i, 0, j))) { f1 = 3.0F; } } if (i != 0 || j != 0) { f1 /= 4.0F; } f += f1; } } BlockPos blockpos1 = pos.north(); BlockPos blockpos2 = pos.south(); BlockPos blockpos3 = pos.west(); BlockPos blockpos4 = pos.east(); boolean flag = blockIn == worldIn.getBlockState(blockpos3).getBlock() || blockIn == worldIn.getBlockState(blockpos4).getBlock(); boolean flag1 = blockIn == worldIn.getBlockState(blockpos1).getBlock() || blockIn == worldIn.getBlockState(blockpos2).getBlock(); if (flag && flag1) { f /= 2.0F; } else { boolean flag2 = blockIn == worldIn.getBlockState(blockpos3.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.south()).getBlock() || blockIn == worldIn.getBlockState(blockpos3.south()).getBlock(); if (flag2) { f /= 2.0F; } } return f; }
Example 15
Source File: WeatherRenderer.java From TFC2 with GNU General Public License v3.0 | 4 votes |
public static void addRainParticles(Random random, int rendererUpdateCount) { Minecraft mc = Minecraft.getMinecraft(); WorldClient worldclient = mc.world; if(worldclient.provider.getDimension() != 0) return; float rainStrength = (float)WeatherManager.getInstance().getPrecipitation((int)mc.player.posX, (int)mc.player.posZ); double tempPlayer = WeatherManager.getInstance().getTemperature((int)mc.player.posX,(int)mc.player.posY, (int)mc.player.posZ); if(tempPlayer <= 0) return; if (!mc.gameSettings.fancyGraphics) { rainStrength /= 2.0F; } if (rainStrength > 0.0F) { worldclient.rand.setSeed((long)rendererUpdateCount * 312987231L); Entity entity = mc.getRenderViewEntity(); BlockPos blockpos = new BlockPos(entity); byte b0 = 10; double d0 = 0.0D; double d1 = 0.0D; double d2 = 0.0D; int i = 0; int rainParticles = Math.max((int)(100.0F * rainStrength * rainStrength), 4); if (mc.gameSettings.particleSetting == 1) { rainParticles >>= 1; } else if (mc.gameSettings.particleSetting == 2) { rainParticles = 0; } for (int k = 0; k < rainParticles; ++k) { BlockPos blockPos1 = worldclient.getPrecipitationHeight(blockpos.add(worldclient.rand.nextInt(b0) - worldclient.rand.nextInt(b0), 0, worldclient.rand.nextInt(b0) - worldclient.rand.nextInt(b0))); double temp = WeatherManager.getInstance().getTemperature(blockPos1); BlockPos blockpos2 = blockPos1.down(); IBlockState state = worldclient.getBlockState(blockpos2); Block block = worldclient.getBlockState(blockpos2).getBlock(); if (blockPos1.getY() <= blockpos.getY() + b0 && blockPos1.getY() >= blockpos.getY() - b0 && temp > 0) { float f1 = worldclient.rand.nextFloat(); float f2 = worldclient.rand.nextFloat(); AxisAlignedBB axisalignedbb = state.getBoundingBox(worldclient, blockpos2); if (block.getMaterial(state) == Material.LAVA) { mc.world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, (double)((float)blockPos1.getX() + f1), (double)((float)blockPos1.getY() + 0.1F) - axisalignedbb.minY, (double)((float)blockPos1.getZ() + f2), 0.0D, 0.0D, 0.0D, new int[0]); } else if (block.getMaterial(state) != Material.AIR) { //block.setBlockBoundsBasedOnState(worldclient, blockpos2); ++i; if (worldclient.rand.nextInt(i) == 0) { d0 = (double)((float)blockpos2.getX() + f1); d1 = (double)((float)blockpos2.getY() + 0.1F) + axisalignedbb.maxY - 1.0D; d2 = (double)((float)blockpos2.getZ() + f2); } mc.world.spawnParticle(EnumParticleTypes.WATER_DROP, (double)((float)blockpos2.getX() + f1), (double)((float)blockpos2.getY() + 0.1F) + axisalignedbb.maxY, (double)((float)blockpos2.getZ() + f2), 0.0D, 0.0D, 0.0D, new int[0]); } } } if (i > 0 && worldclient.rand.nextInt(3) < rainSoundCounter++) { rainSoundCounter = 0; if (d1 > (double)(blockpos.getY() + 1) && worldclient.getPrecipitationHeight(blockpos).getY() > MathHelper.floor((float)blockpos.getY())) { mc.world.playSound(d0, d1, d2, SoundEvents.WEATHER_RAIN_ABOVE, SoundCategory.WEATHER, 0.1F*rainStrength, 0.5F, false); } else { mc.world.playSound(d0, d1, d2, SoundEvents.WEATHER_RAIN, SoundCategory.WEATHER, 0.2F*rainStrength, 1.0F, false); } } } }
Example 16
Source File: BlockRice.java From TofuCraftReload with MIT License | 4 votes |
protected float getRiceGrowthChance(Block blockIn, World worldIn, BlockPos pos) { float f = 1.0F; BlockPos blockpos = pos.down(); for (int i = -1; i <= 1; ++i) { for (int j = -1; j <= 1; ++j) { float f1 = 0.0F; IBlockState iblockstate = worldIn.getBlockState(blockpos.add(i, 0, j)); if (iblockstate.getBlock().canSustainPlant(iblockstate, worldIn, blockpos.add(i, 0, j), net.minecraft.util.EnumFacing.UP, (net.minecraftforge.common.IPlantable) blockIn)) { f1 = 1.0F; if (this.isWater(worldIn, blockpos.add(i, 0, j))) { f1 = 3.0F; } } if (i != 0 || j != 0) { f1 /= 4.0F; } f += f1; } } BlockPos blockpos1 = pos.north(); BlockPos blockpos2 = pos.south(); BlockPos blockpos3 = pos.west(); BlockPos blockpos4 = pos.east(); boolean flag = blockIn == worldIn.getBlockState(blockpos3).getBlock() || blockIn == worldIn.getBlockState(blockpos4).getBlock(); boolean flag1 = blockIn == worldIn.getBlockState(blockpos1).getBlock() || blockIn == worldIn.getBlockState(blockpos2).getBlock(); if (flag && flag1) { f /= 2.0F; } else { boolean flag2 = blockIn == worldIn.getBlockState(blockpos3.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.north()).getBlock() || blockIn == worldIn.getBlockState(blockpos4.south()).getBlock() || blockIn == worldIn.getBlockState(blockpos3.south()).getBlock(); if (flag2) { f /= 2.0F; } } return f; }
Example 17
Source File: TorikkiIceSpike.java From Wizardry with GNU Lesser General Public License v3.0 | 4 votes |
public boolean generate(World worldIn, Random rand, BlockPos position) { while (worldIn.isAirBlock(position) && position.getY() > 2) { position = position.down(); } if (worldIn.getBlockState(position).getBlock() != Blocks.SNOW) { return false; } else { position = position.up(rand.nextInt(4)); int i = rand.nextInt(4) + 7; int j = i / 4 + rand.nextInt(2); if (j > 1 && rand.nextInt(60) == 0) { position = position.up(10 + rand.nextInt(30)); } for (int k = 0; k < i; ++k) { float f = (1.0F - (float) k / (float) i) * (float) j; int l = MathHelper.ceil(f); for (int i1 = -l; i1 <= l; ++i1) { float f1 = (float) MathHelper.abs(i1) - 0.25F; for (int j1 = -l; j1 <= l; ++j1) { float f2 = (float) MathHelper.abs(j1) - 0.25F; if ((i1 == 0 && j1 == 0 || f1 * f1 + f2 * f2 <= f * f) && (i1 != -l && i1 != l && j1 != -l && j1 != l || rand.nextFloat() <= 0.75F)) { IBlockState iblockstate = worldIn.getBlockState(position.add(i1, k, j1)); Block block = iblockstate.getBlock(); if (iblockstate.getBlock().isAir(iblockstate, worldIn, position.add(i1, k, j1)) || block == Blocks.DIRT || block == Blocks.SNOW || block == Blocks.ICE) { this.setBlockAndNotifyAdequately(worldIn, position.add(i1, k, j1), Blocks.PACKED_ICE.getDefaultState()); } if (k != 0 && l > 1) { iblockstate = worldIn.getBlockState(position.add(i1, -k, j1)); block = iblockstate.getBlock(); if (iblockstate.getBlock().isAir(iblockstate, worldIn, position.add(i1, -k, j1)) || block == Blocks.DIRT || block == Blocks.SNOW || block == Blocks.ICE) { this.setBlockAndNotifyAdequately(worldIn, position.add(i1, -k, j1), Blocks.PACKED_ICE.getDefaultState()); } } } } } } int k1 = j - 1; if (k1 < 0) { k1 = 0; } else if (k1 > 1) { k1 = 1; } for (int l1 = -k1; l1 <= k1; ++l1) { for (int i2 = -k1; i2 <= k1; ++i2) { BlockPos blockpos = position.add(l1, -1, i2); int j2 = 50; if (Math.abs(l1) == 1 && Math.abs(i2) == 1) { j2 = rand.nextInt(5); } while (blockpos.getY() > 50) { IBlockState iblockstate1 = worldIn.getBlockState(blockpos); Block block1 = iblockstate1.getBlock(); if (!iblockstate1.getBlock().isAir(iblockstate1, worldIn, blockpos) && block1 != Blocks.DIRT && block1 != Blocks.SNOW && block1 != Blocks.ICE && block1 != Blocks.PACKED_ICE) { break; } this.setBlockAndNotifyAdequately(worldIn, blockpos, Blocks.PACKED_ICE.getDefaultState()); blockpos = blockpos.down(); --j2; if (j2 <= 0) { blockpos = blockpos.down(rand.nextInt(5) + 1); j2 = rand.nextInt(5); } } } } return true; } }
Example 18
Source File: PlatformCommand.java From YUNoMakeGoodMap with Apache License 2.0 | 4 votes |
@Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { if (args.length < 1) throw new WrongUsageException(getUsage(sender)); String cmd = args[0].toLowerCase(Locale.ENGLISH); if ("list".equals(cmd)) { sender.sendMessage(new TextComponentString("Known Platforms:")); for (ResourceLocation rl : getPlatforms()) { sender.sendMessage(new TextComponentString(" " + rl.toString())); } } else if ("spawn".equals(cmd) || "preview".equals(cmd)) { if (args.length < 2) throw new WrongUsageException(getUsage(sender)); Entity ent = sender.getCommandSenderEntity(); PlacementSettings settings = new PlacementSettings(); WorldServer world = (WorldServer)sender.getEntityWorld(); if (args.length >= 3) { //TODO: Preview doesnt quite work correctly with rotations.... String rot = args[2].toLowerCase(Locale.ENGLISH); if ("0".equals(rot) || "none".equals(rot)) settings.setRotation(Rotation.NONE); else if ("90".equals(rot)) settings.setRotation(Rotation.CLOCKWISE_90); else if ("180".equals(rot)) settings.setRotation(Rotation.CLOCKWISE_180); else if ("270".equals(rot)) settings.setRotation(Rotation.COUNTERCLOCKWISE_90); else throw new WrongUsageException("Only rotations none, 0, 90, 180, and 270 allowed."); } BlockPos pos; if (args.length >= 6) pos = CommandBase.parseBlockPos(sender, args, 3, false); else if (ent != null) pos = ent.getPosition(); else throw new WrongUsageException("Must specify a position if the command sender is not an entity"); Template temp = StructureUtil.loadTemplate(new ResourceLocation(args[1]), world, true); BlockPos spawn = StructureUtil.findSpawn(temp, settings); if (spawn != null) pos = pos.subtract(spawn); if ("spawn".equals(cmd)) { sender.sendMessage(new TextComponentString("Building \"" + args[1] +"\" at " + pos.toString())); temp.addBlocksToWorld(world, pos, settings, 2); //Push to world, with no neighbor notifications! world.getPendingBlockUpdates(new StructureBoundingBox(pos, pos.add(temp.getSize())), true); //Remove block updates, so that sand doesn't fall! } else { BlockPos tpos = pos.down(); if (spawn != null) tpos = tpos.add(spawn); sender.sendMessage(new TextComponentString("Previewing \"" + args[1] +"\" at " + pos.toString())); world.setBlockState(tpos, Blocks.STRUCTURE_BLOCK.getDefaultState().withProperty(BlockStructure.MODE, TileEntityStructure.Mode.LOAD)); TileEntityStructure te = (TileEntityStructure)world.getTileEntity(tpos); if (spawn != null) te.setPosition(te.getPosition().subtract(spawn)); te.setSize(temp.getSize()); te.setMode(Mode.LOAD); te.markDirty(); } } else throw new WrongUsageException(getUsage(sender)); }
Example 19
Source File: BlockTofuSapling.java From TofuCraftReload with MIT License | 4 votes |
@Override public boolean canBlockStay(World world, BlockPos pos, IBlockState state) { BlockPos down = pos.down(); IBlockState soil = world.getBlockState(down); return soil.getBlock().canSustainPlant(soil, world, down, EnumFacing.UP, this); }
Example 20
Source File: MetaTileEntityPump.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
private void updateQueueState(int blocksToCheckAmount) { BlockPos selfPos = getPos().down(pumpHeadY); for(int i = 0; i < blocksToCheckAmount; i++) { BlockPos checkPos = null; int amountIterated = 0; do { if (checkPos != null) { blocksToCheck.push(checkPos); amountIterated++; } checkPos = blocksToCheck.poll(); } while (checkPos != null && !getWorld().isBlockLoaded(checkPos) && amountIterated < blocksToCheck.size()); if (checkPos != null) { checkFluidBlockAt(selfPos, checkPos); } else break; } if (fluidSourceBlocks.isEmpty()) { if (getTimer() % 20 == 0) { BlockPos downPos = selfPos.down(1); if (downPos != null && downPos.getY() >= 0) { IBlockState downBlock = getWorld().getBlockState(downPos); if (downBlock.getBlock() instanceof BlockLiquid || downBlock.getBlock() instanceof IFluidBlock || !downBlock.isTopSolid()) { this.pumpHeadY++; } } // Always recheck next time writeCustomData(200, b -> b.writeVarInt(pumpHeadY)); markDirty(); //schedule queue rebuild because we changed our position and no fluid is available this.initializedQueue = false; } if (!initializedQueue || getTimer() % 6000 == 0) { this.initializedQueue = true; //just add ourselves to check list and see how this will go this.blocksToCheck.add(selfPos); } } }