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

The following examples show how to use net.minecraft.world.World#getBlock() . 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: 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 2
Source File: AdapterSensor.java    From OpenPeripheral-Addons with MIT License 6 votes vote down vote up
private static Map<String, Object> describeBlock(World world, int sx, int sy, int sz, int dx, int dy, int dz) {
	final int bx = sx + dx;
	final int by = sy + dy;
	final int bz = sz + dz;

	if (!world.blockExists(bx, by, bz)) return null;

	final Block block = world.getBlock(bx, by, bz);
	final String type = getBlockType(world, block, bx, by, bz);
	final int color = getBlockColorBitmask(world, block, bx, by, bz);

	Map<String, Object> tmp = Maps.newHashMap();
	tmp.put("x", dx);
	tmp.put("y", dy);
	tmp.put("z", dz);
	tmp.put("type", type);
	tmp.put("color", color);
	return tmp;
}
 
Example 3
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 6 votes vote down vote up
public static void checkBlockInteraction(Resident res, BlockPos bp, PlayerInteractEvent.Action action, Event ev) {
    if(!ev.isCancelable()) {
        return;
    }

    World world = MinecraftServer.getServer().worldServerForDimension(bp.getDim());
    Block block = world.getBlock(bp.getX(), bp.getY(), bp.getZ());

    // Bypass for SellSign
    if (block instanceof BlockSign) {
        TileEntity te = world.getTileEntity(bp.getX(), bp.getY(), bp.getZ());
        if(te instanceof TileEntitySign && SellSign.SellSignType.instance.isTileValid((TileEntitySign) te)) {
            return;
        }
    }

    for(SegmentBlock segment : segmentsBlock.get(block.getClass())) {
        if(!segment.shouldInteract(res, bp, action)) {
            ev.setCanceled(true);
        }
    }
}
 
Example 4
Source File: BlockSmallFire.java    From GardenCollection with MIT License 6 votes vote down vote up
public static boolean extinguishSmallFire (World world, EntityPlayer player, int x, int y, int z, int direction) {
    switch (direction) {
        case 0: y--; break;
        case 1: y++; break;
        case 2: z--; break;
        case 3: z++; break;
        case 4: x--; break;
        case 5: x++; break;
    }

    if (world.getBlock(x, y, z) == ModBlocks.smallFire) {
        world.playAuxSFXAtEntity(player, 1004, x, y, z, 0);
        world.setBlockToAir(x, y, z);
        return true;
    }

    return false;
}
 
Example 5
Source File: BlockQuickSand.java    From Artifacts with MIT License 6 votes vote down vote up
private boolean flowDown(World world, int x, int y, int z)
  {
  	if(world.getBlock(x, y, z) == BlockQuickSand.instance) {
  		//Flow the entire block downwards, or as much as possible.
	int sandAmount = getQuicksandLevel(world, x, y, z);
	int amountFlowed = flowIntoBlock(world, x, y-1, z, sandAmount);
	
	if(amountFlowed > 0) {
		if(sandAmount <= amountFlowed) {
			world.setBlockToAir(x, y, z);
			return true;
		}
		else {
			world.setBlockMetadataWithNotify(x, y, z, 16 - (sandAmount - amountFlowed), 3);
			return true;
		}
	}
}
  	
  	return false;
  }
 
Example 6
Source File: FrostedIce.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@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 7
Source File: ModuleAirGrate.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
private void checkForPlantsAndFarm(World worldObj, int x, int y, int z, int plantCheckRange){
    if(grateRange > 0 && worldObj.getTotalWorldTime() % 5 == 0) {
        if(plantCheckX < x - plantCheckRange || plantCheckZ < z - plantCheckRange) {
            plantCheckX = x - plantCheckRange;
            plantCheckZ = z - plantCheckRange;
        }

        if(plantCheckX != x || plantCheckZ != z) { // we know that we're no plant, avoid getBlock
            Block b = worldObj.getBlock(plantCheckX, y, plantCheckZ);
            NetworkHandler.sendToAllAround(new PacketSpawnParticle("reddust", plantCheckX + 0.5, y + 0.5, plantCheckZ + 0.5, 0, 0, 0), worldObj);
            if(b instanceof BlockPneumaticPlantBase) {
                ((BlockPneumaticPlantBase)b).attemptFarmByAirGrate(worldObj, plantCheckX, y, plantCheckZ);
            }
        }

        if(plantCheckZ++ >= z + plantCheckRange) {
            plantCheckZ = z - plantCheckRange;
            if(plantCheckX++ >= x + plantCheckRange) {
                plantCheckX = x - plantCheckRange;
            }
        }
    }
}
 
