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

The following examples show how to use net.minecraft.world.World#getBlockTileEntity() . 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: BlockBusFluidStorage.java    From ExtraCells1 with MIT License 6 votes vote down vote up
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int neighbourID)
{
	TileEntity blockTE = world.getBlockTileEntity(x, y, z);
	if (blockTE instanceof TileEntityBusFluidStorage)
	{
		TileEntityBusFluidStorage storageBus = (TileEntityBusFluidStorage) blockTE;
		if (!world.isRemote)
		{
			storageBus.updateGrid();
			PacketDispatcher.sendPacketToAllPlayers(world.getBlockTileEntity(x, y, z).getDescriptionPacket());
			MinecraftForge.EVENT_BUS.post(new GridStorageUpdateEvent(world, new WorldCoord(x, y, z), storageBus.getGrid()));
		}
		ForgeDirection blockOrientation = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));

		TileEntity fluidHandler = world.getBlockTileEntity(x + blockOrientation.offsetX, y + blockOrientation.offsetY, z + blockOrientation.offsetZ);
		storageBus.setFluidHandler(fluidHandler instanceof IFluidHandler ? (IFluidHandler) fluidHandler : null);
	}
}
 
Example 2
Source File: BlockBusFluidImport.java    From ExtraCells1 with MIT License 6 votes vote down vote up
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int neighborID)
{
	super.onNeighborBlockChange(world, x, y, z, neighborID);
	if (!world.isRemote)
	{
		if (world.getBlockTileEntity(x, y, z) instanceof TileEntityBusFluidImport)
			((TileEntityBusFluidImport) world.getBlockTileEntity(x, y, z)).setRedstoneStatus(world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z));
		PacketDispatcher.sendPacketToAllPlayers(world.getBlockTileEntity(x, y, z).getDescriptionPacket());
	}
	ForgeDirection blockOrientation = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
	TileEntity blockTE = world.getBlockTileEntity(x, y, z);
	if (blockTE instanceof TileEntityBusFluidImport)
	{
		TileEntity fluidHandler = world.getBlockTileEntity(x + blockOrientation.offsetX, y + blockOrientation.offsetY, z + blockOrientation.offsetZ);
		((TileEntityBusFluidImport) blockTE).setFluidHandler(fluidHandler instanceof IFluidHandler ? (IFluidHandler) fluidHandler : null);
	}
}
 
Example 3
Source File: BlockBusFluidExport.java    From ExtraCells1 with MIT License 6 votes vote down vote up
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int neighborID)
{
	super.onNeighborBlockChange(world, x, y, z, neighborID);
	if (!world.isRemote)
	{
		if (world.getBlockTileEntity(x, y, z) instanceof TileEntityBusFluidExport)
			PacketDispatcher.sendPacketToAllPlayers(world.getBlockTileEntity(x, y, z).getDescriptionPacket());
		((TileEntityBusFluidExport) world.getBlockTileEntity(x, y, z)).setRedstoneStatus(world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z));
	}
	ForgeDirection blockOrientation = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
	TileEntity blockTE = world.getBlockTileEntity(x, y, z);
	if (blockTE instanceof TileEntityBusFluidExport)
	{
		TileEntity fluidHandler = world.getBlockTileEntity(x + blockOrientation.offsetX, y + blockOrientation.offsetY, z + blockOrientation.offsetZ);
		((TileEntityBusFluidExport) blockTE).setFluidHandler(fluidHandler instanceof IFluidHandler ? (IFluidHandler) fluidHandler : null);
	}
}
 
