diff --git a/src/main/java/gregtech/api/capability/internal/IGregTechTileEntity.java b/src/main/java/gregtech/api/capability/internal/IGregTechTileEntity.java index 1f8eb3e8..fa11a6d7 100644 --- a/src/main/java/gregtech/api/capability/internal/IGregTechTileEntity.java +++ b/src/main/java/gregtech/api/capability/internal/IGregTechTileEntity.java @@ -11,7 +11,7 @@ import javax.annotation.Nullable; * Also delivers most of the Informations about my TileEntities. *
*/ -public interface IGregTechTileEntity extends IHasWorldObjectAndCoords { +public interface IGregTechTileEntity extends IHasWorldObjectAndCoords, IUIHolder { @Nullable IMetaTileEntity getMetaTileEntity(); diff --git a/src/main/java/gregtech/api/capability/internal/ISimpleFluidInventory.java b/src/main/java/gregtech/api/capability/internal/ISimpleFluidInventory.java new file mode 100644 index 00000000..79c64bd8 --- /dev/null +++ b/src/main/java/gregtech/api/capability/internal/ISimpleFluidInventory.java @@ -0,0 +1,18 @@ +package gregtech.api.capability.internal; + +import gregtech.api.gui.IUIHolder; +import net.minecraftforge.fluids.FluidStack; + +public interface ISimpleFluidInventory extends IUIHolder { + + int getTanksCount(); + int getTankCapacity(int tankIndex); + + /** + * @return a COPY of stack in slot. Actual stack won't change. + */ + FluidStack getFluidInTank(int tankIndex); + void setFluidInTank(int index, FluidStack fluidStack); + boolean isValidFluidTank(int tankIndex); + +} diff --git a/src/main/java/gregtech/api/capability/internal/ISimpleSlotInventory.java b/src/main/java/gregtech/api/capability/internal/ISimpleSlotInventory.java new file mode 100644 index 00000000..d90d98e7 --- /dev/null +++ b/src/main/java/gregtech/api/capability/internal/ISimpleSlotInventory.java @@ -0,0 +1,18 @@ +package gregtech.api.capability.internal; + +import gregtech.api.gui.IUIHolder; +import net.minecraft.item.ItemStack; + +public interface ISimpleSlotInventory extends IUIHolder { + + int getSlotsCount(); + int getMaxStackSize(int index); + + /** + * @return a COPY of stack in slot. Actual stack won't change. + */ + ItemStack getStackInSlot(int index); + void setStackInSlot(int index, ItemStack stack); + boolean isValidSlot(int index); + +} diff --git a/src/main/java/gregtech/api/gui/widgets/IInventoryWrapper.java b/src/main/java/gregtech/api/gui/widgets/IInventoryWrapper.java new file mode 100644 index 00000000..38ce8a4f --- /dev/null +++ b/src/main/java/gregtech/api/gui/widgets/IInventoryWrapper.java @@ -0,0 +1,132 @@ +package gregtech.api.gui.widgets; + +import gregtech.api.capability.internal.ISimpleSlotInventory; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.util.text.ITextComponent; +import net.minecraft.util.text.TextComponentString; + +import javax.annotation.Nullable; + +/** + * Just an IInventory wrapper to pass to Slot instances, + * since vanilla is too dumb to handle slots with null inventory properly + */ +public class IInventoryWrapper implements IInventory { + + public final ISimpleSlotInventory inventory; + + public IInventoryWrapper(ISimpleSlotInventory inventory) { + this.inventory = inventory; + } + + @Override + public int getSizeInventory() { + return inventory.getSlotsCount(); + } + + @Nullable + @Override + public ItemStack getStackInSlot(int index) { + return inventory.getStackInSlot(index); + } + + @Nullable + @Override + public ItemStack decrStackSize(int index, int count) { + ItemStack stackInSlot = inventory.getStackInSlot(index); + if(stackInSlot == null) { + return null; + } + ItemStack result = stackInSlot.splitStack(count); + inventory.setStackInSlot(index, stackInSlot); + return result; + } + + @Nullable + @Override + public ItemStack removeStackFromSlot(int index) { + ItemStack stack = inventory.getStackInSlot(index); + inventory.setStackInSlot(index, null); + return stack; + } + + @Override + public void setInventorySlotContents(int index, @Nullable ItemStack stack) { + inventory.setStackInSlot(index, stack); + } + + @Override + public void clear() { + for(int i = 0; i < inventory.getSlotsCount(); i++) { + inventory.setStackInSlot(i, null); + } + } + + @Override + public int getInventoryStackLimit() { + return 64; //Handled by Slot implementation + } + + @Override + public void markDirty() { + //Handled by ISimpleInventory implementation + } + + @Override + public boolean isUseableByPlayer(EntityPlayer player) { + return true; //Handled by ModularUI implementation + } + + @Override + public void openInventory(EntityPlayer player) { + //NOOP + } + + @Override + public void closeInventory(EntityPlayer player) { + //NOOP + } + + @Override + public boolean isItemValidForSlot(int index, ItemStack stack) { + return false; //Handled by ISimpleInventory implementation + } + + @Override + public int getField(int id) { + return 0; //NOOP + } + + @Override + public void setField(int id, int value) { + //NOOP + } + + @Override + public int getFieldCount() { + return 0; //NOOP + } + + @Override + public String getName() { + return ""; //Handled by ModularUI implementation + } + + @Override + public boolean hasCustomName() { + return false; //Handled by ModularUI implementation + } + + @Override + public ITextComponent getDisplayName() { + return new TextComponentString(""); //Handled by ModularUI implementation + } + + @Override + public boolean equals(Object obj) { + return obj instanceof IInventoryWrapper && ((IInventoryWrapper) obj).inventory == inventory; + } + +} diff --git a/src/main/java/gregtech/api/gui/widgets/SlotWidget.java b/src/main/java/gregtech/api/gui/widgets/SlotWidget.java new file mode 100644 index 00000000..c2d6fd71 --- /dev/null +++ b/src/main/java/gregtech/api/gui/widgets/SlotWidget.java @@ -0,0 +1,132 @@ +package gregtech.api.gui.widgets; + +import gregtech.api.capability.internal.ISimpleSlotInventory; +import gregtech.api.gui.INativeWidget; +import gregtech.api.gui.Widget; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.ClickType; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; + +import javax.annotation.Nullable; + +public abstract class SlotWidget extends Widget