Java Code Examples for net.minecraft.world.gen.structure.StructureBoundingBox#isVecInside()
The following examples show how to use
net.minecraft.world.gen.structure.StructureBoundingBox#isVecInside() .
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: StructureTofuVillagePieces.java From TofuCraftReload with MIT License | 6 votes |
/** * Discover the y coordinate that will serve as the ground level of the supplied BoundingBox. (A median of * all the levels in the BB's horizontal rectangle). */ protected int getAverageGroundLevel(World worldIn, StructureBoundingBox structurebb) { int i = 0; int j = 0; BlockPos.MutableBlockPos blockpos$mutableblockpos = new BlockPos.MutableBlockPos(); for (int k = this.boundingBox.minZ; k <= this.boundingBox.maxZ; ++k) { for (int l = this.boundingBox.minX; l <= this.boundingBox.maxX; ++l) { blockpos$mutableblockpos.setPos(l, 64, k); if (structurebb.isVecInside(blockpos$mutableblockpos)) { i += Math.max(worldIn.getTopSolidOrLiquidBlock(blockpos$mutableblockpos).getY(), worldIn.provider.getAverageGroundLevel() - 1); ++j; } } } if (j == 0) { return -1; } else { return i / j; } }
Example 2
Source File: StructureTofuVillagePieces.java From TofuCraftReload with MIT License | 5 votes |
/** * Spawns a number of villagers in this component. Parameters: world, component bounding box, x offset, y * offset, z offset, number of villagers */ protected void spawnVillagers(World worldIn, StructureBoundingBox structurebb, int x, int y, int z, int count) { if (this.villagersSpawned < count) { for (int i = this.villagersSpawned; i < count; ++i) { int j = this.getXWithOffset(x + i, z); int k = this.getYWithOffset(y); int l = this.getZWithOffset(x + i, z); if (!structurebb.isVecInside(new BlockPos(j, k, l))) { break; } ++this.villagersSpawned; if (this.field_189929_i) { EntityZombieVillager entityzombie = new EntityZombieVillager(worldIn); entityzombie.setLocationAndAngles((double) j + 0.5D, (double) k, (double) l + 0.5D, 0.0F, 0.0F); entityzombie.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityzombie)), (IEntityLivingData) null); entityzombie.enablePersistence(); worldIn.spawnEntity(entityzombie); } else { EntityTofunian entityvillager = new EntityTofunian(worldIn); entityvillager.setLocationAndAngles((double) j + 0.5D, (double) k, (double) l + 0.5D, 0.0F, 0.0F); entityvillager.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData) null); worldIn.spawnEntity(entityvillager); } } } }
Example 3
Source File: StructureTofuVillagePieces.java From TofuCraftReload with MIT License | 5 votes |
protected void spawnVillagers(World worldIn, StructureBoundingBox structurebb, int x, int y, int z, int count,int profession) { if (this.villagersSpawned < count) { for (int i = this.villagersSpawned; i < count; ++i) { int j = this.getXWithOffset(x + i, z); int k = this.getYWithOffset(y); int l = this.getZWithOffset(x + i, z); if (!structurebb.isVecInside(new BlockPos(j, k, l))) { break; } ++this.villagersSpawned; if (this.field_189929_i) { EntityZombieVillager entityzombie = new EntityZombieVillager(worldIn); entityzombie.setLocationAndAngles((double) j + 0.5D, (double) k, (double) l + 0.5D, 0.0F, 0.0F); entityzombie.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityzombie)), (IEntityLivingData) null); entityzombie.enablePersistence(); worldIn.spawnEntity(entityzombie); } else { EntityTofunian entityvillager = new EntityTofunian(worldIn); entityvillager.setLocationAndAngles((double) j + 0.5D, (double) k, (double) l + 0.5D, 0.0F, 0.0F); entityvillager.onInitialSpawn(worldIn.getDifficultyForLocation(new BlockPos(entityvillager)), (IEntityLivingData) null); entityvillager.setTofuProfession(profession); worldIn.spawnEntity(entityvillager); } } } }
Example 4
Source File: StructureTofuMineshaftPieces.java From TofuCraftReload with MIT License | 5 votes |
/** * Adds chest to the structure and sets its contents */ protected boolean generateChest(World worldIn, StructureBoundingBox structurebb, Random randomIn, int x, int y, int z, ResourceLocation loot) { BlockPos blockpos = new BlockPos(this.getXWithOffset(x, z), this.getYWithOffset(y), this.getZWithOffset(x, z)); if (structurebb.isVecInside(blockpos) && worldIn.getBlockState(blockpos).getMaterial() == Material.AIR && worldIn.getBlockState(blockpos.down()).getMaterial() != Material.AIR) { IBlockState iblockstate = Blocks.RAIL.getDefaultState().withProperty(BlockRail.SHAPE, randomIn.nextBoolean() ? BlockRailBase.EnumRailDirection.NORTH_SOUTH : BlockRailBase.EnumRailDirection.EAST_WEST); this.setBlockState(worldIn, iblockstate, x, y, z, structurebb); EntityMinecartChest entityminecartchest = new EntityMinecartChest(worldIn, (double) ((float) blockpos.getX() + 0.5F), (double) ((float) blockpos.getY() + 0.5F), (double) ((float) blockpos.getZ() + 0.5F)); entityminecartchest.setLootTable(loot, randomIn.nextLong()); worldIn.spawnEntity(entityminecartchest); return true; } else { return false; } }
Example 5
Source File: StructureTofuMineshaftPieces.java From TofuCraftReload with MIT License | 4 votes |
/** * second Part of Structure generating, this for example places Spiderwebs, Mob Spawners, it closes * Mineshafts at the end, it adds Fences... */ public boolean addComponentParts(World worldIn, Random randomIn, StructureBoundingBox structureBoundingBoxIn) { if (this.isLiquidInStructureBoundingBox(worldIn, structureBoundingBoxIn)) { return false; } else { int i1 = this.sectionCount * 5 - 1; IBlockState iblockstate = this.getPlanksBlock(); this.fillWithBlocks(worldIn, structureBoundingBoxIn, 0, 0, 0, 2, 1, i1, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false); this.generateMaybeBox(worldIn, structureBoundingBoxIn, randomIn, 0.8F, 0, 2, 0, 2, 2, i1, Blocks.AIR.getDefaultState(), Blocks.AIR.getDefaultState(), false, 0); if (this.hasSpiders) { this.generateMaybeBox(worldIn, structureBoundingBoxIn, randomIn, 0.6F, 0, 0, 0, 2, 1, i1, Blocks.WEB.getDefaultState(), Blocks.AIR.getDefaultState(), false, 8); } for (int j1 = 0; j1 < this.sectionCount; ++j1) { int k1 = 2 + j1 * 5; this.placeSupport(worldIn, structureBoundingBoxIn, 0, 0, k1, 2, 2, randomIn); this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 0, 2, k1 - 1); this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 2, 2, k1 - 1); this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 0, 2, k1 + 1); this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.1F, 2, 2, k1 + 1); this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 0, 2, k1 - 2); this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 2, 2, k1 - 2); this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 0, 2, k1 + 2); this.placeCobWeb(worldIn, structureBoundingBoxIn, randomIn, 0.05F, 2, 2, k1 + 2); if (randomIn.nextInt(100) == 0) { this.generateChest(worldIn, structureBoundingBoxIn, randomIn, 2, 0, k1 - 1, TofuLootTables.tofumineshaft); } if (randomIn.nextInt(100) == 0) { this.generateChest(worldIn, structureBoundingBoxIn, randomIn, 0, 0, k1 + 1, TofuLootTables.tofumineshaft); } if (this.hasSpiders && !this.spawnerPlaced) { int l1 = this.getYWithOffset(0); int i2 = k1 - 1 + randomIn.nextInt(3); int j2 = this.getXWithOffset(1, i2); int k2 = this.getZWithOffset(1, i2); BlockPos blockpos = new BlockPos(j2, l1, k2); if (structureBoundingBoxIn.isVecInside(blockpos) && this.getSkyBrightness(worldIn, 1, 0, i2, structureBoundingBoxIn) < 8) { this.spawnerPlaced = true; worldIn.setBlockState(blockpos, Blocks.MOB_SPAWNER.getDefaultState(), 2); TileEntity tileentity = worldIn.getTileEntity(blockpos); if (tileentity instanceof TileEntityMobSpawner) { ((TileEntityMobSpawner) tileentity).getSpawnerBaseLogic().setEntityId(EntityList.getKey(EntityTofuSpider.class)); } } } } for (int l2 = 0; l2 <= 2; ++l2) { for (int i3 = 0; i3 <= i1; ++i3) { IBlockState iblockstate3 = this.getBlockStateFromPos(worldIn, l2, -1, i3, structureBoundingBoxIn); if (iblockstate3.getMaterial() == Material.AIR && this.getSkyBrightness(worldIn, l2, -1, i3, structureBoundingBoxIn) < 8) { this.setBlockState(worldIn, iblockstate, l2, -1, i3, structureBoundingBoxIn); } } } if (this.hasRails) { IBlockState iblockstate1 = Blocks.RAIL.getDefaultState().withProperty(BlockRail.SHAPE, BlockRailBase.EnumRailDirection.NORTH_SOUTH); for (int j3 = 0; j3 <= i1; ++j3) { IBlockState iblockstate2 = this.getBlockStateFromPos(worldIn, 1, -1, j3, structureBoundingBoxIn); if (iblockstate2.getMaterial() != Material.AIR && iblockstate2.isFullBlock()) { float f = this.getSkyBrightness(worldIn, 1, 0, j3, structureBoundingBoxIn) > 8 ? 0.9F : 0.7F; this.randomlyPlaceBlock(worldIn, structureBoundingBoxIn, randomIn, f, 1, 0, j3, iblockstate1); } } } return true; } }