Example 8
Source File: EndCrystal.java    From Et-Futurum with The Unlicense 6 votes vote down vote up
@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 9
Source File: StructureJourneymanTower.java    From Artifacts with MIT License 6 votes vote down vote up
@Override
public boolean generate(World world, Random random, int x, int y, int z) {
	for (z -= 8; y > 5 && (!world.getBlock(x, y, z).isOpaqueCube() || world.getBlock(x, y, z) == Blocks.leaves); --y)
       {
           ;
       }

       if (y <= 61)
       {
           return false;
       }
       else
       {
       	build(world, random, x-5, y, z+1);
       }
	return false;
}
 
Example 10
Source File: BlockPotionPlant.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Significantly (twice as much per 3 brewing stands) increase the growth rate when there brewing stands that are currently brewing around the plant.
 */
@Override
protected float getGrowthRate(World world, int x, int y, int z){
    int brewingBrewingStands = 0;
    for(int i = x - SQUARE_RADIUS; i <= x + SQUARE_RADIUS; i++) {
        for(int j = y - MAX_HEIGHT_DIFF; j <= y + MAX_HEIGHT_DIFF; j++) {
            for(int k = z - SQUARE_RADIUS; k <= z + SQUARE_RADIUS; k++) {
                if(world.getBlock(i, j, k) == Blocks.brewing_stand && world.getTileEntity(i, j, k) instanceof TileEntityBrewingStand) {
                    TileEntityBrewingStand brewingStand = (TileEntityBrewingStand)world.getTileEntity(i, j, k);
                    if(brewingStand.getBrewTime() > 0) brewingBrewingStands++;
                }
            }
        }
    }
    return super.getGrowthRate(world, x, y, z) * (1 + brewingBrewingStands * 0.333F);
}
 
Example 11
Source File: AuraEffects.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void doBlockEffect(ChunkCoordinates originTile, ChunkCoordinates selectedBlock, World world) {
    Block selected = world.getBlock(selectedBlock.posX, selectedBlock.posY, selectedBlock.posZ);
    if(selected.equals(Blocks.water) && world.getBlockMetadata(selectedBlock.posX, selectedBlock.posY, selectedBlock.posZ) == 0) {
        world.setBlock(selectedBlock.posX, selectedBlock.posY, selectedBlock.posZ, Blocks.ice);
    }
}
 
Example 12
Source File: BlockLaserBeamSource.java    From Artifacts with MIT License 5 votes vote down vote up
public void rebuildLaser(World world, int x, int y, int z, int meta) {
	int l1 = meta & 3;
    boolean flag1 = (meta & 8) == 8;
    int offsetX = Direction.offsetX[l1];
    int offsetZ = Direction.offsetZ[l1];
    int l2;
    int i3;
    Block j3;
    int k3;
    boolean shouldbetriggered = false;
    boolean quitEarly = false;
    for (i3 = 1; i3 < 16 && !quitEarly; ++i3)
    {
    	l2 = x + offsetX * i3;
        k3 = z + offsetZ * i3;
        j3 = world.getBlock(l2, y, k3);
        if(j3 == Blocks.air || (j3 != BlockLaserBeam.instance && j3.getMaterial() == Material.air)) {
        	world.setBlock(l2, y, k3, BlockLaserBeam.instance, 0, 3);
        }
        if (world.getBlock(l2, y, k3).isOpaqueCube()) {
        	quitEarly = true;
        }
        if(j3 == BlockLaserBeam.instance) {
        	if(world.getBlockMetadata(l2, y, k3) != 0) {
        		shouldbetriggered = true;
        	}
        }
    }
    /*if(flag1 && shouldbetriggered) {
    	System.out.println("trigger?" + shouldbetriggered);
		world.setBlockMetadataWithNotify(x, y, z, l1|8, 3);
		notifyNeighborOfChange(world, x, y, z, l1);
	}*/
}
 
