Java Code Examples for net.minecraft.world.World.getBlock()

The following are Jave code examples for showing how to use getBlock() of the net.minecraft.world.World class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: connor41-etfuturum2   File: OceanMonument.java   View Source Code Vote up 6 votes
public static void generateFile(World world, int x, int y, int z, String path) {
	try {
		BufferedWriter bw = new BufferedWriter(new FileWriter(new File(path)));

		for (int i = 0; i < 58; i++)
			for (int j = 0; j < 31 - 9; j++)
				for (int k = 0; k < 58; k++) {
					Block b = world.getBlock(x + i, y + j, z + k);
					int meta = world.getBlockMetadata(x + i, y + j, z + k);

					String s = "(" + i + ", " + j + ", " + k + ") - ";
					if (b == ModBlocks.prismarine)
						s += meta;
					else if (b == ModBlocks.sea_lantern)
						s += 3;
					else if (b == Blocks.gold_block)
						s += 4;
					else if (b == Blocks.sponge)
						s += 5;
					else if (b == Blocks.stained_glass)
						s += 6;
					else
						s = null;

					if (s != null) {
						bw.write(s);
						bw.newLine();
					}
				}

		bw.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
}
 
Example 2
Project: connor41-etfuturum2   File: FrostedIce.java   View Source Code Vote up 6 votes
@Override
public void updateTick(World world, int x, int y, int z, Random rand) {
	if (world.isRemote)
		return;

	int surroundingBlockCount = 0;
	for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
		Block block = world.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
		if (block == this || block == Blocks.ice || block == Blocks.packed_ice)
			if (++surroundingBlockCount >= 4)
				break;
	}

	if (surroundingBlockCount < 4 || rand.nextInt(100) <= 33) {
		int meta = world.getBlockMetadata(x, y, z);
		if (meta < 3)
			world.setBlockMetadataWithNotify(x, y, z, meta + 1, 2);
		else
			world.setBlock(x, y, z, Blocks.water);
	}

	world.scheduleBlockUpdate(x, y, z, this, 40 + rand.nextInt(40));
}
 
Example 3
Project: connor41-etfuturum2   File: EntityRabbit.java   View Source Code Vote up 6 votes
@Override
public void updateTask() {
	super.updateTask();
	getLookHelper().setLookPosition(destinationBlock.getX() + 0.5D, destinationBlock.getY() + 1, destinationBlock.getZ() + 0.5D, 10.0F, getVerticalFaceSpeed());

	if (getIsAboveDestination()) {
		World world = worldObj;
		BlockPos blockpos = destinationBlock.up();
		Block block = world.getBlock(blockpos.getX(), blockpos.getY(), blockpos.getZ());
		int meta = world.getBlockMetadata(blockpos.getX(), blockpos.getY(), blockpos.getZ());

		if (field_179499_e && block instanceof BlockCarrot && meta >= 7) {
			world.func_147480_a(blockpos.getX(), blockpos.getY(), blockpos.getZ(), false);
			carrotTicks = 100;
		}

		field_179499_e = false;
		runDelay = 10;
	}
}
 
Example 4
Project: ThaumOres   File: TOEvents.java   View Source Code Vote up 6 votes
@SubscribeEvent
public void eventBreakEvent(BlockEvent.BreakEvent event) {
	World world = event.world;
	int x = event.x;
	int y = event.y;
	int z = event.z;
	EntityPlayer player = event.getPlayer();

	if (player != null && player.getHeldItem() != null && player.getHeldItem().getItem() == Items.stick) {
		if (TOConfig.debugEnable && TOConfig.debugRemover && !world.isRemote
				&& player.capabilities.isCreativeMode) {
			int radius = TOConfig.debugRemoverScannerRadius;
			for (int xx = x - radius; xx < x + radius; xx++)
				for (int zz = z - radius; zz < z + radius; zz++)
					for (int yy = 0; yy < 257; yy++)
						if (!(world.getBlock(xx, yy, zz) instanceof BlockInfusedBlockOre))
							world.setBlock(xx, yy, zz, Blocks.air, 0, 2);
			String text = "[DEBUG " + ThaumOresMod.NAME + "] Removed blocks at " + x + ";" + z + " with radius "
					+ radius;
			player.addChatMessage(new ChatComponentText(text));
			ThaumOresMod.log.info(text);
		}
	}
}
 
