Interface base block (with inventory)
This commit is contained in:
		| @@ -19,4 +19,5 @@ public final class RefinedStorageBlocks | ||||
| 	public static final BlockConstructor CONSTRUCTOR = new BlockConstructor(); | ||||
| 	public static final BlockStorage STORAGE = new BlockStorage(); | ||||
| 	public static final BlockRelay RELAY = new BlockRelay(); | ||||
| 	public static final BlockInterface INTERFACE = new BlockInterface(); | ||||
| } | ||||
|   | ||||
| @@ -14,4 +14,5 @@ public final class RefinedStorageGui | ||||
| 	public static final int CONSTRUCTOR = 10; | ||||
| 	public static final int STORAGE = 11; | ||||
| 	public static final int RELAY = 12; | ||||
| 	public static final int INTERFACE = 13; | ||||
| } | ||||
|   | ||||
							
								
								
									
										37
									
								
								src/main/java/refinedstorage/block/BlockInterface.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/main/java/refinedstorage/block/BlockInterface.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| package refinedstorage.block; | ||||
|  | ||||
| import net.minecraft.block.state.IBlockState; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.EnumFacing; | ||||
| import net.minecraft.util.EnumHand; | ||||
| import net.minecraft.world.World; | ||||
| import refinedstorage.RefinedStorage; | ||||
| import refinedstorage.RefinedStorageGui; | ||||
| import refinedstorage.tile.TileInterface; | ||||
|  | ||||
| public class BlockInterface extends BlockMachine | ||||
| { | ||||
| 	public BlockInterface() | ||||
| 	{ | ||||
| 		super("interface"); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public TileEntity createTileEntity(World world, IBlockState state) | ||||
| 	{ | ||||
| 		return new TileInterface(); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public boolean onBlockActivated(World world, net.minecraft.util.math.BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) | ||||
| 	{ | ||||
| 		if (!world.isRemote) | ||||
| 		{ | ||||
| 			player.openGui(RefinedStorage.INSTANCE, RefinedStorageGui.INTERFACE, world, pos.getX(), pos.getY(), pos.getZ()); | ||||
| 		} | ||||
|  | ||||
| 		return true; | ||||
| 	} | ||||
| } | ||||
| @@ -13,7 +13,7 @@ public class ContainerConstructor extends ContainerBase | ||||
| 	{ | ||||
| 		public SlotConstructor(IInventory inventory, int id, int x, int y) | ||||
| 		{ | ||||
| 			super(inventory, id, x, y); | ||||
| 			super(inventory, id, x, y, false); | ||||
| 		} | ||||
|  | ||||
| 		@Override | ||||
|   | ||||
| @@ -10,7 +10,7 @@ public class ContainerDetector extends ContainerBase | ||||
| 	{ | ||||
| 		super(player); | ||||
|  | ||||
| 		addSlotToContainer(new SlotSpecimen(detector.getInventory(), 0, 107, 20)); | ||||
| 		addSlotToContainer(new SlotSpecimen(detector.getInventory(), 0, 107, 20, false)); | ||||
|  | ||||
| 		addPlayerInventory(8, 55); | ||||
| 	} | ||||
|   | ||||
| @@ -12,7 +12,7 @@ public class ContainerExporter extends ContainerBase | ||||
|  | ||||
| 		for (int i = 0; i < 9; ++i) | ||||
| 		{ | ||||
| 			addSlotToContainer(new SlotSpecimen(exporter.getInventory(), i, 8 + (18 * i), 20)); | ||||
| 			addSlotToContainer(new SlotSpecimen(exporter.getInventory(), i, 8 + (18 * i), 20, false)); | ||||
| 		} | ||||
|  | ||||
| 		addPlayerInventory(8, 55); | ||||
|   | ||||
| @@ -12,7 +12,7 @@ public class ContainerImporter extends ContainerBase | ||||
|  | ||||
| 		for (int i = 0; i < 9; ++i) | ||||
| 		{ | ||||
| 			addSlotToContainer(new SlotSpecimen(importer.getInventory(), i, 8 + (18 * i), 20)); | ||||
| 			addSlotToContainer(new SlotSpecimen(importer.getInventory(), i, 8 + (18 * i), 20, false)); | ||||
| 		} | ||||
|  | ||||
| 		addPlayerInventory(8, 55); | ||||
|   | ||||
| @@ -0,0 +1,32 @@ | ||||
| package refinedstorage.container; | ||||
|  | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.inventory.Slot; | ||||
| import refinedstorage.container.slot.SlotOutput; | ||||
| import refinedstorage.container.slot.SlotSpecimen; | ||||
| import refinedstorage.tile.TileInterface; | ||||
|  | ||||
| public class ContainerInterface extends ContainerBase | ||||
| { | ||||
| 	public ContainerInterface(EntityPlayer player, TileInterface tile) | ||||
| 	{ | ||||
| 		super(player); | ||||
|  | ||||
| 		for (int i = 0; i < 9; ++i) | ||||
| 		{ | ||||
| 			addSlotToContainer(new Slot(tile, i, 8 + (18 * i), 20)); | ||||
| 		} | ||||
|  | ||||
| 		for (int i = 9; i < 18; ++i) | ||||
| 		{ | ||||
| 			addSlotToContainer(new SlotSpecimen(tile, i, 8 + (18 * (i - 9)), 54, true)); | ||||
| 		} | ||||
|  | ||||
| 		for (int i = 18; i < 27; ++i) | ||||
| 		{ | ||||
| 			addSlotToContainer(new SlotOutput(tile, i, 8 + (18 * (i - 18)), 100)); | ||||
| 		} | ||||
|  | ||||
| 		addPlayerInventory(8, 136); | ||||
| 	} | ||||
| } | ||||
| @@ -12,7 +12,7 @@ public class ContainerStorage extends ContainerBase | ||||
|  | ||||
| 		for (int i = 0; i < 9; ++i) | ||||
| 		{ | ||||
| 			addSlotToContainer(new SlotSpecimen(inventory, i, 8 + (18 * i), 20)); | ||||
| 			addSlotToContainer(new SlotSpecimen(inventory, i, 8 + (18 * i), 20, false)); | ||||
| 		} | ||||
|  | ||||
| 		addPlayerInventory(8, 129); | ||||
|   | ||||
| @@ -7,9 +7,13 @@ import net.minecraft.item.ItemStack; | ||||
|  | ||||
| public class SlotSpecimen extends Slot | ||||
| { | ||||
| 	public SlotSpecimen(IInventory inventory, int id, int x, int y) | ||||
| 	private boolean allowSize; | ||||
|  | ||||
| 	public SlotSpecimen(IInventory inventory, int id, int x, int y, boolean allowSize) | ||||
| 	{ | ||||
| 		super(inventory, id, x, y); | ||||
|  | ||||
| 		this.allowSize = allowSize; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| @@ -27,7 +31,7 @@ public class SlotSpecimen extends Slot | ||||
| 	@Override | ||||
| 	public void putStack(ItemStack stack) | ||||
| 	{ | ||||
| 		if (stack != null) | ||||
| 		if (stack != null && !allowSize) | ||||
| 		{ | ||||
| 			stack.stackSize = 1; | ||||
| 		} | ||||
|   | ||||
| @@ -41,6 +41,8 @@ public class GuiHandler implements IGuiHandler | ||||
| 				return new ContainerStorage(player, ((IStorageGui) tile).getInventory()); | ||||
| 			case RefinedStorageGui.RELAY: | ||||
| 				return new ContainerRelay(player); | ||||
| 			case RefinedStorageGui.INTERFACE: | ||||
| 				return new ContainerInterface(player, (TileInterface) tile); | ||||
| 			default: | ||||
| 				return null; | ||||
| 		} | ||||
| @@ -83,6 +85,8 @@ public class GuiHandler implements IGuiHandler | ||||
| 				return new GuiStorage((ContainerStorage) getContainer(ID, player, tile), (IStorageGui) tile); | ||||
| 			case RefinedStorageGui.RELAY: | ||||
| 				return new GuiRelay((ContainerRelay) getContainer(ID, player, tile), (TileRelay) tile); | ||||
| 			case RefinedStorageGui.INTERFACE: | ||||
| 				return new GuiInterface((ContainerInterface) getContainer(ID, player, tile), (TileInterface) tile); | ||||
| 			default: | ||||
| 				return null; | ||||
| 		} | ||||
|   | ||||
							
								
								
									
										44
									
								
								src/main/java/refinedstorage/gui/GuiInterface.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/main/java/refinedstorage/gui/GuiInterface.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| package refinedstorage.gui; | ||||
|  | ||||
| import refinedstorage.container.ContainerInterface; | ||||
| import refinedstorage.gui.sidebutton.SideButtonRedstoneMode; | ||||
| import refinedstorage.tile.TileInterface; | ||||
|  | ||||
| public class GuiInterface extends GuiBase | ||||
| { | ||||
| 	private TileInterface tile; | ||||
|  | ||||
| 	public GuiInterface(ContainerInterface container, TileInterface tile) | ||||
| 	{ | ||||
| 		super(container, 176, 218); | ||||
|  | ||||
| 		this.tile = tile; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void init(int x, int y) | ||||
| 	{ | ||||
| 		addSideButton(new SideButtonRedstoneMode(tile)); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void update(int x, int y) | ||||
| 	{ | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void drawBackground(int x, int y, int mouseX, int mouseY) | ||||
| 	{ | ||||
| 		bindTexture("gui/interface.png"); | ||||
|  | ||||
| 		drawTexture(x, y, 0, 0, width, height); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void drawForeground(int mouseX, int mouseY) | ||||
| 	{ | ||||
| 		drawString(7, 7, t("gui.refinedstorage:interface.import")); | ||||
| 		drawString(7, 42, t("gui.refinedstorage:interface.export")); | ||||
| 		drawString(7, 123, t("container.inventory")); | ||||
| 	} | ||||
| } | ||||
| @@ -53,6 +53,7 @@ public class CommonProxy | ||||
| 		GameRegistry.registerTileEntity(TileConstructor.class, "constructor"); | ||||
| 		GameRegistry.registerTileEntity(TileStorage.class, "storage"); | ||||
| 		GameRegistry.registerTileEntity(TileRelay.class, "relay"); | ||||
| 		GameRegistry.registerTileEntity(TileInterface.class, "interface"); | ||||
|  | ||||
| 		GameRegistry.registerBlock(RefinedStorageBlocks.CONTROLLER, ItemBlockController.class, "controller"); | ||||
| 		GameRegistry.registerBlock(RefinedStorageBlocks.CABLE, "cable"); | ||||
| @@ -68,7 +69,8 @@ public class CommonProxy | ||||
| 		GameRegistry.registerBlock(RefinedStorageBlocks.DESTRUCTOR, "destructor"); | ||||
| 		GameRegistry.registerBlock(RefinedStorageBlocks.CONSTRUCTOR, "constructor"); | ||||
| 		GameRegistry.registerBlock(RefinedStorageBlocks.STORAGE, ItemBlockStorage.class, "storage"); | ||||
| 		GameRegistry.registerBlock(RefinedStorageBlocks.RELAY, "relay"); | ||||
| 		GameRegistry.registerBlock(RefinedStorageBlocks.RELAY, "relay"); // @TODO: Recipe | ||||
| 		GameRegistry.registerBlock(RefinedStorageBlocks.INTERFACE, "interface"); // @TODO: Recipe | ||||
|  | ||||
| 		GameRegistry.registerItem(RefinedStorageItems.STORAGE_CELL, "storage_cell"); | ||||
| 		GameRegistry.registerItem(RefinedStorageItems.WIRELESS_GRID, "wireless_grid"); | ||||
|   | ||||
							
								
								
									
										183
									
								
								src/main/java/refinedstorage/tile/TileInterface.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										183
									
								
								src/main/java/refinedstorage/tile/TileInterface.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,183 @@ | ||||
| package refinedstorage.tile; | ||||
|  | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.inventory.IInventory; | ||||
| import net.minecraft.inventory.ISidedInventory; | ||||
| import net.minecraft.item.ItemStack; | ||||
| import net.minecraft.nbt.NBTTagCompound; | ||||
| import net.minecraft.util.EnumFacing; | ||||
| import net.minecraft.util.text.ITextComponent; | ||||
| import refinedstorage.inventory.InventorySimple; | ||||
| import refinedstorage.util.InventoryUtils; | ||||
|  | ||||
| public class TileInterface extends TileMachine implements ISidedInventory | ||||
| { | ||||
| 	// 1st row for import | ||||
| 	// 2st row for specimen to export | ||||
| 	// 3st row for export | ||||
| 	private InventorySimple inventory = new InventorySimple("interface", 9 * 3); | ||||
|  | ||||
| 	@Override | ||||
| 	public int getEnergyUsage() | ||||
| 	{ | ||||
| 		return 5; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void updateMachine() | ||||
| 	{ | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void readFromNBT(NBTTagCompound nbt) | ||||
| 	{ | ||||
| 		super.readFromNBT(nbt); | ||||
|  | ||||
| 		InventoryUtils.restoreInventory(this, 0, nbt); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void writeToNBT(NBTTagCompound nbt) | ||||
| 	{ | ||||
| 		super.writeToNBT(nbt); | ||||
|  | ||||
| 		InventoryUtils.saveInventory(this, 0, nbt); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public int getSizeInventory() | ||||
| 	{ | ||||
| 		return inventory.getSizeInventory(); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public ItemStack getStackInSlot(int slot) | ||||
| 	{ | ||||
| 		return inventory.getStackInSlot(slot); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public ItemStack decrStackSize(int slot, int count) | ||||
| 	{ | ||||
| 		return inventory.decrStackSize(slot, count); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public ItemStack removeStackFromSlot(int slot) | ||||
| 	{ | ||||
| 		return inventory.removeStackFromSlot(slot); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void setInventorySlotContents(int slot, ItemStack stack) | ||||
| 	{ | ||||
| 		inventory.setInventorySlotContents(slot, stack); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public int getInventoryStackLimit() | ||||
| 	{ | ||||
| 		return inventory.getInventoryStackLimit(); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public boolean isUseableByPlayer(EntityPlayer player) | ||||
| 	{ | ||||
| 		return inventory.isUseableByPlayer(player); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void openInventory(EntityPlayer player) | ||||
| 	{ | ||||
| 		inventory.openInventory(player); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void closeInventory(EntityPlayer player) | ||||
| 	{ | ||||
| 		inventory.closeInventory(player); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public boolean isItemValidForSlot(int slot, ItemStack stack) | ||||
| 	{ | ||||
| 		return inventory.isItemValidForSlot(slot, stack); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public int getField(int id) | ||||
| 	{ | ||||
| 		return inventory.getField(id); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void setField(int id, int value) | ||||
| 	{ | ||||
| 		inventory.setField(id, value); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public int getFieldCount() | ||||
| 	{ | ||||
| 		return inventory.getFieldCount(); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void clear() | ||||
| 	{ | ||||
| 		inventory.clear(); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public String getName() | ||||
| 	{ | ||||
| 		return inventory.getName(); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public boolean hasCustomName() | ||||
| 	{ | ||||
| 		return inventory.hasCustomName(); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public ITextComponent getDisplayName() | ||||
| 	{ | ||||
| 		return inventory.getDisplayName(); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public IInventory getDroppedInventory() | ||||
| 	{ | ||||
| 		return inventory; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public int[] getSlotsForFace(EnumFacing side) | ||||
| 	{ | ||||
| 		if (side == EnumFacing.DOWN) | ||||
| 		{ | ||||
| 			return new int[] | ||||
| 			{ | ||||
| 				18, 19, 20, 21, 22, 23, 24, 25, 26 | ||||
| 			}; | ||||
| 		} | ||||
|  | ||||
| 		return new int[] | ||||
| 		{ | ||||
| 			0, 1, 2, 3, 4, 5, 6, 7, 8 | ||||
| 		}; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side) | ||||
| 	{ | ||||
| 		return slot < 9; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side) | ||||
| 	{ | ||||
| 		return slot >= 18; | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Raoul Van den Berge
					Raoul Van den Berge