Example 4
Source File: BlockMEDropper.java    From ExtraCells1 with MIT License 6 votes vote down vote up
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int neighbourID)
{
	if (((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).todispense != null)
	{
		ItemStack request = ((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).todispense;
		if (!world.isRemote)
		{
			if ((world.isBlockIndirectlyGettingPowered(x, y, z) || world.isBlockIndirectlyGettingPowered(x, y + 1, z)) && unpowered)
			{
				if (((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).getGrid() != null)
				{
					IMEInventoryHandler cellArray = ((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).getGrid().getCellArray();
					if (cellArray != null && cellArray.extractItems(Util.createItemStack(request)) != null)
					{
						dispense(world, x, y, z, ((TileEntityMEDropper) world.getBlockTileEntity(x, y, z)).getItem().copy());
						unpowered = false;
					}
				}
			} else
			{
				unpowered = true;
			}
		}
	}
}
 
Example 5
Source File: BlockCertusTank.java    From ExtraCells1 with MIT License 6 votes vote down vote up
public ItemStack getDropWithNBT(World world, int x, int y, int z)
{
	NBTTagCompound tileEntity = new NBTTagCompound();
	TileEntity worldTE = world.getBlockTileEntity(x, y, z);
	if (worldTE != null && worldTE instanceof TileEntityCertusTank)
	{
		ItemStack dropStack = new ItemStack(BlockEnum.CERTUSTANK.getBlockInstance(), 1);

		((TileEntityCertusTank) worldTE).writeToNBTWithoutCoords(tileEntity);

		dropStack.setTagCompound(new NBTTagCompound());
		dropStack.stackTagCompound.setCompoundTag("tileEntity", tileEntity);
		return dropStack;

	}
	return null;
}
 
Example 6
Source File: CommonProxy.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
	TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
	if (tileEntity != null)
	{
		switch (ID)
		{
		case 0: // GUI Hard ME Drive
			return new GuiHardMEDrive(player.inventory, (TileEntityHardMEDrive) tileEntity);
		case 1: // GUI Fluid Terminal
			return new GuiTerminalFluid((TileEntityTerminalFluid) tileEntity, player);
		case 2: // GUI Storage Bus Fluid
			return new GuiBusFluidStorage(world, player.inventory, (TileEntityBusFluidStorage) tileEntity);
		case 3: // GUI Import Bus Fluid
			return new GuiBusFluidImport(world, player.inventory, (TileEntityBusFluidImport) tileEntity, player);
		case 4: // GUI Export Bus Fluid
			return new GuiBusFluidExport(world, player.inventory, (TileEntityBusFluidExport) tileEntity, player);
		case 5: // GUI ME Battery
			return new GuiMEBattery(world, (TileEntityMEBattery) tileEntity, player);
		case 6: // GUI ME Fluid Level Emitter
			return new GuiLevelEmitterFluid(player.inventory, (TileEntityLevelEmitterFluid) tileEntity);
		case 7: // GUI ME Fluid Interface
			return new GuiInterfaceFluid(player.inventory, (TileEntityInterfaceFluid) tileEntity);
		case 8: // GUI ME Fluid Crafter
			return new GuiFluidCrafter(player.inventory, ((TileEntityFluidCrafter) tileEntity).getInventory());
		default:
			return false;
		}
	} else
	{
		return false;
	}
}
 
Example 7
Source File: CommonProxy.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
	TileEntity tileEntity = world.getBlockTileEntity(x, y, z);

	if (tileEntity != null)
	{
		switch (ID)
		{
		case 0: // GUI Hard ME Drive
			return new ContainerHardMEDrive(player.inventory, (TileEntityHardMEDrive) tileEntity);
		case 1: // GUI Fluid Terminal
			return new ContainerTerminalFluid(player, ((TileEntityTerminalFluid) tileEntity).getInventory());
		case 2: // GUI Storage Bus Fluid
			return new ContainerBusFluidStorage(player.inventory, ((TileEntityBusFluidStorage) tileEntity).getInventory());
		case 3: // GUI Import Bus Fluid
			return new ContainerBusFluidImport(player.inventory, ((TileEntityBusFluidImport) tileEntity).getInventory());
		case 4: // GUI Export Bus Fluid
			return new ContainerBusFluidExport(player.inventory, ((TileEntityBusFluidExport) tileEntity).getInventory());
		case 5: // GUI ME Battery
			return new ContainerMEBattery();
		case 6: // GUI ME Fluid Level Emitter
			return new ContainerLevelEmitterFluid(player.inventory, ((TileEntityLevelEmitterFluid) tileEntity).getInventory());
		case 7: // GUI ME Fluid Interface
			return new ContainerInterfaceFluid(player.inventory, ((TileEntityInterfaceFluid) tileEntity).getInventory());
		case 8: // GUI ME Fluid Crafter
			return new ContainerFluidCrafter(player.inventory, ((TileEntityFluidCrafter) tileEntity).getInventory());
		default:
			return false;
		}
	} else
	{
		return false;
	}
}
 
Example 8
Source File: Grid.java    From ExtraCells1 with MIT License 5 votes vote down vote up
/**
 * Returns the grid entity at the given location, or null if its not a grid entity.
 * @param w
 * @param x
 * @param y
 * @param z
 * @return gridEntity
 */
public static IGridTileEntity getGridEntity(World w, int x, int y, int z)
{
    TileEntity te = w.getBlockTileEntity(x, y, z);

    if (te instanceof IGridTileEntity)
    {
        return (IGridTileEntity)te;
    }

    return null;
}
 
Example 9
Source File: BlockHardMEDrive.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float offsetX, float offsetY, float offsetZ)
{
	if (!world.isRemote)
	{
		if (world.getBlockTileEntity(x, y, z) == null || player.isSneaking())
		{
			return false;
		}
		player.openGui(Extracells.instance, 0, world, x, y, z);
	}
	return true;
}
 
Example 10
Source File: BlockMEBattery.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int neighbourID)
{
	if (!world.isRemote)
	{
		TileEntityMEBattery battery = (TileEntityMEBattery) world.getBlockTileEntity(x, y, z);
		battery.updateRedstone();
	}
}
 