Example 5
Project: Technical   File: TechnicalWorldGenerator.java   View Source Code Vote up 6 votes
private void removeStone(World world, Random random, int x, int z) {
	int id = world.getBiomeGenForCoords(x, z).biomeID;
	Block block = Blocks.stone;

	if(id == 35 || id == 163 || id == 29 || id == 157 || id == 6 || id == 134 || id == 160 || id == 161 || id == 32 || id == 33) {
		block = Granite;
	} else if(id == 36 || id == 164 || id == 16 || id == 14 || id == 15 || id == 0 || id == 24 || id == 26) {
		block = Basalt;
	} else if(id == 2 || id == 1 || id == 7 || id == 129 || id == 5 || id == 30 || id == 11) {
		block = Limestone;
	} else if(id == 130 || id == 17 || id == 21 || id == 149 || id == 23 || id == 151 || id == 22 || id == 133 || id == 155 || id == 19 || id == 31 || id == 158 || id == 27) {
		block = Shale;
	} else if(id == 37 || id == 165 || id == 132 || id == 4 || id == 3 || id == 131 || id == 34 || id == 162 || id == 28 || id == 156 || id == 25) {
		block = Slate;
	} else if(id == 39 || id == 167 || id == 38 || id == 166 || id == 18 || id == 13 || id == 12 || id == 140) {
		block = Gneiss;
	} else {
		FMLLog.log(Level.ERROR, Technical.modName + ": TechnicalWorldGenerator could not find stone type for " + world.getBiomeGenForCoords(x, z).biomeName + " (id " + id + "). Please report this to the mod author(s)");
	}

	for(int y = 0; y < world.getActualHeight(); y++) {
		if(world.getBlock(x, y, z) == Blocks.stone)
			world.setBlock(x, y, z, block, 0, 0);
	}
}
 
Example 6
Project: connor41-etfuturum2   File: EndCrystal.java   View Source Code Vote up 6 votes
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
	if (side != 1)
		return false;

	Block block = world.getBlock(x, y, z);
	if (block == Blocks.obsidian || block == Blocks.bedrock)
		if (world.isAirBlock(x, y + 1, z)) {
			if (!world.isRemote) {
				EntityPlacedEndCrystal endCrystal = new EntityPlacedEndCrystal(world);
				endCrystal.setPosition(x + 0.5, y, z + 0.5);
				endCrystal.setBlockPos(x, y, z);

				world.spawnEntityInWorld(endCrystal);
				if (!player.capabilities.isCreativeMode)
					stack.stackSize--;
			}
			return true;
		}

	return false;
}
 
Example 7
Project: minecraft-quiverbow   File: Helper.java   View Source Code Vote up 6 votes
public static boolean hasValidMaterial(World world, int x, int y, int z)
{
	Block block = world.getBlock(x, y, z);
	
	// Is the attached block a valid material?
	if (block.getMaterial() == Material.clay) { return true; }
	else if (block.getMaterial() == Material.cloth) { return true; }
	else if (block.getMaterial() == Material.grass) { return true; }
	else if (block.getMaterial() == Material.ground) { return true; }
	else if (block.getMaterial() == Material.iron) { return true; }
	else if (block.getMaterial() == Material.piston) { return true; }
	else if (block.getMaterial() == Material.rock) { return true; }
	else if (block.getMaterial() == Material.sand) { return true; }
	else if (block.getMaterial() == Material.wood) { return true; }
	else if (block.getMaterial() == Material.craftedSnow) { return true; }
	else if (block.getMaterial() == Material.leaves) { return true; }
	
	// No?
	return false;
}
 
Example 8
Project: Prospecting   File: IndicatorFlowerGenerator.java   View Source Code Vote up 5 votes
public boolean generate(World world, Random random, int x, int y, int z, Block flower) {
	Block b = world.getBlock(x, y-1, z);
	if (b == Blocks.grass || b == Blocks.dirt) {
		world.setBlock(x, y, z, flower);
		if (flower instanceof BlockIndicatorFlowerDouble && y < 255) {
			world.setBlock(x, y+1, z, flower, 1, 1);
		}
		return true;
	}
	return false;
}
 
