priority on drives
This commit is contained in:
		| @@ -13,7 +13,7 @@ public class ContainerDrive extends ContainerBase | ||||
| 	{ | ||||
| 		super(player); | ||||
|  | ||||
| 		int x = 71; | ||||
| 		int x = 8; | ||||
| 		int y = 20; | ||||
|  | ||||
| 		for (int i = 0; i < 8; ++i) | ||||
| @@ -22,7 +22,7 @@ public class ContainerDrive extends ContainerBase | ||||
|  | ||||
| 			if ((i + 1) % 2 == 0) | ||||
| 			{ | ||||
| 				x = 71; | ||||
| 				x = 8; | ||||
| 				y += 18; | ||||
| 			} | ||||
| 			else | ||||
|   | ||||
| @@ -1,13 +1,20 @@ | ||||
| package storagecraft.gui; | ||||
|  | ||||
| import com.google.common.primitives.Ints; | ||||
| import java.io.IOException; | ||||
| import net.minecraft.client.gui.GuiTextField; | ||||
| import storagecraft.StorageCraft; | ||||
| import storagecraft.container.ContainerDrive; | ||||
| import storagecraft.gui.sidebutton.SideButtonRedstoneMode; | ||||
| import storagecraft.network.MessagePriorityUpdate; | ||||
| import storagecraft.tile.TileDrive; | ||||
|  | ||||
| public class GuiDrive extends GuiBase | ||||
| { | ||||
| 	private TileDrive drive; | ||||
|  | ||||
| 	private GuiTextField priorityField; | ||||
|  | ||||
| 	public GuiDrive(ContainerDrive container, TileDrive drive) | ||||
| 	{ | ||||
| 		super(container, 176, 190); | ||||
| @@ -19,6 +26,14 @@ public class GuiDrive extends GuiBase | ||||
| 	public void init(int x, int y) | ||||
| 	{ | ||||
| 		addSideButton(new SideButtonRedstoneMode(drive)); | ||||
|  | ||||
| 		priorityField = new GuiTextField(0, fontRendererObj, x + 52 + 1, y + 32 + 1, 25, fontRendererObj.FONT_HEIGHT); | ||||
| 		priorityField.setText(String.valueOf(drive.getPriority())); | ||||
| 		priorityField.setEnableBackgroundDrawing(false); | ||||
| 		priorityField.setVisible(true); | ||||
| 		priorityField.setTextColor(16777215); | ||||
| 		priorityField.setCanLoseFocus(false); | ||||
| 		priorityField.setFocused(true); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| @@ -32,12 +47,33 @@ public class GuiDrive extends GuiBase | ||||
| 		bindTexture("gui/drive.png"); | ||||
|  | ||||
| 		drawTexture(x, y, 0, 0, width, height); | ||||
|  | ||||
| 		priorityField.drawTextBox(); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void drawForeground(int mouseX, int mouseY) | ||||
| 	{ | ||||
| 		drawString(7, 7, t("gui.storagecraft:drive")); | ||||
| 		drawString(51, 20, t("misc.storagecraft:priority")); | ||||
| 		drawString(7, 96, t("container.inventory")); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	protected void keyTyped(char character, int keyCode) throws IOException | ||||
| 	{ | ||||
| 		if (!checkHotbarKeys(keyCode) && priorityField.textboxKeyTyped(character, keyCode)) | ||||
| 		{ | ||||
| 			Integer result = Ints.tryParse(priorityField.getText()); | ||||
|  | ||||
| 			if (result != null) | ||||
| 			{ | ||||
| 				StorageCraft.NETWORK.sendToServer(new MessagePriorityUpdate(drive.getPos(), result)); | ||||
| 			} | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			super.keyTyped(character, keyCode); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -5,21 +5,22 @@ import net.minecraft.entity.player.EntityPlayerMP; | ||||
| import net.minecraft.tileentity.TileEntity; | ||||
| import net.minecraft.util.BlockPos; | ||||
| import net.minecraftforge.fml.common.network.simpleimpl.IMessage; | ||||
| import storagecraft.tile.TileDrive; | ||||
| import storagecraft.tile.TileExternalStorage; | ||||
| import storagecraft.tile.TileStorage; | ||||
| 
 | ||||
| public class MessageStoragePriorityUpdate extends MessageHandlerPlayerToServer<MessageStoragePriorityUpdate> implements IMessage | ||||
| public class MessagePriorityUpdate extends MessageHandlerPlayerToServer<MessagePriorityUpdate> implements IMessage | ||||
| { | ||||
| 	private int x; | ||||
| 	private int y; | ||||
| 	private int z; | ||||
| 	private int priority; | ||||
| 
 | ||||
| 	public MessageStoragePriorityUpdate() | ||||
| 	public MessagePriorityUpdate() | ||||
| 	{ | ||||
| 	} | ||||
| 
 | ||||
| 	public MessageStoragePriorityUpdate(BlockPos pos, int priority) | ||||
| 	public MessagePriorityUpdate(BlockPos pos, int priority) | ||||
| 	{ | ||||
| 		this.x = pos.getX(); | ||||
| 		this.y = pos.getY(); | ||||
| @@ -46,7 +47,7 @@ public class MessageStoragePriorityUpdate extends MessageHandlerPlayerToServer<M | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void handle(MessageStoragePriorityUpdate message, EntityPlayerMP player) | ||||
| 	public void handle(MessagePriorityUpdate message, EntityPlayerMP player) | ||||
| 	{ | ||||
| 		TileEntity tile = player.worldObj.getTileEntity(new BlockPos(message.x, message.y, message.z)); | ||||
| 
 | ||||
| @@ -58,5 +59,9 @@ public class MessageStoragePriorityUpdate extends MessageHandlerPlayerToServer<M | ||||
| 		{ | ||||
| 			((TileExternalStorage) tile).setPriority(message.priority); | ||||
| 		} | ||||
| 		else if (tile instanceof TileDrive) | ||||
| 		{ | ||||
| 			((TileDrive) tile).setPriority(message.priority); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @@ -36,7 +36,7 @@ public class CommonProxy | ||||
| 		StorageCraft.NETWORK.registerMessage(MessageDetectorAmountUpdate.class, MessageDetectorAmountUpdate.class, 7, Side.SERVER); | ||||
| 		StorageCraft.NETWORK.registerMessage(MessageGridCraftingUpdate.class, MessageGridCraftingUpdate.class, 8, Side.CLIENT); | ||||
| 		StorageCraft.NETWORK.registerMessage(MessageGridCraftingClear.class, MessageGridCraftingClear.class, 9, Side.SERVER); | ||||
| 		StorageCraft.NETWORK.registerMessage(MessageStoragePriorityUpdate.class, MessageStoragePriorityUpdate.class, 10, Side.SERVER); | ||||
| 		StorageCraft.NETWORK.registerMessage(MessagePriorityUpdate.class, MessagePriorityUpdate.class, 10, Side.SERVER); | ||||
|  | ||||
| 		NetworkRegistry.INSTANCE.registerGuiHandler(StorageCraft.INSTANCE, new GuiHandler()); | ||||
|  | ||||
|   | ||||
| @@ -5,9 +5,9 @@ import storagecraft.item.ItemStorageCell; | ||||
|  | ||||
| public class CellStorage extends NBTStorage | ||||
| { | ||||
| 	public CellStorage(ItemStack cell) | ||||
| 	public CellStorage(ItemStack cell, int priority) | ||||
| 	{ | ||||
| 		super(cell.getTagCompound(), getCapacity(cell), 0); | ||||
| 		super(cell.getTagCompound(), getCapacity(cell), priority); | ||||
| 	} | ||||
|  | ||||
| 	public static int getCapacity(ItemStack cell) | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| package storagecraft.tile; | ||||
|  | ||||
| import io.netty.buffer.ByteBuf; | ||||
| import java.util.List; | ||||
| import net.minecraft.entity.player.EntityPlayer; | ||||
| import net.minecraft.inventory.IInventory; | ||||
| import net.minecraft.item.ItemStack; | ||||
| @@ -11,12 +13,14 @@ import storagecraft.storage.IStorage; | ||||
| import storagecraft.storage.IStorageProvider; | ||||
| import storagecraft.util.InventoryUtils; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| public class TileDrive extends TileMachine implements IInventory, IStorageProvider | ||||
| { | ||||
| 	public static final String NBT_PRIORITY = "Priority"; | ||||
|  | ||||
| 	private InventorySimple inventory = new InventorySimple("drive", 8); | ||||
|  | ||||
| 	private int priority = 0; | ||||
|  | ||||
| 	@Override | ||||
| 	public int getEnergyUsage() | ||||
| 	{ | ||||
| @@ -38,12 +42,27 @@ public class TileDrive extends TileMachine implements IInventory, IStorageProvid | ||||
| 	{ | ||||
| 	} | ||||
|  | ||||
| 	public int getPriority() | ||||
| 	{ | ||||
| 		return priority; | ||||
| 	} | ||||
|  | ||||
| 	public void setPriority(int priority) | ||||
| 	{ | ||||
| 		this.priority = priority; | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void readFromNBT(NBTTagCompound nbt) | ||||
| 	{ | ||||
| 		super.readFromNBT(nbt); | ||||
|  | ||||
| 		InventoryUtils.restoreInventory(this, nbt); | ||||
|  | ||||
| 		if (nbt.hasKey(NBT_PRIORITY)) | ||||
| 		{ | ||||
| 			priority = nbt.getInteger(NBT_PRIORITY); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| @@ -52,6 +71,24 @@ public class TileDrive extends TileMachine implements IInventory, IStorageProvid | ||||
| 		super.writeToNBT(nbt); | ||||
|  | ||||
| 		InventoryUtils.saveInventory(this, nbt); | ||||
|  | ||||
| 		nbt.setInteger(NBT_PRIORITY, priority); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void toBytes(ByteBuf buf) | ||||
| 	{ | ||||
| 		super.toBytes(buf); | ||||
|  | ||||
| 		buf.writeInt(priority); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| 	public void fromBytes(ByteBuf buf) | ||||
| 	{ | ||||
| 		super.fromBytes(buf); | ||||
|  | ||||
| 		priority = buf.readInt(); | ||||
| 	} | ||||
|  | ||||
| 	@Override | ||||
| @@ -61,7 +98,7 @@ public class TileDrive extends TileMachine implements IInventory, IStorageProvid | ||||
| 		{ | ||||
| 			if (getStackInSlot(i) != null) | ||||
| 			{ | ||||
| 				storages.add(new CellStorage(getStackInSlot(i))); | ||||
| 				storages.add(new CellStorage(getStackInSlot(i), priority)); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|   | ||||
| @@ -10,7 +10,7 @@ import net.minecraftforge.fml.relauncher.Side; | ||||
| import net.minecraftforge.fml.relauncher.SideOnly; | ||||
| import storagecraft.StorageCraft; | ||||
| import storagecraft.inventory.InventorySimple; | ||||
| import storagecraft.network.MessageStoragePriorityUpdate; | ||||
| import storagecraft.network.MessagePriorityUpdate; | ||||
| import storagecraft.storage.IStorage; | ||||
| import storagecraft.storage.IStorageGui; | ||||
| import storagecraft.storage.IStorageProvider; | ||||
| @@ -307,7 +307,7 @@ public class TileExternalStorage extends TileMachine implements IStorageProvider | ||||
| 			@Override | ||||
| 			public void onPriorityChanged(int priority) | ||||
| 			{ | ||||
| 				StorageCraft.NETWORK.sendToServer(new MessageStoragePriorityUpdate(pos, priority)); | ||||
| 				StorageCraft.NETWORK.sendToServer(new MessagePriorityUpdate(pos, priority)); | ||||
| 			} | ||||
| 		}; | ||||
| 	} | ||||
|   | ||||
| @@ -11,7 +11,7 @@ import storagecraft.StorageCraft; | ||||
| import storagecraft.block.BlockStorage; | ||||
| import storagecraft.block.EnumStorageType; | ||||
| import storagecraft.inventory.InventorySimple; | ||||
| import storagecraft.network.MessageStoragePriorityUpdate; | ||||
| import storagecraft.network.MessagePriorityUpdate; | ||||
| import storagecraft.storage.IStorage; | ||||
| import storagecraft.storage.IStorageGui; | ||||
| import storagecraft.storage.IStorageProvider; | ||||
| @@ -272,7 +272,7 @@ public class TileStorage extends TileMachine implements IStorageProvider, IStora | ||||
| 			@Override | ||||
| 			public void onPriorityChanged(int priority) | ||||
| 			{ | ||||
| 				StorageCraft.NETWORK.sendToServer(new MessageStoragePriorityUpdate(pos, priority)); | ||||
| 				StorageCraft.NETWORK.sendToServer(new MessagePriorityUpdate(pos, priority)); | ||||
| 			} | ||||
| 		}; | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Raoul Van den Berge
					Raoul Van den Berge