Example 13
Source File: FarmablePlastic.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isSaplingAt(World world, int x, int y, int z){
    Block block = world.getBlock(x, y, z);
    List<ItemStack> seeds = new ArrayList<ItemStack>();
    ((ItemPlasticPlants)Itemss.plasticPlant).addSubItems(seeds);
    for(ItemStack seed : seeds) {
        if(seed.getItemDamage() % 16 == meta) {
            Block plantBlock = ItemPlasticPlants.getPlantBlockIDFromSeed(seed.getItemDamage());
            if(plantBlock == block) return true;
        }
    }
    return false;
}
 
Example 14
Source File: BlockEssentiaCompressor.java    From Gadomancy with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean isMultiblockable(World world, int x, int y, int z) {
    Block block = world.getBlock(x, y, z);
    TileEntity te = world.getTileEntity(x, y, z);
    if(!block.equals(RegisteredBlocks.blockEssentiaCompressor)) return false;
    if(te == null || !(te instanceof TileEssentiaCompressor)) return false;
    TileEssentiaCompressor compressor = (TileEssentiaCompressor) te;
    return !compressor.isMultiblockFormed();
}
 
Example 15
Source File: EventHandlerPneumaticCraft.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
private ItemStack attemptFill(World world, MovingObjectPosition p){
    Block id = world.getBlock(p.blockX, p.blockY, p.blockZ);
    for(Map.Entry<Block, Item> entry : Fluids.fluidBlockToBucketMap.entrySet()) {
        if(id == entry.getKey()) {
            world.setBlock(p.blockX, p.blockY, p.blockZ, Blocks.air);
            return new ItemStack(entry.getValue());
        }
    }
    return null;
}
 
Example 16
Source File: StaticUtils.java    From BigReactors with MIT License 5 votes vote down vote up
public static IInventory checkForDoubleChest(World worldObj, IInventory te, int x, int y, int z) {
	for(ForgeDirection dir : chestDirections) {
		if(worldObj.getBlock(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ) == Blocks.chest) {
			TileEntity otherTe = worldObj.getTileEntity(x + dir.offsetX, y + dir.offsetY, z + dir.offsetZ);
			if(otherTe instanceof IInventory) {
				return new InventoryLargeChest("Large Chest", te, (IInventory)otherTe);
			}
		}
	}

	// Not a large chest, so just return the single chest.
	return te;
}
 
Example 17
Source File: ItemMarbleSlab.java    From Chisel with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hx, float hy, float hz)
{
    BlockMarbleSlab block = (BlockMarbleSlab) Block.getBlockFromItem(this);

    Block targetBlock = world.getBlock(x, y, z);
    int meta = world.getBlockMetadata(x, y, z);
    boolean metaMatches = meta == stack.getItemDamage();

    if(metaMatches && side == 0 && targetBlock.equals(block.top))
    {
        world.setBlock(x, y, z, block.master, meta, 2);
        stack.stackSize -= 1;
        return true;
    } else if(metaMatches && side == 1 && targetBlock.equals(block.bottom))
    {
        world.setBlock(x, y, z, block.master, meta, 2);
        stack.stackSize -= 1;
        return true;
    }

    boolean result = super.onItemUse(stack, player, world, x, y, z, side, hz, hy, hz);


    switch(side)
    {
        case 0:
            --y;
            break;
        case 1:
            ++y;
            break;
        case 2:
            --z;
            break;
        case 3:
            ++z;
            break;
        case 4:
            --x;
            break;
        case 5:
            ++x;
            break;
    }

    targetBlock = world.getBlock(x, y, z);
    meta = world.getBlockMetadata(x, y, z);

    if(!result && (targetBlock.equals(block.top) || targetBlock.equals(block.bottom)) && meta == stack.getItemDamage())
    {
        world.setBlock(x, y, z, block.master, meta, 2);
        return true;
    }

    if(!result)
        return false;

    if(side != 0 && (side == 1 || hy <= 0.5D))
        return true;


    //TODO allow top slabs
    //world.setBlock(x, y, z, block.top, meta, 2);
    return true;
}
 
Example 18
Source File: BlockBlackFlower.java    From ForbiddenMagic with Do What The F*ck You Want To Public License 4 votes vote down vote up
@Override
public boolean canBlockStay(World world, int x, int y, int z) {
    Block block = world.getBlock(x, y - 1, z);
    return block.canSustainPlant(world, x, y - 1, z, ForgeDirection.UP, this);
}
 