Example 9
Project: Prospecting   File: SifterItem.java   View Source Code Vote up 5 votes
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitx, float hity, float hitz) {
	Block b = world.getBlock(x, y, z);
	if (b.equals(Blocks.dirt) || b.equals(Blocks.gravel)) {
		super.doProspect(player, world, x, y, z);
		return true;
	}
	return false;
}
 
Example 10
Project: connor41-etfuturum2   File: NewAnvil.java   View Source Code Vote up 5 votes
public static void onPlayerInteract(PlayerInteractEvent event) {
	if (!EtFuturum.enableAnvil)
		return;

	World world = event.world;
	int x = event.x;
	int y = event.y;
	int z = event.z;

	if (world == null || world.isRemote)
		return;
	if (world.getBlock(x, y, z) == Blocks.anvil)
		world.setBlock(x, y, z, ModBlocks.anvil, world.getBlockMetadata(x, y, z), 3);
}
 
Example 11
Project: connor41-etfuturum2   File: CoarseDirt.java   View Source Code Vote up 5 votes
public static void onHoeEvent(UseHoeEvent event) {
	if (EtFuturum.enableCoarseDirt) {
		World world = event.world;
		if (world.getBlock(event.x, event.y, event.z) == ModBlocks.coarse_dirt) {
			world.setBlock(event.x, event.y, event.z, Blocks.dirt);
			world.playSoundEffect(event.x + 0.5F, event.y + 0.5F, event.z + 0.5F, Block.soundTypeGravel.getStepResourcePath(), 1.0F, 0.8F);
			event.setResult(Result.ALLOW);
		}
	}
}
 
Example 12
Project: Prospecting   File: BlockIndicatorFlowerDouble.java   View Source Code Vote up 5 votes
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block b) {
	if (isTop(world, x, y, z)) {
		super.onNeighborBlockChange(world, x, y, z, b);
	} else if (world.getBlock(x, y+1, z) != this || world.getBlockMetadata(x, y+1, z) != 1) {
		world.setBlockToAir(x, y, z);
	}
}
 
Example 13
Project: ThaumOres   File: TOInfusedOreWandTrigger.java   View Source Code Vote up 5 votes
@Override
public boolean executeAction(World world, ItemStack wand, EntityPlayer player, int x, int y, int z, int side,
		int event) {
	int md = world.getBlockMetadata(x, y, z);
	BlockInfusedBlockOre block = (BlockInfusedBlockOre) world.getBlock(x, y, z);
	if (world.isRemote) {
		for (int i = 0; i < 10; i++)
			if (md < 6)
				UtilsFX.infusedStoneSparkle(world, x, y, z, md + 1);
		return false;
	} else {
		ForgeDirection dir = ForgeDirection.getOrientation(side);
		int iX = dir.equals(ForgeDirection.EAST) ? x + 1 : dir.equals(ForgeDirection.WEST) ? x - 1 : x;
		int iY = dir.equals(ForgeDirection.UP) ? y + 1 : dir.equals(ForgeDirection.DOWN) ? y - 1 : y;
		int iZ = dir.equals(ForgeDirection.SOUTH) ? z + 1 : dir.equals(ForgeDirection.NORTH) ? z - 1 : z;
		for (ItemStack item : block.getDropsWand(world, x, y, z, md, player.isSneaking())) {
			float f = 0.7F;
			double d0 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
			double d1 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
			double d2 = (double) (world.rand.nextFloat() * f) + (double) (1.0F - f) * 0.5D;
			EntityItem entityitem = new EntityItem(world, (double) iX + d0, (double) iY + d1, (double) iZ + d2,
					item);
			entityitem.delayBeforeCanPickup = 10;
			world.spawnEntityInWorld(entityitem);

		}
		world.setBlock(x, y, z, block.getBaseBlock(), block.getBaseMeta(), 2);
		return true;
	}
}
 
Example 14
Project: connor41-etfuturum2   File: ItemEntityEgg.java   View Source Code Vote up 5 votes
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
	if (world.isRemote)
		return true;
	else {
		Block block = world.getBlock(x, y, z);
		x += Facing.offsetsXForSide[side];
		y += Facing.offsetsYForSide[side];
		z += Facing.offsetsZForSide[side];
		double d0 = 0.0D;

		if (side == 1 && block.getRenderType() == 11)
			d0 = 0.5D;

		Entity entity = spawnEntity(world, stack.getItemDamage(), x + 0.5D, y + d0, z + 0.5D);

		if (entity != null) {
			if (entity instanceof EntityLivingBase && stack.hasDisplayName())
				((EntityLiving) entity).setCustomNameTag(stack.getDisplayName());

			if (!player.capabilities.isCreativeMode)
				stack.stackSize--;
		}

		return true;
	}
}
 