Example 11
Source File: BlockMonitorStorageFluid.java    From ExtraCells1 with MIT License 5 votes vote down vote up
public ArrayList<ItemStack> getBlockDropped(World world, int x, int y, int z, int metadata, int fortune)
{
	ArrayList<ItemStack> items = super.getBlockDropped(world, x, y, z, metadata, fortune);
	TileEntity blockTE = world.getBlockTileEntity(x, y, z);
	if (blockTE instanceof TileEntityMonitorStorageFluid)
	{
		if (((TileEntityMonitorStorageFluid) blockTE).isMatrixed())
		{
			items.add(Materials.matConversionMatrix.copy());
		}
	}
	return items;
}
 
Example 12
Source File: BlockLevelEmitterFluid.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float offsetX, float offsetY, float offsetZ)
{
	if (!world.isRemote)
	{
		if (world.getBlockTileEntity(x, y, z) == null || player.isSneaking())
		{
			return false;
		}
		PacketDispatcher.sendPacketToPlayer(world.getBlockTileEntity(x, y, z).getDescriptionPacket(), (Player) player);
		player.openGui(Extracells.instance, 6, world, x, y, z);
	}
	return true;
}
 
Example 13
Source File: RotatableColorBlock.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis)
{
	ForgeDirection rotation = ForgeDirection.getOrientation(worldObj.getBlockMetadata(x, y, z));

	worldObj.setBlockMetadataWithNotify(x, y, z, rotateDirecions(rotation).ordinal(), 3);
	TileEntity te = worldObj.getBlockTileEntity(x, y, z);
	if (te instanceof IGridTileEntity)
	{
		MinecraftForge.EVENT_BUS.post(new GridTileConnectivityEvent((IGridTileEntity) te, worldObj, new WorldCoord(x, y, z)));
	}
	return true;
}
 
Example 14
Source File: BlockFluidTransitionPlane.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int neighbourID)
{
	TileEntity blockTE = world.getBlockTileEntity(x, y, z);
	if (blockTE instanceof TileEntityTransitionPlaneFluid)
	{
		((TileEntityTransitionPlaneFluid) blockTE).doWork();
	}
}
 
Example 15
Source File: BlockFluidCrafter.java    From ExtraCells1 with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float offsetX, float offsetY, float offsetZ)
{
	if (!world.isRemote)
	{
		if (world.getBlockTileEntity(x, y, z) == null || player.isSneaking())
		{
			return false;
		}
		player.openGui(Extracells.instance, 8, world, x, y, z);
	}
	return true;
}
 
Example 16
Source File: BlockHardMEDrive.java    From ExtraCells1 with MIT License 5 votes vote down vote up
private void dropItems(World world, int x, int y, int z)
{
	Random rand = new Random();

	TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
	if (!(tileEntity instanceof IInventory))
	{
		return;
	}
	IInventory inventory = (IInventory) tileEntity;

	for (int i = 0; i < inventory.getSizeInventory(); i++)
	{
		ItemStack item = inventory.getStackInSlot(i);

		if (item != null && item.stackSize > 0)
		{
			float rx = rand.nextFloat() * 0.8F + 0.1F;
			float ry = rand.nextFloat() * 0.8F + 0.1F;
			float rz = rand.nextFloat() * 0.8F + 0.1F;

			EntityItem entityItem = new EntityItem(world, x + rx, y + ry, z + rz, new ItemStack(item.itemID, item.stackSize, item.getItemDamage()));

			if (item.hasTagCompound())
			{
				entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy());
			}

			float factor = 0.05F;
			entityItem.motionX = rand.nextGaussian() * factor;
			entityItem.motionY = rand.nextGaussian() * factor + 0.2F;
			entityItem.motionZ = rand.nextGaussian() * factor;
			world.spawnEntityInWorld(entityItem);
			item.stackSize = 0;
		}
	}
}
 
