importer block
This commit is contained in:
@@ -19,6 +19,7 @@ public class SC {
|
||||
public static final int CONTROLLER = 0;
|
||||
public static final int GRID = 1;
|
||||
public static final int DRIVE = 2;
|
||||
public static final int IMPORTER = 3;
|
||||
}
|
||||
|
||||
public static final String ID = "storagecraft";
|
||||
|
@@ -4,6 +4,7 @@ import storagecraft.block.BlockCable;
|
||||
import storagecraft.block.BlockController;
|
||||
import storagecraft.block.BlockDrive;
|
||||
import storagecraft.block.BlockGrid;
|
||||
import storagecraft.block.BlockImporter;
|
||||
import storagecraft.block.BlockStorageProxy;
|
||||
|
||||
public class SCBlocks {
|
||||
@@ -12,4 +13,5 @@ public class SCBlocks {
|
||||
public static final BlockGrid GRID = new BlockGrid();
|
||||
public static final BlockDrive DRIVE = new BlockDrive();
|
||||
public static final BlockStorageProxy STORAGE_PROXY = new BlockStorageProxy();
|
||||
public static final BlockImporter IMPORTER = new BlockImporter();
|
||||
}
|
||||
|
28
src/main/java/storagecraft/block/BlockImporter.java
Normal file
28
src/main/java/storagecraft/block/BlockImporter.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package storagecraft.block;
|
||||
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import storagecraft.SC;
|
||||
import storagecraft.tile.TileImporter;
|
||||
|
||||
public class BlockImporter extends BlockSC implements ITileEntityProvider {
|
||||
public BlockImporter() {
|
||||
super("importer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World world, int meta) {
|
||||
return new TileImporter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
|
||||
if (!world.isRemote) {
|
||||
player.openGui(SC.INSTANCE, SC.GUI.IMPORTER, world, x, y, z);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -11,7 +11,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import storagecraft.SC;
|
||||
import storagecraft.tile.TileSC;
|
||||
import storagecraft.util.InventoryUtil;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class BlockSC extends Block {
|
||||
private String name;
|
||||
@@ -46,7 +46,7 @@ public class BlockSC extends Block {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
|
||||
if (tile instanceof IInventory) {
|
||||
InventoryUtil.dropInventory(world, (IInventory) tile, x, y, z, 0);
|
||||
InventoryUtils.dropInventory(world, (IInventory) tile, x, y, z);
|
||||
}
|
||||
|
||||
super.onBlockPreDestroy(world, x, y, z, meta);
|
||||
|
@@ -9,9 +9,11 @@ import storagecraft.SC;
|
||||
import storagecraft.inventory.ContainerController;
|
||||
import storagecraft.inventory.ContainerDrive;
|
||||
import storagecraft.inventory.ContainerGrid;
|
||||
import storagecraft.inventory.ContainerImporter;
|
||||
import storagecraft.tile.TileController;
|
||||
import storagecraft.tile.TileDrive;
|
||||
import storagecraft.tile.TileGrid;
|
||||
import storagecraft.tile.TileImporter;
|
||||
|
||||
public class GuiHandler implements IGuiHandler {
|
||||
private Container getContainer(int ID, EntityPlayer player, TileEntity tile) {
|
||||
@@ -22,6 +24,8 @@ public class GuiHandler implements IGuiHandler {
|
||||
return new ContainerGrid(player);
|
||||
case SC.GUI.DRIVE:
|
||||
return new ContainerDrive(player, (TileDrive) tile);
|
||||
case SC.GUI.IMPORTER:
|
||||
return new ContainerImporter(player, (TileImporter) tile);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -43,6 +47,8 @@ public class GuiHandler implements IGuiHandler {
|
||||
return new GuiGrid((ContainerGrid) getContainer(ID, player, tile), (TileGrid) tile);
|
||||
case SC.GUI.DRIVE:
|
||||
return new GuiDrive((ContainerDrive) getContainer(ID, player, tile));
|
||||
case SC.GUI.IMPORTER:
|
||||
return new GuiImporter((ContainerImporter) getContainer(ID, player, tile), (TileImporter) tile);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
|
87
src/main/java/storagecraft/gui/GuiImporter.java
Normal file
87
src/main/java/storagecraft/gui/GuiImporter.java
Normal file
@@ -0,0 +1,87 @@
|
||||
package storagecraft.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import storagecraft.SC;
|
||||
import storagecraft.inventory.ContainerImporter;
|
||||
import storagecraft.network.MessageImporterSettingsUpdate;
|
||||
import storagecraft.tile.TileImporter;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class GuiImporter extends GuiContainer {
|
||||
public static final ResourceLocation IMPORTER_RESOURCE = new ResourceLocation("storagecraft:textures/gui/importer.png");
|
||||
|
||||
private TileImporter importer;
|
||||
|
||||
private int compareFlags;
|
||||
|
||||
private GuiButton compareNBT;
|
||||
private GuiButton compareDamage;
|
||||
|
||||
public GuiImporter(ContainerImporter container, TileImporter importer) {
|
||||
super(container);
|
||||
|
||||
this.xSize = 176;
|
||||
this.ySize = 182;
|
||||
|
||||
this.importer = importer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
int x = (this.width - xSize) / 2;
|
||||
int y = (this.height - ySize) / 2;
|
||||
|
||||
buttonList.add(compareNBT = new GuiButton(0, x + 7, y + 40, 100, 20, "..."));
|
||||
buttonList.add(compareDamage = new GuiButton(1, x + 7, y + 64, 120, 20, "..."));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
||||
compareFlags = importer.getCompareFlags();
|
||||
|
||||
compareNBT.displayString = StatCollector.translateToLocal("misc.storagecraft:compareNBT") + ": ";
|
||||
compareNBT.displayString += ((compareFlags & InventoryUtils.COMPARE_NBT) == InventoryUtils.COMPARE_NBT) ? StatCollector.translateToLocal("misc.storagecraft:on") : StatCollector.translateToLocal("misc.storagecraft:off");
|
||||
|
||||
compareDamage.displayString = StatCollector.translateToLocal("misc.storagecraft:compareDamage") + ": ";
|
||||
compareDamage.displayString += ((compareFlags & InventoryUtils.COMPARE_DAMAGE) == InventoryUtils.COMPARE_DAMAGE) ? StatCollector.translateToLocal("misc.storagecraft:on") : StatCollector.translateToLocal("misc.storagecraft:off");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float renderPartialTicks, int mouseX, int mouseY) {
|
||||
GL11.glColor3f(1.0F, 1.0F, 1.0F);
|
||||
|
||||
mc.getTextureManager().bindTexture(IMPORTER_RESOURCE);
|
||||
|
||||
drawTexturedModalRect((this.width - xSize) / 2, (this.height - ySize) / 2, 0, 0, xSize, ySize);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
fontRendererObj.drawString(StatCollector.translateToLocal("gui.storagecraft:importer"), 7, 7, 4210752);
|
||||
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 7, 87, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
int flags = compareFlags;
|
||||
|
||||
switch (button.id) {
|
||||
case 0:
|
||||
flags ^= InventoryUtils.COMPARE_NBT;
|
||||
break;
|
||||
case 1:
|
||||
flags ^= InventoryUtils.COMPARE_DAMAGE;
|
||||
break;
|
||||
}
|
||||
|
||||
SC.NETWORK.sendToServer(new MessageImporterSettingsUpdate(importer.xCoord, importer.yCoord, importer.zCoord, flags));
|
||||
}
|
||||
}
|
17
src/main/java/storagecraft/inventory/ContainerImporter.java
Normal file
17
src/main/java/storagecraft/inventory/ContainerImporter.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package storagecraft.inventory;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import storagecraft.inventory.slot.SlotSpecimen;
|
||||
import storagecraft.tile.TileImporter;
|
||||
|
||||
public class ContainerImporter extends ContainerSC {
|
||||
public ContainerImporter(EntityPlayer player, TileImporter importer) {
|
||||
super(player);
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
addSlotToContainer(new SlotSpecimen(importer, i, 8 + (18 * i), 20));
|
||||
}
|
||||
|
||||
addPlayerInventory(8, 100);
|
||||
}
|
||||
}
|
11
src/main/java/storagecraft/inventory/slot/SlotSpecimen.java
Normal file
11
src/main/java/storagecraft/inventory/slot/SlotSpecimen.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package storagecraft.inventory.slot;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
|
||||
// @TODO: Correct behaviour
|
||||
public class SlotSpecimen extends Slot {
|
||||
public SlotSpecimen(IInventory inventory, int id, int x, int y) {
|
||||
super(inventory, id, x, y);
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
package storagecraft.network;
|
||||
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import storagecraft.tile.TileImporter;
|
||||
|
||||
public class MessageImporterSettingsUpdate implements IMessage, IMessageHandler<MessageImporterSettingsUpdate, IMessage> {
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
private int compareFlags;
|
||||
|
||||
public MessageImporterSettingsUpdate() {
|
||||
}
|
||||
|
||||
public MessageImporterSettingsUpdate(int x, int y, int z, int compareFlags) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.compareFlags = compareFlags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
compareFlags = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
buf.writeInt(compareFlags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(MessageImporterSettingsUpdate message, MessageContext context) {
|
||||
EntityPlayerMP player = context.getServerHandler().playerEntity;
|
||||
|
||||
TileEntity tile = player.worldObj.getTileEntity(message.x, message.y, message.z);
|
||||
|
||||
if (tile instanceof TileImporter) {
|
||||
((TileImporter) tile).setCompareFlags(message.compareFlags);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -10,6 +10,7 @@ import storagecraft.SC;
|
||||
import storagecraft.SCBlocks;
|
||||
import storagecraft.SCItems;
|
||||
import storagecraft.gui.GuiHandler;
|
||||
import storagecraft.network.MessageImporterSettingsUpdate;
|
||||
import storagecraft.network.MessagePullFromStorage;
|
||||
import storagecraft.network.MessagePushToStorage;
|
||||
import storagecraft.network.MessageTileUpdate;
|
||||
@@ -17,6 +18,7 @@ import storagecraft.tile.TileCable;
|
||||
import storagecraft.tile.TileController;
|
||||
import storagecraft.tile.TileDrive;
|
||||
import storagecraft.tile.TileGrid;
|
||||
import storagecraft.tile.TileImporter;
|
||||
import storagecraft.tile.TileStorageProxy;
|
||||
|
||||
public class CommonProxy {
|
||||
@@ -24,6 +26,7 @@ public class CommonProxy {
|
||||
SC.NETWORK.registerMessage(MessageTileUpdate.class, MessageTileUpdate.class, 0, Side.CLIENT);
|
||||
SC.NETWORK.registerMessage(MessagePushToStorage.class, MessagePushToStorage.class, 1, Side.SERVER);
|
||||
SC.NETWORK.registerMessage(MessagePullFromStorage.class, MessagePullFromStorage.class, 2, Side.SERVER);
|
||||
SC.NETWORK.registerMessage(MessageImporterSettingsUpdate.class, MessageImporterSettingsUpdate.class, 3, Side.SERVER);
|
||||
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(SC.INSTANCE, new GuiHandler());
|
||||
|
||||
@@ -32,12 +35,14 @@ public class CommonProxy {
|
||||
GameRegistry.registerTileEntity(TileGrid.class, "grid");
|
||||
GameRegistry.registerTileEntity(TileDrive.class, "drive");
|
||||
GameRegistry.registerTileEntity(TileStorageProxy.class, "storageProxy");
|
||||
GameRegistry.registerTileEntity(TileImporter.class, "importer");
|
||||
|
||||
GameRegistry.registerBlock(SCBlocks.CONTROLLER, "controller");
|
||||
GameRegistry.registerBlock(SCBlocks.CABLE, "cable");
|
||||
GameRegistry.registerBlock(SCBlocks.GRID, "grid");
|
||||
GameRegistry.registerBlock(SCBlocks.DRIVE, "drive");
|
||||
GameRegistry.registerBlock(SCBlocks.STORAGE_PROXY, "storageProxy");
|
||||
GameRegistry.registerBlock(SCBlocks.IMPORTER, "importer");
|
||||
|
||||
GameRegistry.registerItem(SCItems.STORAGE_CELL, "storageCell");
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ import storagecraft.inventory.InventorySC;
|
||||
import storagecraft.storage.CellStorage;
|
||||
import storagecraft.storage.IStorage;
|
||||
import storagecraft.storage.IStorageProvider;
|
||||
import storagecraft.util.InventoryUtil;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileDrive extends TileMachine implements IInventory, IStorageProvider {
|
||||
private InventorySC inventory = new InventorySC("drive", 8);
|
||||
@@ -91,14 +91,14 @@ public class TileDrive extends TileMachine implements IInventory, IStorageProvid
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
InventoryUtil.restoreInventory(this, nbt);
|
||||
InventoryUtils.restoreInventory(this, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
InventoryUtil.saveInventory(this, nbt);
|
||||
InventoryUtils.saveInventory(this, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
173
src/main/java/storagecraft/tile/TileImporter.java
Normal file
173
src/main/java/storagecraft/tile/TileImporter.java
Normal file
@@ -0,0 +1,173 @@
|
||||
package storagecraft.tile;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import storagecraft.inventory.InventorySC;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileImporter extends TileMachine implements IInventory {
|
||||
public static final int DEFAULT_COMPARE_FLAGS = InventoryUtils.COMPARE_NBT | InventoryUtils.COMPARE_DAMAGE;
|
||||
|
||||
private InventorySC inventory = new InventorySC("importer", 9);
|
||||
private IInventory connectedInventory;
|
||||
|
||||
private int compareFlags = DEFAULT_COMPARE_FLAGS;
|
||||
|
||||
private int currentSlot = 0;
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if (!worldObj.isRemote && isConnected()) {
|
||||
TileEntity tile = worldObj.getTileEntity(xCoord + getDirection().offsetX, yCoord + getDirection().offsetY, zCoord + getDirection().offsetZ);
|
||||
|
||||
if (tile instanceof IInventory) {
|
||||
connectedInventory = (IInventory) tile;
|
||||
}
|
||||
|
||||
if (connectedInventory != null) {
|
||||
if (ticks % 5 == 0) {
|
||||
ItemStack slot = connectedInventory.getStackInSlot(currentSlot);
|
||||
|
||||
if (slot != null && canImport(slot)) {
|
||||
if (getController().push(slot.copy())) {
|
||||
connectedInventory.setInventorySlotContents(currentSlot, null);
|
||||
}
|
||||
}
|
||||
|
||||
currentSlot++;
|
||||
|
||||
if (currentSlot > connectedInventory.getSizeInventory() - 1) {
|
||||
currentSlot = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
connectedInventory = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canImport(ItemStack stack) {
|
||||
int slots = 0;
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
||||
ItemStack slot = inventory.getStackInSlot(i);
|
||||
|
||||
if (slot != null) {
|
||||
slots++;
|
||||
|
||||
if (InventoryUtils.compareStack(slot, stack, compareFlags)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return slots == 0;
|
||||
}
|
||||
|
||||
public int getCompareFlags() {
|
||||
return compareFlags;
|
||||
}
|
||||
|
||||
public void setCompareFlags(int flags) {
|
||||
this.compareFlags = flags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyUsage() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return inventory.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return inventory.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int amount) {
|
||||
return inventory.decrStackSize(slot, amount);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int slot) {
|
||||
return inventory.getStackInSlotOnClosing(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack stack) {
|
||||
inventory.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName() {
|
||||
return inventory.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName() {
|
||||
return inventory.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
return inventory.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer player) {
|
||||
return inventory.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory() {
|
||||
inventory.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory() {
|
||||
inventory.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
||||
return inventory.isItemValidForSlot(slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
super.readFromNBT(nbt);
|
||||
|
||||
InventoryUtils.restoreInventory(this, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
||||
InventoryUtils.saveInventory(this, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
super.fromBytes(buf);
|
||||
|
||||
compareFlags = buf.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
super.toBytes(buf);
|
||||
|
||||
buf.writeInt(compareFlags);
|
||||
}
|
||||
}
|
@@ -7,7 +7,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import storagecraft.storage.IStorage;
|
||||
import storagecraft.storage.IStorageProvider;
|
||||
import storagecraft.storage.StorageItem;
|
||||
import storagecraft.util.InventoryUtil;
|
||||
import storagecraft.util.InventoryUtils;
|
||||
|
||||
public class TileStorageProxy extends TileMachine implements IStorageProvider, IStorage {
|
||||
private IInventory inventory;
|
||||
@@ -58,7 +58,7 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
||||
inventory.setInventorySlotContents(i, stack);
|
||||
|
||||
return;
|
||||
} else if (InventoryUtil.equalsIgnoreQuantity(slot, stack)) {
|
||||
} else if (InventoryUtils.compareStackNoQuantity(slot, stack)) {
|
||||
int toAdd = toGo;
|
||||
|
||||
if (slot.stackSize + toAdd > slot.getMaxStackSize()) {
|
||||
@@ -87,7 +87,7 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
||||
ItemStack slot = inventory.getStackInSlot(i);
|
||||
|
||||
if (slot != null && InventoryUtil.equalsIgnoreQuantity(slot, stack)) {
|
||||
if (slot != null && InventoryUtils.compareStackNoQuantity(slot, stack)) {
|
||||
if (quantity > slot.stackSize) {
|
||||
quantity = slot.stackSize;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class TileStorageProxy extends TileMachine implements IStorageProvider, I
|
||||
|
||||
if (slot == null) {
|
||||
return true;
|
||||
} else if (InventoryUtil.equalsIgnoreQuantity(slot, stack)) {
|
||||
} else if (InventoryUtils.compareStackNoQuantity(slot, stack)) {
|
||||
int toAdd = toGo;
|
||||
|
||||
if (slot.stackSize + toAdd > slot.getMaxStackSize()) {
|
||||
|
@@ -9,7 +9,14 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
public class InventoryUtil {
|
||||
public class InventoryUtils {
|
||||
public static final String NBT_INVENTORY = "Inventory";
|
||||
public static final String NBT_SLOT = "Slot";
|
||||
|
||||
public static final int COMPARE_DAMAGE = 1;
|
||||
public static final int COMPARE_NBT = 2;
|
||||
public static final int COMPARE_QUANTITY = 4;
|
||||
|
||||
public static void saveInventory(IInventory inventory, NBTTagCompound nbt) {
|
||||
NBTTagList tagList = new NBTTagList();
|
||||
|
||||
@@ -17,7 +24,7 @@ public class InventoryUtil {
|
||||
if (inventory.getStackInSlot(i) != null) {
|
||||
NBTTagCompound compoundTag = new NBTTagCompound();
|
||||
|
||||
compoundTag.setInteger("Slot", i);
|
||||
compoundTag.setInteger(NBT_SLOT, i);
|
||||
|
||||
inventory.getStackInSlot(i).writeToNBT(compoundTag);
|
||||
|
||||
@@ -25,15 +32,15 @@ public class InventoryUtil {
|
||||
}
|
||||
}
|
||||
|
||||
nbt.setTag("Inventory", tagList);
|
||||
nbt.setTag(NBT_INVENTORY, tagList);
|
||||
}
|
||||
|
||||
public static void restoreInventory(IInventory inventory, NBTTagCompound nbt) {
|
||||
if (nbt.hasKey("Inventory")) {
|
||||
NBTTagList tagList = nbt.getTagList("Inventory", Constants.NBT.TAG_COMPOUND);
|
||||
if (nbt.hasKey(NBT_INVENTORY)) {
|
||||
NBTTagList tagList = nbt.getTagList(NBT_INVENTORY, Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int i = 0; i < tagList.tagCount(); i++) {
|
||||
int slot = tagList.getCompoundTagAt(i).getInteger("Slot");
|
||||
int slot = tagList.getCompoundTagAt(i).getInteger(NBT_SLOT);
|
||||
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(tagList.getCompoundTagAt(i));
|
||||
|
||||
@@ -43,10 +50,10 @@ public class InventoryUtil {
|
||||
}
|
||||
|
||||
// https://github.com/cpw/ironchest/blob/master/src/main/java/cpw/mods/ironchest/BlockIronChest.java#L200
|
||||
public static void dropInventory(World world, IInventory inventory, int x, int y, int z, int newSize) {
|
||||
public static void dropInventory(World world, IInventory inventory, int x, int y, int z) {
|
||||
Random random = world.rand;
|
||||
|
||||
for (int i = newSize; i < inventory.getSizeInventory(); ++i) {
|
||||
for (int i = 0; i < inventory.getSizeInventory(); ++i) {
|
||||
ItemStack stack = inventory.getStackInSlot(i);
|
||||
|
||||
if (stack == null) {
|
||||
@@ -66,7 +73,7 @@ public class InventoryUtil {
|
||||
|
||||
stack.stackSize -= amount;
|
||||
|
||||
EntityItem entity = new EntityItem(world, (float) x + xo, (float) y + (newSize > 0 ? 1 : 0) + yo, (float) z + zo, new ItemStack(stack.getItem(), amount, stack.getItemDamage()));
|
||||
EntityItem entity = new EntityItem(world, (float) x + xo, (float) y + yo, (float) z + zo, new ItemStack(stack.getItem(), amount, stack.getItemDamage()));
|
||||
|
||||
entity.motionX = (float) random.nextGaussian() * 0.05F;
|
||||
entity.motionY = (float) random.nextGaussian() * 0.05F + 0.2F;
|
||||
@@ -81,11 +88,33 @@ public class InventoryUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean equalsIgnoreQuantity(ItemStack first, ItemStack second) {
|
||||
if (first.stackTagCompound != null && !first.stackTagCompound.equals(second.stackTagCompound)) {
|
||||
return false;
|
||||
public static boolean compareStackNoQuantity(ItemStack first, ItemStack second) {
|
||||
return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE);
|
||||
}
|
||||
|
||||
public static boolean compareStack(ItemStack first, ItemStack second) {
|
||||
return compareStack(first, second, COMPARE_NBT | COMPARE_DAMAGE | COMPARE_QUANTITY);
|
||||
}
|
||||
|
||||
public static boolean compareStack(ItemStack first, ItemStack second, int flags) {
|
||||
if ((flags & COMPARE_NBT) == COMPARE_NBT) {
|
||||
if (first.stackTagCompound != null && !first.stackTagCompound.equals(second.stackTagCompound)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return first.getItem() == second.getItem() && first.getItemDamage() == second.getItemDamage();
|
||||
if ((flags & COMPARE_DAMAGE) == COMPARE_DAMAGE) {
|
||||
if (first.getItemDamage() != second.getItemDamage()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ((flags & COMPARE_QUANTITY) == COMPARE_QUANTITY) {
|
||||
if (first.stackSize != second.stackSize) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return first.getItem() == second.getItem();
|
||||
}
|
||||
}
|
@@ -3,18 +3,26 @@ itemGroup.storagecraft=StorageCraft
|
||||
gui.storagecraft:controller=Controller
|
||||
gui.storagecraft:grid=Grid
|
||||
gui.storagecraft:drive=Drive
|
||||
gui.storagecraft:importer=Importer
|
||||
|
||||
misc.storagecraft:energyStored=%d / %d RF
|
||||
misc.storagecraft:energyUsage=Energy Usage: %d RF/t
|
||||
misc.storagecraft:energyUsage=Usage: %d RF/t
|
||||
|
||||
misc.storagecraft:storageCellStored=Stored: %d
|
||||
misc.storagecraft:storageCellStoredWithCapacity=Stored: %d / %d
|
||||
|
||||
misc.storagecraft:compareNBT=Compare NBT
|
||||
misc.storagecraft:compareDamage=Compare Damage
|
||||
|
||||
misc.storagecraft:on=On
|
||||
misc.storagecraft:off=Off
|
||||
|
||||
block.storagecraft:controller.name=Controller
|
||||
block.storagecraft:cable.name=Cable
|
||||
block.storagecraft:grid.name=Grid
|
||||
block.storagecraft:drive.name=Drive
|
||||
block.storagecraft:storageProxy.name=Storage Proxy
|
||||
block.storagecraft:importer.name=Importer
|
||||
|
||||
item.storagecraft:storageCell.0.name=1k Storage Cell
|
||||
item.storagecraft:storageCell.1.name=4k Storage Cell
|
||||
|
@@ -3,18 +3,26 @@ itemGroup.storagecraft=StorageCraft
|
||||
gui.storagecraft:controller=Controleur
|
||||
gui.storagecraft:grid=Rooster
|
||||
gui.storagecraft:drive=Schijf
|
||||
gui.storagecraft:importer=Importeur
|
||||
|
||||
misc.storagecraft:energyStored=%d / %d RF
|
||||
misc.storagecraft:energyUsage=Energie Verbruik: %d RF/t
|
||||
misc.storagecraft:energyUsage=Verbruik: %d RF/t
|
||||
|
||||
misc.storagecraft:storageCellStored=Opgeslagen: %d
|
||||
misc.storagecraft:storageCellStoredWithCapacity=Opgeslagen: %d / %d
|
||||
|
||||
misc.storagecraft:compareNBT=NBT vergelijken
|
||||
misc.storagecraft:compareDamage=Damage vergelijken
|
||||
|
||||
misc.storagecraft.on=Aan
|
||||
misc.storagecraft.off=Uit
|
||||
|
||||
block.storagecraft:controller.name=Controleur
|
||||
block.storagecraft:cable.name=Kabel
|
||||
block.storagecraft:grid.name=Rooster
|
||||
block.storagecraft:drive.name=Schijf
|
||||
block.storagecraft:storageProxy.name=Opslag Proxy
|
||||
block.storagecraft:importer.name=Importeur
|
||||
|
||||
item.storagecraft:storageCell.0.name=1k Opslagcel
|
||||
item.storagecraft:storageCell.1.name=4k Opslagcel
|
||||
|
BIN
src/main/resources/assets/storagecraft/textures/gui/exporter.png
Normal file
BIN
src/main/resources/assets/storagecraft/textures/gui/exporter.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
src/main/resources/assets/storagecraft/textures/gui/importer.png
Normal file
BIN
src/main/resources/assets/storagecraft/textures/gui/importer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
Reference in New Issue
Block a user