Example 15
Project: connor41-etfuturum2   File: ItemEntityEgg.java   View Source Code Vote up 5 votes
@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 16
Project: connor41-etfuturum2   File: ItemGenericSlab.java   View Source Code Vote up 5 votes
@Override
@SideOnly(Side.CLIENT)
public boolean func_150936_a(World world, int x, int y, int z, int side, EntityPlayer player, ItemStack stack) {
	int i1 = x;
	int j1 = y;
	int k1 = z;
	Block block = world.getBlock(x, y, z);
	int meta = world.getBlockMetadata(x, y, z);

	if (block == field_150939_a && meta == 2)
		return true;
	else {
		if (side == 0)
			y--;
		if (side == 1)
			y++;
		if (side == 2)
			z--;
		if (side == 3)
			z++;
		if (side == 4)
			x--;
		if (side == 5)
			x++;

		Block block1 = world.getBlock(x, y, z);
		return block1 == field_150939_a ? true : super.func_150936_a(world, i1, j1, k1, side, player, stack);
	}
}
 
Example 17
Project: connor41-etfuturum2   File: ItemGenericSlab.java   View Source Code Vote up 5 votes
private boolean func_150946_a(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side) {
	if (side == 0)
		y--;
	if (side == 1)
		y++;
	if (side == 2)
		z--;
	if (side == 3)
		z++;
	if (side == 4)
		x--;
	if (side == 5)
		x++;

	Block block = world.getBlock(x, y, z);
	int meta = world.getBlockMetadata(x, y, z);

	if (block == field_150939_a && meta != 2) {
		if (world.checkNoEntityCollision(field_150939_a.getCollisionBoundingBoxFromPool(world, x, y, z)) && world.setBlockMetadataWithNotify(x, y, z, 2, 3)) {
			world.playSoundEffect(x + 0.5F, y + 0.5F, z + 0.5F, field_150939_a.stepSound.func_150496_b(), (field_150939_a.stepSound.getVolume() + 1.0F) / 2.0F, field_150939_a.stepSound.getPitch() * 0.8F);
			stack.stackSize--;
		}

		return true;
	} else
		return false;
}
 
Example 18
Project: minecraft-quiverbow   File: PowderKnuckle_Mod.java   View Source Code Vote up 5 votes
void doMining(World world, EntityPlayerMP player, int x, int y, int z)	// Calling this 27 times, to blast mine a 3x3x3 area
{
	Block toBeBroken = world.getBlock(x, y, z);
	int meta = world.getBlockMetadata(x, y, z);

	if (toBeBroken.getBlockHardness(world, x, y, z) == -1) { return; }	// Unbreakable

	if (toBeBroken.getHarvestLevel(meta) > 1) { return; }
	if (toBeBroken.getMaterial() == Material.water) { return; }
	if (toBeBroken.getMaterial() == Material.lava) { return; }
	if (toBeBroken.getMaterial() == Material.air) { return; }
	if (toBeBroken.getMaterial() == Material.portal) { return; }

	// Need to do checks here against invalid blocks
	if (toBeBroken == Blocks.water) { return; }
	if (toBeBroken == Blocks.flowing_water) { return; }
	if (toBeBroken == Blocks.lava) { return; }
	if (toBeBroken == Blocks.flowing_lava) { return; }
	if (toBeBroken == Blocks.obsidian) { return; }
	if (toBeBroken == Blocks.mob_spawner) { return; }

	// Crashing blocks: Redstone Lamp, Extended Piston
	// They're likely trying to drop things that cannot be dropped (active states of themselves)

	//WorldSettings.GameType gametype = WorldSettings.GameType.getByName("survival");
	WorldSettings.GameType gametype = world.getWorldInfo().getGameType();
	BlockEvent.BreakEvent event = ForgeHooks.onBlockBreakEvent(world, gametype, player, x, y, z);

	if (event.isCanceled()) { return; }	// Not allowed to do this

	//toBeBroken.dropBlockAsItem(world, x, x, z, meta, 0);	// The last one is Fortune

	boolean removalSuccess = world.setBlockToAir(x, y, z);
	if (removalSuccess) { toBeBroken.onBlockDestroyedByPlayer(world, x, y, z, meta); }

	Item preBlockItem = toBeBroken.getItemDropped(meta, player.getRNG(), 0);

	if (preBlockItem == null) { return; }	// Item doesn't exist

	ItemStack blockItem = new ItemStack(preBlockItem);

	blockItem.setItemDamage(meta);

	EntityItem entityItem = new EntityItem(world, x, y + 0.5d, z, blockItem);
	entityItem.delayBeforeCanPickup = 10;

	world.spawnEntityInWorld(entityItem);
}
 