Example 17
Source File: BlockCertusTank.java    From ExtraCells1 with MIT License 4 votes vote down vote up
@Override
public boolean onBlockActivated(World worldObj, int x, int y, int z, EntityPlayer entityplayer, int blockID, float offsetX, float offsetY, float offsetZ)
{

	ItemStack current = entityplayer.inventory.getCurrentItem();

	if (entityplayer.isSneaking() && current == null)
	{
		dropBlockAsItem_do(worldObj, x, y, z, getDropWithNBT(worldObj, x, y, z));
		worldObj.destroyBlock(x, y, z, false);
		return true;
	}
	if (current != null)
	{
		FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);
		TileEntityCertusTank tank = (TileEntityCertusTank) worldObj.getBlockTileEntity(x, y, z);

		if (liquid != null)
		{
			int amountFilled = tank.fill(ForgeDirection.UNKNOWN, liquid, true);

			if (amountFilled != 0 && !entityplayer.capabilities.isCreativeMode)
			{
				if (current.stackSize > 1)
				{
					entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize -= 1;
					entityplayer.inventory.addItemStackToInventory(current.getItem().getContainerItemStack(current));
				} else
				{
					entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = current.getItem().getContainerItemStack(current);
				}
			}

			return true;

			// Handle empty containers
		} else
		{

			FluidStack available = tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid;
			if (available != null)
			{
				ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current);

				liquid = FluidContainerRegistry.getFluidForFilledItem(filled);

				if (liquid != null)
				{
					if (!entityplayer.capabilities.isCreativeMode)
					{
						if (current.stackSize > 1)
						{
							if (!entityplayer.inventory.addItemStackToInventory(filled))
							{
								tank.fill(ForgeDirection.UNKNOWN, new FluidStack(liquid, liquid.amount), true);
								return false;
							} else
							{
								entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem].stackSize -= 1;
							}
						} else
						{
							entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = filled;
						}
					}
					tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true);
					return true;
				}
			}
		}
	}
	return false;
}
 
Example 18
Source File: BlockBusFluidExport.java    From ExtraCells1 with MIT License 4 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float offsetX, float offsetY, float offsetZ)
{
	if (!world.isRemote)
	{
		ItemStack currentItem = player.inventory.getCurrentItem();
		if (currentItem != null)
		{
			IMemoryCard card = Util.getAppEngApi().getMemoryCardHandler();
			TileEntity blockTE = world.getBlockTileEntity(x, y, z);

			if (card.isMemoryCard(currentItem))
			{
				if (player.isSneaking())
				{
					NBTTagCompound nbt = new NBTTagCompound();
					blockTE.writeToNBT(nbt);
					nbt.removeTag("x");
					nbt.removeTag("y");
					nbt.removeTag("z");
					blockTE.readFromNBT(nbt);
					card.setMemoryCardContents(currentItem, getUnlocalizedName() + ".name", nbt);
					player.sendChatToPlayer(new ChatMessageComponent().addText(StatCollector.translateToLocal("ChatMsg.SettingsSaved")));
					return true;
				} else if (card.getSettingsName(currentItem).equals(getUnlocalizedName() + ".name") || card.getSettingsName(currentItem).equals("AppEng.GuiITooltip.Blank"))
				{
					blockTE.readFromNBT(card.getData(currentItem));
					Packet description = blockTE.getDescriptionPacket();
					if (description != null)
						PacketDispatcher.sendPacketToAllPlayers(description);
					player.sendChatToPlayer(new ChatMessageComponent().addText(StatCollector.translateToLocal("ChatMsg.SettingsLoaded")));
					return true;
				} else
				{
					player.sendChatToPlayer(new ChatMessageComponent().addText(StatCollector.translateToLocal("ChatMsg.IncorrectDevice")));
					return true;
				}
			}
		}
		if (world.getBlockTileEntity(x, y, z) == null || player.isSneaking())
		{
			return false;
		}
		player.openGui(Extracells.instance, 4, world, x, y, z);
	}
	return true;
}
 