Example 19
Source File: StructureJourneymanTower.java    From Artifacts with MIT License 4 votes vote down vote up
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.cobbleOrMossy(rand), 0, 2);
					}
				}
			}
		}
		y--;
	} while(noair && (j+y) >= 0);
	if(y >= -7 && world.rand.nextBoolean()) {
		y = -8;
	}
	if(y < -7) {
		y++;
		int yy = 3;
		for(; yy <= 5; yy++) {
			for(int x = 3; x <= 7; x++) {
				for(int z = 2; z <= 6; z++) {
					world.setBlockToAir(i+x, j+y+yy, k+z);
				}
			}
		}
		world.setBlock(i+5, j+y+5, k+4, Blocks.mob_spawner, 0, 2);
		TileEntityMobSpawner tileentitymobspawner = (TileEntityMobSpawner)world.getTileEntity(i+5, j+y+5, k+4);

           if (tileentitymobspawner != null)
           {
               tileentitymobspawner.func_145881_a/*getSpawnerLogic*/().setEntityName("ClayGolem");
               NBTTagCompound nbt = new NBTTagCompound();
               tileentitymobspawner.writeToNBT(nbt);
               nbt.setShort("MinSpawnDelay",(short)100);
               nbt.setShort("MaxSpawnDelay",(short)600);
               tileentitymobspawner.readFromNBT(nbt);
           }
           
           world.setBlock(i+5, j+y+4, k+4, StructureGenHelper.randomBlock(rand, new Block[]{Blocks.chest, Blocks.chest, Blocks.air}), 2, 2);
   		TileEntity te = world.getTileEntity(i+5, j+y+4, k+4);
   		if(te != null && te instanceof TileEntityChest) {
   			TileEntityChest tec = (TileEntityChest)te;
   			ChestGenHooks info = ChestGenHooks.getInfo(ChestGenHooks.DUNGEON_CHEST);
               WeightedRandomChestContent.generateChestContents(rand, info.getItems(rand), tec, info.getCount(rand));
   		}
   		
   		world.setBlock(i+5, j+y+3, k+4, StructureGenHelper.cobbleOrMossy(rand), 0, 2);
           
		for(yy=3;yy*-1>y;yy++) {
			world.setBlock(i+7, j+y+yy, k+6, Blocks.ladder, 2, 2);
		}
		world.setBlock(i+7, j+y+yy, k+6, Blocks.ladder, 2, 2);
		world.setBlock(i+7, j+y+yy+1, k+6, Blocks.trapdoor, 2, 2);
	}
}
 
Example 20
Source File: GeneralChiselClient.java    From Chisel with GNU General Public License v2.0 4 votes vote down vote up
public static EntityDiggingFX addBlockHitEffects(World world, int x, int y, int z, int side)
    {
        Block block = world.getBlock(x, y, z);
        if(block.isAir(world, x, y, z))
            return null;

        EffectRenderer renderer = Minecraft.getMinecraft().effectRenderer;

        float f = 0.1F;
        double d0 = x + rand.nextDouble() * (block.getBlockBoundsMaxX() - block.getBlockBoundsMinX() - f * 2.0F) + f + block.getBlockBoundsMinX();
        double d1 = y + rand.nextDouble() * (block.getBlockBoundsMaxY() - block.getBlockBoundsMinY() - f * 2.0F) + f + block.getBlockBoundsMinY();
        double d2 = z + rand.nextDouble() * (block.getBlockBoundsMaxZ() - block.getBlockBoundsMinZ() - f * 2.0F) + f + block.getBlockBoundsMinZ();

        switch(side)
        {
            case 0:
                d1 = y + block.getBlockBoundsMinY() - f;
                break;
            case 1:
                d1 = y + block.getBlockBoundsMaxY() + f;
                break;
            case 2:
                d2 = z + block.getBlockBoundsMinZ() - f;
                break;
            case 3:
                d2 = z + block.getBlockBoundsMaxZ() + f;
                break;
            case 4:
                d0 = x + block.getBlockBoundsMinX() - f;
                break;
            case 5:
                d0 = x + block.getBlockBoundsMaxX() + f;
                break;
        }

        EntityDiggingFX res = new EntityDiggingFX(world, d0, d1, d2, 0.0D, 0.0D, 0.0D, block, world.getBlockMetadata(x, y, z), side);
//		res.func_70596_a(x, y, z);
        res.motionX = d0 - (x + 0.5);
        res.motionY = d1 - (y + 0.5);
        res.motionZ = d2 - (z + 0.5);

        renderer.addEffect(res);

        return res;
    }