Example 19
Project: Technical   File: Machine.java   View Source Code Vote up 5 votes
protected void direction(World world, int x, int y, int z) {
	if (!world.isRemote) {
		Block direction0 = world.getBlock(x, y, z - 1);
		Block direction1 = world.getBlock(x, y, z + 1);
		Block direction2 = world.getBlock(x - 1, y, z);
		Block direction3 = world.getBlock(x + 1, y, z);
		byte b = 3;

		if (direction0.func_149730_j() && !direction0.func_149730_j()) {
			b = 3;
		}

		if (direction1.func_149730_j() && !direction1.func_149730_j()) {
			b = 2;
		}

		if (direction2.func_149730_j() && !direction2.func_149730_j()) {
			b = 5;
		}

		if (direction3.func_149730_j() && !direction3.func_149730_j()) {
			b = 4;
		}

		world.setBlockMetadataWithNotify(x, y, z, b, 2);
	}
}
 
Example 20
Project: connor41-etfuturum2   File: ChorusFlower.java   View Source Code Vote up 4 votes
@Override
public void updateTick(World world, int x, int y, int z, Random rand) {
	if (world.isRemote)
		return;
	int meta = world.getBlockMetadata(x, y, z);
	if (meta >= 5)
		return;

	if (!canBlockStay(world, x, y, z))
		world.func_147480_a(x, y, z, true);
	else if (world.isAirBlock(x, y + 1, z)) {
		boolean canGrowUp = false;
		boolean isSegmentOnEndstone = false;
		Block lowerBlock = world.getBlock(x, y - 1, z);
		if (lowerBlock == Blocks.end_stone)
			canGrowUp = true;
		else if (lowerBlock == ModBlocks.chorus_plant) {
			int par8 = 1;
			int height;
			for (height = 0; height < 4; height++) {
				Block b = world.getBlock(x, y - (par8 + 1), z);
				if (b != ModBlocks.chorus_plant) {
					if (b == Blocks.end_stone)
						isSegmentOnEndstone = true;
					break;
				}
				par8++;
			}

			height = 4;
			if (isSegmentOnEndstone)
				height++;

			if (par8 < 2 || rand.nextInt(height) >= par8)
				canGrowUp = true;
		} else if (lowerBlock.isAir(world, x, y - 1, z))
			canGrowUp = true;

		if (canGrowUp && isSpaceAroundFree(world, x, y + 1, z, ForgeDirection.DOWN) && world.isAirBlock(x, y + 2, z)) {
			world.setBlock(x, y, z, ModBlocks.chorus_plant);
			world.setBlock(x, y + 1, z, this, meta, 3);
		} else if (meta < 4) {
			int tries = rand.nextInt(4);
			boolean grew = false;
			if (isSegmentOnEndstone)
				tries++;
			for (int i = 0; i < tries; i++) {
				ForgeDirection dir = ForgeDirection.VALID_DIRECTIONS[rand.nextInt(ForgeDirection.VALID_DIRECTIONS.length)];
				int xx = x + dir.offsetX;
				int yy = y + dir.offsetY;
				int zz = z + dir.offsetZ;
				if (world.isAirBlock(xx, yy, zz) && isSpaceAroundFree(world, xx, yy, zz, dir.getOpposite())) {
					world.setBlock(xx, yy, zz, this, meta + 1, 3);
					grew = true;
				}
			}
			if (grew)
				world.setBlock(x, y, z, ModBlocks.chorus_plant, 0, 3);
			else
				world.setBlock(x, y, z, this, 5, 3);
		} else if (meta == 4)
			world.setBlock(x, y, z, this, 5, 3);
	}
}