Example 19
Source File: ColorBlock.java    From ExtraCells1 with MIT License 4 votes vote down vote up
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemstack)
{
	ForgeDirection orientation = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));

	TileEntity clickedOnTileEntity = world.getBlockTileEntity(x + orientation.getOpposite().offsetX, y + orientation.getOpposite().offsetY, z + orientation.getOpposite().offsetZ);
	TileEntity blockTileEntity = world.getBlockTileEntity(x, y, z);

	if (blockTileEntity instanceof IColoredMETile)
	{
		if (clickedOnTileEntity instanceof IColoredMETile)
		{

			// All this shit to make it compatible w/ AE 13 AND 14 :D
			Method isColoredMethod = null;
			boolean isColored = false;

			try
			{
				// Method for AE 14 (With forgeDireciton argument)
				isColoredMethod = ((IColoredMETile) clickedOnTileEntity).getClass().getDeclaredMethod("isColored", ForgeDirection.class);
				isColored = (Boolean) isColoredMethod.invoke((IColoredMETile) clickedOnTileEntity, orientation);
			} catch (Throwable ex)
			{
				try
				{
					// Method for AE 13 (W/O the argument)
					isColoredMethod = ((IColoredMETile) clickedOnTileEntity).getClass().getDeclaredMethod("isColored");
					isColored = (Boolean) isColoredMethod.invoke(clickedOnTileEntity);
				} catch (Throwable e)
				{
				}
			}

			if (isColored)
			{
				((IColoredMETile) blockTileEntity).setColor(((IColoredMETile) clickedOnTileEntity).getColor());
			} else
			{
				((IColoredMETile) blockTileEntity).setColor(-1);
			}
		} else
		{
			((IColoredMETile) blockTileEntity).setColor(-1);
		}
	}

	if (player.isSneaking())
	{
		world.setBlockMetadataWithNotify(x, y, z, orientation.getOpposite().ordinal(), 3);
	}
}
 
Example 20
Source File: BlockBusFluidImport.java    From ExtraCells1 with MIT License 4 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float offsetX, float offsetY, float offsetZ)
{
	if (!world.isRemote)
	{
		ItemStack currentItem = player.inventory.getCurrentItem();
		if (currentItem != null)
		{
			IMemoryCard card = Util.getAppEngApi().getMemoryCardHandler();
			TileEntity blockTE = world.getBlockTileEntity(x, y, z);

			if (card.isMemoryCard(currentItem))
			{
				if (player.isSneaking())
				{
					NBTTagCompound nbt = new NBTTagCompound();
					blockTE.writeToNBT(nbt);
					nbt.removeTag("x");
					nbt.removeTag("y");
					nbt.removeTag("z");
					blockTE.readFromNBT(nbt);
					card.setMemoryCardContents(currentItem, getUnlocalizedName() + ".name", nbt);
					player.sendChatToPlayer(new ChatMessageComponent().addText(StatCollector.translateToLocal("ChatMsg.SettingsSaved")));
					return true;
				} else if (card.getSettingsName(currentItem).equals(getUnlocalizedName() + ".name") || card.getSettingsName(currentItem).equals("AppEng.GuiITooltip.Blank"))
				{
					blockTE.readFromNBT(card.getData(currentItem));
					Packet description = blockTE.getDescriptionPacket();
					if (description != null)
						PacketDispatcher.sendPacketToAllPlayers(description);
					player.sendChatToPlayer(new ChatMessageComponent().addText(StatCollector.translateToLocal("ChatMsg.SettingsLoaded")));
					return true;
				} else
				{
					player.sendChatToPlayer(new ChatMessageComponent().addText(StatCollector.translateToLocal("ChatMsg.IncorrectDevice")));
					return true;
				}
			}
		}
		if (world.getBlockTileEntity(x, y, z) == null || player.isSneaking())
		{
			return false;
		}
		player.openGui(Extracells.instance, 3, world, x, y, z);
	}
	return true;
}