Java Code Examples for net.minecraft.world.World#setBlock()
The following examples show how to use
net.minecraft.world.World#setBlock() .
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: BW_OreLayer.java From bartworks with MIT License | 6 votes |
public boolean setGTOreBlockSpace(World aWorld, int aX, int aY, int aZ, int aMetaData, Block block){ if (!GT_TileEntity_Ores.setOreBlock(aWorld, aX, aY, aZ, aMetaData, false, false)) { aY = Math.min(aWorld.getActualHeight(), Math.max(aY, 1)); Block tBlock = aWorld.getBlock(aX, aY, aZ); Block tOreBlock = GregTech_API.sBlockOres1; if (aMetaData < 0 || tBlock == Blocks.air) { return false; } else { if (!tBlock.isReplaceableOreGen(aWorld, aX, aY, aZ, block)) { return false; } aMetaData += 5000; aWorld.setBlock(aX, aY, aZ, tOreBlock, aMetaData, 0); TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); if (tTileEntity instanceof GT_TileEntity_Ores) { ((GT_TileEntity_Ores) tTileEntity).mMetaData = (short) aMetaData; } return true; } }else return true; }
Example 2
Source File: ExplosionHelper.java From Gadomancy with GNU Lesser General Public License v3.0 | 6 votes |
public static void taintplosion(World world, int x, int y, int z, boolean taintBiome, int chanceToTaint, float str, int size, int blocksAffected) { if(chanceToTaint < 1) chanceToTaint = 1; world.createExplosion(null, x + 0.5D, y + 0.5D, z + 0.5D, str, false); for (int a = 0; a < blocksAffected; a++) { int xx = x + world.rand.nextInt(size) - world.rand.nextInt(size); int yy = y + world.rand.nextInt(size) - world.rand.nextInt(size); int zz = z + world.rand.nextInt(size) - world.rand.nextInt(size); if (world.isAirBlock(xx, yy, zz)) { if (yy < y) { world.setBlock(xx, yy, zz, ConfigBlocks.blockFluxGoo, 8, 3); } else { world.setBlock(xx, yy, zz, ConfigBlocks.blockFluxGas, 8, 3); } } if(!Config.genTaint) continue; if(taintBiome && world.rand.nextInt(chanceToTaint) == 0) { Utils.setBiomeAt(world, xx, zz, ThaumcraftWorldGenerator.biomeTaint); } } }
Example 3
Source File: ItemPlasticPlants.java From PneumaticCraft with GNU General Public License v3.0 | 6 votes |
/** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ @Override public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){ BlockPneumaticPlantBase plant = (BlockPneumaticPlantBase)getPlantBlockIDFromSeed(stack.getItemDamage()); if(plant == Blockss.squidPlant) { MovingObjectPosition mop = getMovingObjectPositionFromPlayer(world, player, true); if(mop != null) { int x = mop.blockX; int y = mop.blockY; int z = mop.blockZ; if(player.canPlayerEdit(x, y, z, 1, stack) && player.canPlayerEdit(x, y + 1, z, 1, stack)) { if(plant.canBlockStay(world, x, y + 1, z) && world.isAirBlock(x, y + 1, z)) { stack.stackSize--; world.setBlock(x, y + 1, z, Blockss.squidPlant, 7, 3); } } } } return stack; }
Example 4
Source File: BlockSaplingTainted.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 6 votes |
/** * Grow the tree */ @Override public void func_149878_d(World world, int x, int y, int z, Random rand) { if(!world.isRemote) { int meta = world.getBlockMetadata(x, y, z); world.setBlockToAir(x, y, z); WorldGenTaintedTree tree = new WorldGenTaintedTree(true); if (!tree.generate(world, rand, x, y, z)) { world.setBlock(x, y, z, this, meta, 2); } } }
Example 5
Source File: EntitySmashingRock.java From Chisel-2 with GNU General Public License v2.0 | 6 votes |
public static void smash(World world, int x, int y, int z) { Block block = world.getBlock(x, y, z); int meta = world.getBlockMetadata(x, y, z); Block resBlock = block; int resMeta = meta; if (block.equals(Blocks.stone)) { resBlock = Blocks.cobblestone; } else if (block.equals(Blocks.stonebrick) && meta == 0) { resMeta = 2; } else if (block.equals(Blocks.cobblestone)) { resBlock = Blocks.gravel; } else if (block.equals(Blocks.gravel)) { resBlock = Blocks.sand; } if (resBlock.equals(block) && resMeta == meta) return; world.setBlock(x, y, z, resBlock, resMeta, 3); }
Example 6
Source File: StructureJourneymanTowerAncient.java From Artifacts with MIT License | 6 votes |
private static void basement(World world, int i, int j, int k, Random rand) { boolean noair = false; int y = -1; do { noair = false; for(int x = 1; x <= 9; x++) { for(int z = 0; z <= 8; z++) { //5,y,4 int d = (x-5)*(x-5)+(z-4)*(z-4); if(d <= 17) { if(!world.getBlock(i+x, j+y, z+k).isOpaqueCube() || world.getBlock(i+x, j+y, z+k) == Blocks.leaves) { noair=true; world.setBlock(i+x, j+y, z+k, StructureGenHelper.cobbleMossyOrAir(rand), 0, 2); } } } } y--; } while(noair && (j+y) >= 0); }
Example 7
Source File: BlockDecorativePot.java From GardenCollection with MIT License | 6 votes |
@Override protected boolean applyItemToGarden (World world, int x, int y, int z, EntityPlayer player, ItemStack itemStack, float hitX, float hitY, float hitZ, boolean hitValid) { ItemStack item = (itemStack == null) ? player.inventory.getCurrentItem() : itemStack; if (item != null && item.getItem() == Items.flint_and_steel) { ItemStack substrate = getGardenSubstrate(world, x, y, z, Slot2Profile.SLOT_CENTER); if (substrate != null && substrate.getItem() == Item.getItemFromBlock(Blocks.netherrack)) { if (world.isAirBlock(x, y + 1, z)) { world.playSoundEffect(x + .5, y + .5, z + .5, "fire.ignite", 1, world.rand.nextFloat() * .4f + .8f); world.setBlock(x, y + 1, z, ModBlocks.smallFire); world.notifyBlocksOfNeighborChange(x, y, z, this); world.notifyBlocksOfNeighborChange(x, y - 1, z, this); } item.damageItem(1, player); return true; } } return super.applyItemToGarden(world, x, y, z, player, itemStack, hitX, hitY, hitZ, hitValid); }
Example 8
Source File: ComponentLight.java From Artifacts with MIT License | 5 votes |
@Override public boolean onEntityItemUpdate(EntityItem entityItem, String type) { if(type == "onUpdate") { World world = entityItem.worldObj; NBTTagCompound data = entityItem.getEntityItem().stackTagCompound; int lx = data.getInteger("lastLightX"); int ly = data.getInteger("lastLightY"); int lz = data.getInteger("lastLightZ"); //System.out.println("Last: " + lx + "," + ly + "," + lz); int nlx = (int) entityItem.posX; int nly = (int) entityItem.posY; int nlz = (int) entityItem.posZ; if(nlx != lx || nly != ly || nlz != lz) { int d = (nlx - lx)*(nlx - lx)+(nly - ly)*(nly - ly)+(nlz - lz)*(nlz - lz); if(d > 13) { if(ly >= 0 && ly < 256 && world.getBlock(nlx, nly, nlz) == BlockLight.instance) world.setBlockToAir(lx, ly, lz); if(nly >= 0 && nly < 256 && world.isAirBlock(nlx, nly, nlz)) { world.setBlock(nlx, nly, nlz, BlockLight.instance); data.setInteger("lastLightX",nlx); data.setInteger("lastLightY",nly); data.setInteger("lastLightZ",nlz); //System.out.println("Placed: " + nlx + "," + nly + "," + nlz); } } } //entityItem.getEntityItem().stackTagCompound = data; } else { System.out.println("Hmm. " + type); } return false; }
Example 9
Source File: BW_MetaGenerated_SmallOres.java From bartworks with MIT License | 5 votes |
public static boolean setOreBlock(World aWorld, int aX, int aY, int aZ, int aMetaData, boolean air, Block block, int[] aBlockMeta) { if (!air) { aY = Math.min(aWorld.getActualHeight(), Math.max(aY, 1)); } Block tBlock = aWorld.getBlock(aX, aY, aZ); Block tOreBlock = WerkstoffLoader.BWSmallOres; if (aMetaData < 0 || tBlock == Blocks.air && !air) { return false; } else { if (Block.getIdFromBlock(tBlock) != Block.getIdFromBlock(block)) { return false; } final int aaY = aY; if (Arrays.stream(aBlockMeta).noneMatch(e -> e == aWorld.getBlockMetadata(aX, aaY, aZ))) { return false; } aWorld.setBlock(aX, aY, aZ, tOreBlock, aMetaData, 0); TileEntity tTileEntity = aWorld.getTileEntity(aX, aY, aZ); if (tTileEntity instanceof BW_MetaGeneratedOreTE) { ((BW_MetaGeneratedOreTE) tTileEntity).mMetaData = (short) aMetaData; } return true; } }
Example 10
Source File: ChiselLeftClick.java From Chisel with GNU General Public License v2.0 | 5 votes |
public static void setBlock(World world, int x, int y, int z, ChiselMode chiselMode, Block previousBlock, int previousMetadata, Block newBlock, int newMetadata, ForgeDirection direction) { if(chiselMode == ChiselMode.SINGLE) { world.setBlock(x, y, z, newBlock, newMetadata, 2); } else if(chiselMode == ChiselMode.CIRCLETHREE) { int radius = 1; for(int i = -radius; i <= radius; i++) for(int j = -radius; j <= radius; j++) { //TODO facing stuff so this can be anywhere if(world.getBlock(x + i, y, z + j) != null) { if(world.getBlock(x + i, y, z + j) == previousBlock && world.getBlockMetadata(x + i, y, z + j) == previousMetadata) { int shiftedX = x; int shiftedY = y; int shiftedZ = z; world.setBlock(shiftedX, shiftedY, shiftedZ, newBlock, newMetadata, 2); } } } } }
Example 11
Source File: FarmablePlastic.java From PneumaticCraft with GNU General Public License v3.0 | 5 votes |
@Override public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, int x, int y, int z){ Block plant = ItemPlasticPlants.getPlantBlockIDFromSeed(germling.getItemDamage()); if(plant.canBlockStay(world, x, y, z)) { return world.setBlock(x, y, z, plant); } return false; }
Example 12
Source File: BlockQuantumOre.java From qcraft-mod with Apache License 2.0 | 5 votes |
private void glow( World world, int i, int j, int k ) { this.sparkle( world, i, j, k ); if( this == QCraft.Blocks.quantumOre ) { world.setBlock( i, j, k, QCraft.Blocks.quantumOreGlowing ); } }
Example 13
Source File: PlaceTraps.java From Artifacts with MIT License | 5 votes |
private void pyramidSpikeTrap(Random rand, World world, int x, int y, int z) { for(int ox = -1; ox <= 1; ox++) { for(int oz = -1; oz <= 1; oz++) { if(ox != 0 || oz != 0) world.setBlock(x+ox, 51, z+oz, Blocks.sandstone); } } for(int ox = -1; ox <= 1; ox++) { for(int oz = -1; oz <= 1; oz++) { if(ox != 0 || oz != 0) world.setBlock(x+ox, 52, z+oz, BlockSpikes.instance); } } world.setBlock(x, 53, z, BlockArtifactsPressurePlate.invisObsidian); }
Example 14
Source File: ItemSeeds.java From GardenCollection with MIT License | 5 votes |
@Override public boolean onItemUse (ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { if (side != 1) return false; else if (player.canPlayerEdit(x, y, z, side, itemStack) && player.canPlayerEdit(x, y + 1, z, side, itemStack)) { if (world.getBlock(x, y, z).canSustainPlant(world, x, y, z, ForgeDirection.UP, this) && world.isAirBlock(x, y + 1, z)) { world.setBlock(x, y + 1, z, plantBlock); itemStack.stackSize--; return true; } } return false; }
Example 15
Source File: RecipePureDaisy.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 4 votes |
/** * Returns true if the block was placed (and if the Pure Daisy should do particles and stuffs). * Should only place the block if !world.isRemote, but should return true if it would've placed * it otherwise. You may return false to cancel the normal particles and do your own. */ public boolean set(World world, int x, int y, int z, SubTileEntity pureDaisy) { if(!world.isRemote) world.setBlock(x, y, z, output, outputMeta, 1 | 2); return true; }
Example 16
Source File: BlockRoseBush.java From ForbiddenMagic with Do What The F*ck You Want To Public License | 4 votes |
/** * Called when the block is placed in the world. */ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) { world.setBlock(x, y, z, this, 1, 2); world.setBlock(x, y + 1, z, this, 0, 2); }
Example 17
Source File: ItemMossPaste.java From GardenCollection with MIT License | 4 votes |
@Override public boolean onItemUse (ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { Block block = world.getBlock(x, y, z); int meta = world.getBlockMetadata(x, y, z); Block newBlock = null; int newMeta = -1; if (block == Blocks.stonebrick) { if (meta == 0) newMeta = 1; else if (meta == 1) { newBlock = ModBlocks.mossBrick; newMeta = 0; } else if (meta == 2) { newBlock = ModBlocks.mossBrick; newMeta = 3; } } else if (block == ModBlocks.mossBrick) { if (meta == 0) newMeta = 1; if (meta == 1) newMeta = 2; if (meta == 3) newMeta = 4; if (meta == 4) newMeta = 5; if (meta == 5) newMeta = 6; } else if (block == Blocks.cobblestone) { if (meta == 0) { newBlock = Blocks.mossy_cobblestone; newMeta = 0; } } if (newBlock != null) { world.setBlock(x, y, z, newBlock); } if (newMeta != -1) { world.setBlockMetadataWithNotify(x, y, z, newMeta, 3); itemStack.damageItem(1, player); return true; } return super.onItemUse(itemStack, player, world, x, y, z, side, hitX, hitY, hitZ); }
Example 18
Source File: MoCWorldGenPortal.java From mocreaturesdev with GNU General Public License v3.0 | 4 votes |
public boolean generate(World world, Random random, int x, int y, int z) { //System.out.println("Generating Portal @ x = "+ x + " y = "+y + " z = "+z + " server = " + MoCreatures.isServer()); if(world.getBlockId(x, y , z) == centerBlockID || world.getBlockId(x, y-1 , z) == centerBlockID || world.getBlockId(x, y+1 , z) == centerBlockID) { //System.out.println("portal already exists"); return true; } if(world.getBlockId(x, y , z) == 0 || world.getBlockId(x, y+1, z) !=0) { return false; } int origX = x; int origY = y; int origZ = z; //cleans the area /*for (int i = x-4; i < x+4; i++) { for (int j = z - 4; j < z + 4 ; j++) { for (int k = y - 1; k < y + 2; k++) { world.setBlock(i, k, j, 2, 0, 0); } } }*/ stairMetadata = 2; for (int nZ = z-3; nZ < z+3; nZ = nZ+5) { for (int nX = x-2; nX < x+2; nX++) { if (nZ > z) { stairMetadata = 3; } world.setBlock(nX, y+1, nZ, stairBlockID, stairMetadata, 2); //System.out.println("stairMetadata = " + stairMetadata); //stairMetadata++; } } for (int nX = x-2; nX < x+2; nX++) { for (int nZ = z-2; nZ < z+2; nZ++) { world.setBlock(nX, y+1, nZ, wallBlockID, wallMetadata, 2); } } for (int nX = x-1; nX < x+1; nX++) { for (int nZ = z-1; nZ < z+1; nZ++) { world.setBlock(nX, y+1, nZ, centerBlockID, centerMetadata, 2); } } for (int j = x-3; j <x+3; j = j+5) { for (int nZ = z-3; nZ < z+3; nZ++) { world.setBlock(j, y+6, nZ, wallBlockID, wallMetadata, 2); } } generatePillar(world, x-3, y, z-3); generatePillar(world, x-3, y, z+2); generatePillar(world, x+2, y, z-3); generatePillar(world, x+2, y, z+2); //System.out.println("portal generated"); return true; }
Example 19
Source File: OilGeneratorFix.java From NewHorizonsCoreMod with GNU General Public License v3.0 | 4 votes |
public void buildOilStructure( World pWorld, Random pRand, int pSphereX, int pSphereY, int pSphereZ, int pRadius, int pGroundLevel, Block pTargetBlock, boolean pCheckValidLocation ) { // Make sure to not exceed the max-build height of minecraft EDEPOSIT_SIZE eSize; int tSpringHeight = 0; if( pRadius >= MainRegistry.CoreConfig.OilFixConfig.OilDepositThresholdLarge ) { tSpringHeight = MainRegistry.CoreConfig.OilFixConfig.OilFountainSizeLarge; eSize = EDEPOSIT_SIZE.LARGE; } else if( pRadius >= MainRegistry.CoreConfig.OilFixConfig.OilDepositThresholdMedium ) { tSpringHeight = MainRegistry.CoreConfig.OilFixConfig.OilFountainSizeSmall; eSize = EDEPOSIT_SIZE.MEDIUM; } else { eSize = EDEPOSIT_SIZE.SMALL; } int pMaxHeight = pGroundLevel + tSpringHeight; if( pMaxHeight >= pWorld.getActualHeight() - 1 ) { if( YAMCore.isDebug() ) { _mLog.warn("The total height of the calculated OilDeposit would exceed the maximum world-size."); } return; } int r2 = pRadius * pRadius; for( int bx = -pRadius; bx <= pRadius; bx++ ) { for( int by = -pRadius + 2; by <= pRadius - 2; by++ ) { for( int bz = -pRadius; bz <= pRadius; bz++ ) { int d2 = bx * bx + by * by * 3 + bz * bz; if( d2 <= r2 ) { if( !checkBlock( pWorld, bx + pSphereX - 1, by + pSphereY, bz + pSphereZ ) || !pCheckValidLocation ) { if( !checkBlock( pWorld, bx + pSphereX + 1, by + pSphereY, bz + pSphereZ ) || !pCheckValidLocation ) { if( !checkBlock( pWorld, bx + pSphereX, by + pSphereY - 1, bz + pSphereZ ) || !pCheckValidLocation ) { if( !checkBlock( pWorld, bx + pSphereX, by + pSphereY, bz + pSphereZ - 1 ) || !pCheckValidLocation ) { if( !checkBlock( pWorld, bx + pSphereX, by + pSphereY, bz + pSphereZ + 1 ) || !pCheckValidLocation ) { if( !checkBlockAbove( pWorld, bx + pSphereX, by + pSphereY + 1, bz + pSphereZ ) || !pCheckValidLocation ) { pWorld.setBlock( bx + pSphereX, by + pSphereY, bz + pSphereZ, pTargetBlock, 0, 2 ); } } } } } } } } } } if( eSize.ordinal() >= EDEPOSIT_SIZE.MEDIUM.ordinal() ) { for( int y = pSphereY + 1; y <= pMaxHeight; y++ ) { pWorld.setBlock( pSphereX, y, pSphereZ, pTargetBlock, 0, 3 ); } } if( eSize == EDEPOSIT_SIZE.LARGE ) { for( int y = pSphereY; y <= pMaxHeight - tSpringHeight / 2; y++ ) { pWorld.setBlock( pSphereX + 1, y, pSphereZ, pTargetBlock, 0, 3 ); pWorld.setBlock( pSphereX - 1, y, pSphereZ, pTargetBlock, 0, 3 ); pWorld.setBlock( pSphereX, y, pSphereZ + 1, pTargetBlock, 0, 3 ); pWorld.setBlock( pSphereX, y, pSphereZ - 1, pTargetBlock, 0, 3 ); } } }
Example 20
Source File: ItemCarvableSlab.java From Chisel-2 with GNU General Public License v2.0 | 4 votes |
private void place(ItemStack stack, World world, int x, int y, int z, Block toPlace, int metadata) { world.setBlock(x, y, z, toPlace, metadata, 2); stack.stackSize -= 1; world.playSoundEffect(x + 0.5f, y + 0.5f, z + 0.5f, this.field_150939_a.stepSound.func_150496_b(), (this.field_150939_a.stepSound.getVolume() + 1.0F) / 2.0F, this.field_150939_a.stepSound.getPitch() * 0.8F); }