diff --git a/build.gradle b/build.gradle index 0704164..35be699 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ dependencies { group = "io.github.elytra" archivesBaseName = "Thermionics" -version = "MC1.11.2_ver1.0.4" +version = "MC1.11.2_ver1.0.7" sourceCompatibility = 1.8 targetCompatibility = 1.8 diff --git a/src/main/java/com/elytradev/thermionics/data/ContainerTesting.java b/src/main/java/com/elytradev/concrete/gui/ConcreteContainer.java similarity index 55% rename from src/main/java/com/elytradev/thermionics/data/ContainerTesting.java rename to src/main/java/com/elytradev/concrete/gui/ConcreteContainer.java index 276a01e..c6f3d2c 100644 --- a/src/main/java/com/elytradev/thermionics/data/ContainerTesting.java +++ b/src/main/java/com/elytradev/concrete/gui/ConcreteContainer.java @@ -21,12 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.elytradev.thermionics.data; +package com.elytradev.concrete.gui; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import com.elytradev.thermionics.client.gui.GuiTesting; +import com.elytradev.concrete.inventory.ValidatedSlot; import com.elytradev.thermionics.gui.WPanel; import net.minecraft.entity.player.EntityPlayer; @@ -37,19 +37,19 @@ import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -public class ContainerTesting extends Container { +/** + * "Container" is Minecraft's way of managing shared state for a block whose GUI is currently open. + */ +public class ConcreteContainer extends Container { - private IInventory player; + private IInventory playerInventory; private IInventory container; private WPanel rootPanel; - public ContainerTesting(@Nonnull IInventory player, @Nullable IInventory container) { - this.player = player; + public ConcreteContainer(@Nonnull IInventory player, @Nullable IInventory container) { + this.playerInventory = player; this.container = container; - this.initPlayerInventory(GuiTesting.PADDING, GuiTesting.PADDING + (18*4)); - initContainerSlot(0, 2,1); - initContainerSlot(1, 6,1); } @Override @@ -60,19 +60,19 @@ public boolean canInteractWith(EntityPlayer playerIn) { public void initContainerSlot(int slot, int x, int y) { - this.addSlotToContainer(new SlotTesting(container, slot, x*18 + 6, y*18 + 6)); + this.addSlotToContainer(new ValidatedSlot(container, slot, x*18, y*18)); } public void initPlayerInventory(int x, int y) { for (int yi = 0; yi < 3; yi++) { for (int xi = 0; xi < 9; xi++) { - addSlotToContainer(new Slot(player, xi + (yi * 9) + 9, x + (xi * 18), y + (yi * 18))); + addSlotToContainer(new Slot(playerInventory, xi + (yi * 9) + 9, x + (xi * 18), y + (yi * 18))); } } for(int i=0; i<9; i++) { - addSlotToContainer(new Slot(player, i, x+(i*18), y + (3*18) + 4)); + addSlotToContainer(new Slot(playerInventory, i, x+(i*18), y + (3*18) + 4)); } } @@ -95,8 +95,59 @@ public void detectAndSendChanges() { public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) { - System.out.println("transferStackInSlot:"+index); - return super.transferStackInSlot(playerIn, index); + //System.out.println("transferStackInSlot:"+index); + + ItemStack srcStack = ItemStack.EMPTY; + Slot src = this.inventorySlots.get(index); + if (src != null && src.getHasStack()) { + srcStack = src.getStack(); + + if (src.inventory==playerInventory) { + //System.out.println("Transferring "+srcStack+" from playerInventory to container"); + //Try to push the stack from the player-inventory to the container-inventory. If that's not possible, + //try to move it between the non-hotbar-inventory and the hotbar-inventory + + ItemStack remaining = transferToInventory(srcStack, container); + //System.out.println("Remaining: "+remaining); + //this.detectAndSendChanges(); + src.putStack(remaining); + return ItemStack.EMPTY; + //return remaining; + + + } else { + //Try to push the stack from the container-inventory to the player-inventory. Prefer non-hotbar if possible + + //this.mergeItemStack(srcStack, 9, 27+9, false); + //Non-hotbar inventory + //System.out.println("Transferring "+srcStack+" from container to playerInventory"); + ItemStack remaining = transferToInventory(srcStack, playerInventory); + //System.out.println("Remaining: "+remaining); + //this.detectAndSendChanges(); + src.putStack(remaining); + return ItemStack.EMPTY; + //return remaining; + // + + /* + for(int i=9; i<27+9; i++) { + if (playerInventory.isItemValidForSlot(index, srcStack)) { + //playerInventory. + } + }*/ + } + } else { + //Shift-clicking on an invalid or empty slot does nothing. + } + + src.putStack(srcStack); + return ItemStack.EMPTY; + //return srcStack; + + + + + //return super.transferStackInSlot(playerIn, index); /* ItemStack itemstack = ItemStack.EMPTY; @@ -171,4 +222,61 @@ public WPanel getRootPanel() { return this.rootPanel; } + public ItemStack transferToInventory(ItemStack stack, IInventory inventory) { + ItemStack result = stack.copy(); + + + //Prefer dropping on top of existing stacks + for(Slot s : this.inventorySlots) { + if (s.inventory==inventory && s.isItemValid(result)) { + if (s.getHasStack()) { + ItemStack dest = s.getStack(); + + //If the two items can stack together and the existing stack can hold more items... + if (canStackTogether(result, dest) && dest.getCount()> 16 & 255) / 255.0F; + float g = (float)(color >> 8 & 255) / 255.0F; + float b = (float)(color & 255) / 255.0F; + Tessellator tessellator = Tessellator.getInstance(); + VertexBuffer vertexbuffer = tessellator.getBuffer(); + GlStateManager.enableBlend(); + GlStateManager.disableTexture2D(); + GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); + GlStateManager.color(r, g, b, 1.0f); + vertexbuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); //I thought GL_QUADS was deprecated but okay, sure. + vertexbuffer.pos(left, top+height, 0.0D).endVertex(); + vertexbuffer.pos(left+width, top+height, 0.0D).endVertex(); + vertexbuffer.pos(left+width, top, 0.0D).endVertex(); + vertexbuffer.pos(left, top, 0.0D).endVertex(); + tessellator.draw(); + GlStateManager.enableTexture2D(); + GlStateManager.disableBlend(); + } + + /** + * Draws a beveled, round rectangle that is substantially similar to default Minecraft UI panels. + */ + public static void drawGuiPanel(int x, int y, int width, int height) { + drawGuiPanel(x, y, width, height, 0x555555, 0xC6C6C6, 0xFFFFFF, 0x000000); + } + + + public static void drawGuiPanel(int x, int y, int width, int height, int shadow, int panel, int hilight, int outline) { + rect(x+3, y+3, width-6, height-6, panel); //Main panel area + + rect(x+2, y+1, width-4, 2, hilight); //Top hilight + rect(x+2, y+height-3, width-4, 2, shadow); //Bottom shadow + rect(x+1, y+2, 2, height-4, hilight); //Left hilight + rect(x+width-3, y+2, 2, height-4, shadow); //Right shadow + rect(x+width-3, y+2, 1, 1, panel); //Topright non-hilight/non-shadow transition pixel + rect(x+2, y+height-3, 1, 1, panel); //Bottomleft non-hilight/non-shadow transition pixel + rect(x+3, y+3, 1, 1, hilight); //Topleft round hilight pixel + rect(x+width-4, y+height-4, 1, 1, shadow); //Bottomright round shadow pixel + + rect(x+2, y, width-4, 1, outline); //Top outline + rect(x, y+2, 1, height-4, outline); //Left outline + rect(x+width-1, y+2, 1, height-4, outline); //Right outline + rect(x+2, y+height-1, width-4, 1, outline); //Bottom outline + rect(x+1, y+1, 1, 1, outline); //Topleft round pixel + rect(x+1, y+height-2, 1, 1, outline); //Bottomleft round pixel + rect(x+width-2, y+1, 1, 1, outline); //Topright round pixel + rect(x+width-2, y+height-2, 1, 1, outline); //Bottomright round pixel + } + + public static void drawItemSlot(int x, int y) { + rect(x, y, 18, 18, 0x8b8b8b); //Center panel + rect(x, y, 17, 1, 0x373737); //Top shadow + rect(x, y+1, 1, 16, 0x373737); //Left shadow + rect(x+17, y+1, 1, 17, 0xFFFFFF); //Right hilight + rect(x+1, y+17, 17, 1, 0xFFFFFF); //Bottom hilight + } + + public static void drawBigItemSlot(int x, int y) { + rect(x-4, y-4, 18+8, 18+8, 0x8b8b8b); //Center panel + rect(x-4, y-4, 17+8, 1-4, 0x373737); //Top shadow + rect(x-4, y+1-4, 1-4, 16+8, 0x373737); //Left shadow + rect(x+17+4, y+1-4, 1-4, 17+8, 0xFFFFFF); //Right hilight + rect(x+1-4, y+17+4, 17+8, 1-4, 0xFFFFFF); //Bottom hilight + } +} diff --git a/src/main/java/com/elytradev/thermionics/data/ObservableItemStorage.java b/src/main/java/com/elytradev/concrete/inventory/ConcreteItemStorage.java similarity index 51% rename from src/main/java/com/elytradev/thermionics/data/ObservableItemStorage.java rename to src/main/java/com/elytradev/concrete/inventory/ConcreteItemStorage.java index 61fde01..13d311f 100644 --- a/src/main/java/com/elytradev/thermionics/data/ObservableItemStorage.java +++ b/src/main/java/com/elytradev/concrete/inventory/ConcreteItemStorage.java @@ -21,30 +21,49 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.elytradev.thermionics.data; +package com.elytradev.concrete.inventory; import java.util.ArrayList; +import java.util.function.Predicate; import javax.annotation.Nonnull; +import javax.annotation.Nullable; -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 net.minecraftforge.items.ItemStackHandler; +import scala.actors.threadpool.Arrays; -public class ObservableItemStorage extends ItemStackHandler implements IInventory { +/** + * Base/internal class for managing item storage. Can be wrapped to create various kinds of filtered or validated + * IItemHandlers and IInventories. + */ +public class ConcreteItemStorage extends ItemStackHandler { private ArrayList listeners = new ArrayList<>(); + private ArrayList> validators = new ArrayList<>(); + private boolean[] extractMask; private String name = ""; - public ObservableItemStorage(int slots) { + public ConcreteItemStorage(int slots) { super(slots); + extractMask = new boolean[slots]; + Arrays.fill(extractMask, true); } - public ObservableItemStorage(int slots, String name) { - super(slots); + public final ConcreteItemStorage withName(String name) { this.name = name; + return this; + } + + @SafeVarargs + public final ConcreteItemStorage withValidators(Predicate... predicates) { + validators.clear(); + for(Predicate predicate : predicates) validators.add(predicate); + return this; + } + + public final ConcreteItemStorage setCanExtract(int index, boolean canExtract) { + if (indexslot; } - - @Override - public int getFieldCount() { - return 0; + + /** + * Returns a validator for the indicated slot if one is set, otherwise returns a validator which accepts anything. + */ + @Nonnull + public Predicate getValidator(int slot) { + if (validators.size()<=slot) return Validators.ANYTHING; + return validators.get(slot); } - - @Override - public void clear() { - for(int i=0; i getValidator(int index) { + return delegate.getValidator(index); + } } diff --git a/src/main/java/com/elytradev/thermionics/data/ValidatedItemStorageView.java b/src/main/java/com/elytradev/concrete/inventory/ValidatedItemHandlerView.java similarity index 81% rename from src/main/java/com/elytradev/thermionics/data/ValidatedItemStorageView.java rename to src/main/java/com/elytradev/concrete/inventory/ValidatedItemHandlerView.java index 126393c..541bf4b 100644 --- a/src/main/java/com/elytradev/thermionics/data/ValidatedItemStorageView.java +++ b/src/main/java/com/elytradev/concrete/inventory/ValidatedItemHandlerView.java @@ -21,25 +21,21 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.elytradev.thermionics.data; - -import java.util.function.BiFunction; +package com.elytradev.concrete.inventory; import net.minecraft.item.ItemStack; import net.minecraftforge.items.IItemHandler; -public class ValidatedItemStorageView implements IItemHandler { - private IItemHandler delegate; - private BiFunction validator; +public class ValidatedItemHandlerView implements IItemHandler { + private ConcreteItemStorage delegate; - public ValidatedItemStorageView(IItemHandler delegate, BiFunction validator) { + public ValidatedItemHandlerView(ConcreteItemStorage delegate) { this.delegate = delegate; - this.validator = validator; } @Override public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { - if (!validator.apply(slot, stack)) return stack; + if (!delegate.getValidator(slot).test(stack)) return stack; else return delegate.insertItem(slot, stack, simulate); } @@ -55,6 +51,7 @@ public ItemStack getStackInSlot(int slot) { @Override public ItemStack extractItem(int slot, int amount, boolean simulate) { + if (!delegate.getCanExtract(slot)) return ItemStack.EMPTY; return delegate.extractItem(slot, amount, simulate); } diff --git a/src/main/java/com/elytradev/thermionics/data/MachineItemStorageView.java b/src/main/java/com/elytradev/concrete/inventory/ValidatedSlot.java similarity index 50% rename from src/main/java/com/elytradev/thermionics/data/MachineItemStorageView.java rename to src/main/java/com/elytradev/concrete/inventory/ValidatedSlot.java index f5d373c..3b27077 100644 --- a/src/main/java/com/elytradev/thermionics/data/MachineItemStorageView.java +++ b/src/main/java/com/elytradev/concrete/inventory/ValidatedSlot.java @@ -21,47 +21,27 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package com.elytradev.thermionics.data; - -import org.apache.commons.lang3.Validate; +package com.elytradev.concrete.inventory; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import net.minecraftforge.items.IItemHandler; -public class MachineItemStorageView implements IItemHandler { - public static final int SLOT_MACHINE_INPUT = 0; - public static final int SLOT_MACHINE_OUTPUT = 1; - private final IItemHandler delegate; - - public MachineItemStorageView(IItemHandler delegate) { - Validate.isTrue(delegate.getSlots()>=2, "Cannot create a machine storage view of an inventory with less than 2 slots."); - this.delegate = delegate; - } - - @Override - public int getSlots() { - return delegate.getSlots(); - } - - @Override - public ItemStack getStackInSlot(int slot) { - return delegate.getStackInSlot(slot); - } - - @Override - public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) { - if (slot==SLOT_MACHINE_INPUT) return delegate.insertItem(slot, stack, simulate); - else return stack; - } +/** + * The heavyweight peer used by ConcreteContainer to respect the predicates for validated inventories. + */ +public class ValidatedSlot extends Slot { - @Override - public ItemStack extractItem(int slot, int amount, boolean simulate) { - if (slot==SLOT_MACHINE_OUTPUT) return delegate.extractItem(slot, amount, simulate); - else return ItemStack.EMPTY; + public ValidatedSlot(IInventory inventoryIn, int index, int xPosition, int yPosition) { + super(inventoryIn, index, xPosition, yPosition); } - + @Override - public int getSlotLimit(int slot) { - return delegate.getSlotLimit(slot); + public boolean isItemValid(ItemStack stack) { + if (inventory instanceof ValidatedInventoryView) { + return ((ValidatedInventoryView) inventory).getValidator(getSlotIndex()).test(stack); + } else { + return super.isItemValid(stack); + } } } diff --git a/src/main/java/com/elytradev/concrete/inventory/Validators.java b/src/main/java/com/elytradev/concrete/inventory/Validators.java new file mode 100644 index 0000000..5385323 --- /dev/null +++ b/src/main/java/com/elytradev/concrete/inventory/Validators.java @@ -0,0 +1,20 @@ +package com.elytradev.concrete.inventory; + +import java.util.function.Predicate; + +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.FurnaceRecipes; +import net.minecraft.tileentity.TileEntityFurnace; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; + +public class Validators { + public static final Predicate ANYTHING = (it)->true; + public static final Predicate NOTHING = (it)->false; + public static final Predicate FURNACE_FUELS = TileEntityFurnace::isItemFuel; //This is actually the most correct/accurate way to read the furnace registry! + public static final Predicate SMELTABLE = (it)->{ + return !FurnaceRecipes.instance().getSmeltingResult(it).isEmpty(); + }; + public static final Predicate FLUID_CONTAINERS = (it)->{ + return it.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); + }; +} diff --git a/src/main/java/com/elytradev/thermionics/Thermionics.java b/src/main/java/com/elytradev/thermionics/Thermionics.java index f4c4f02..9d7a1ad 100644 --- a/src/main/java/com/elytradev/thermionics/Thermionics.java +++ b/src/main/java/com/elytradev/thermionics/Thermionics.java @@ -26,6 +26,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import com.elytradev.concrete.gui.ConcreteContainer; +import com.elytradev.concrete.inventory.IContainerInventoryHolder; import com.elytradev.thermionics.api.IHeatStorage; import com.elytradev.thermionics.api.IRotaryPower; import com.elytradev.thermionics.api.ISignalStorage; @@ -47,10 +49,10 @@ import com.elytradev.thermionics.block.BlockRoad; import com.elytradev.thermionics.block.BlockScaffold; import com.elytradev.thermionics.block.ThermionicsBlocks; -import com.elytradev.thermionics.client.gui.GuiTesting; -import com.elytradev.thermionics.data.ContainerInventoryHolder; -import com.elytradev.thermionics.data.ContainerTesting; +import com.elytradev.thermionics.client.gui.ConcreteGui; import com.elytradev.thermionics.data.ProbeDataSupport; +import com.elytradev.thermionics.gui.ContainerFirebox; +import com.elytradev.thermionics.gui.ContainerOven; import com.elytradev.thermionics.item.ItemBlockBattery; import com.elytradev.thermionics.item.ItemBlockEquivalentState; import com.elytradev.thermionics.item.ItemHammer; @@ -73,6 +75,7 @@ import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.Item.ToolMaterial; import net.minecraft.item.ItemBlock; @@ -210,13 +213,24 @@ public void onPreInit(FMLPreInitializationEvent e) { GameRegistry.registerTileEntity(TileEntityConvectionMotor.class, "thermionics:machine.convectionmotor"); //GameRegistry.registerTileEntity(TileEntityCableSignal.class, "thermionics:cable.redstone"); - NetworkRegistry.INSTANCE.registerGuiHandler(this, new IGuiHandler(){ + NetworkRegistry.INSTANCE.registerGuiHandler(this, new IGuiHandler() { + private ConcreteContainer getContainer(int id, IInventory player, IInventory tile) { + switch(id) { + case ContainerFirebox.ID: + default: + return new ContainerFirebox(player, tile); + case ContainerOven.ID: + return new ContainerOven(player, tile); + } + } + @Override - public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { TileEntity te = world.getTileEntity(new BlockPos(x,y,z)); - if (te!=null && (te instanceof ContainerInventoryHolder)) { - return new ContainerTesting(player.inventory, ((ContainerInventoryHolder)te).getContainerInventory()); + if (te!=null && (te instanceof IContainerInventoryHolder)) { + return getContainer(id, player.inventory, ((IContainerInventoryHolder)te).getContainerInventory()); + //return new ConcreteContainer(player.inventory, ((IContainerInventoryHolder)te).getContainerInventory()); } System.out.println("NULL SERVER ELEMENT."); @@ -224,16 +238,15 @@ public Object getServerGuiElement(int ID, EntityPlayer player, World world, int } @Override - public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { + public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) { TileEntity te = world.getTileEntity(new BlockPos(x,y,z)); - Container container = null; - if (te!=null && (te instanceof ContainerInventoryHolder)) { - container = new ContainerTesting(player.inventory, ((ContainerInventoryHolder)te).getContainerInventory()); - } else { - System.out.println("NULL CLIENT ELEMENT"); + ConcreteContainer container = null; + if (te!=null && (te instanceof IContainerInventoryHolder)) { + container = getContainer(id, player.inventory, ((IContainerInventoryHolder)te).getContainerInventory()); + //container = new ConcreteContainer(player.inventory, ((IContainerInventoryHolder)te).getContainerInventory()); } - return new GuiTesting(player.inventory, container,"CLIENT"); + return new ConcreteGui(player.inventory, container); } }); @@ -348,9 +361,9 @@ public void registerItem(Item item) { proxy.registerItemModel(item); } - public void registerCraftingCircle(Block block) { + public void registerCraftingCircle(BlockBase block) { NonNullList variants = NonNullList.create(); - block.getSubBlocks(ItemBlock.getItemFromBlock(block), Thermionics.TAB_THERMIONICS, variants); + block.getVariants(ItemBlock.getItemFromBlock(block), variants); ItemStack first = variants.remove(0); ItemStack prev = first; for(ItemStack item : variants) { diff --git a/src/main/java/com/elytradev/thermionics/block/BlockBase.java b/src/main/java/com/elytradev/thermionics/block/BlockBase.java index ee32d6c..db89d7f 100644 --- a/src/main/java/com/elytradev/thermionics/block/BlockBase.java +++ b/src/main/java/com/elytradev/thermionics/block/BlockBase.java @@ -26,6 +26,9 @@ import net.minecraft.block.Block; import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.util.NonNullList; public abstract class BlockBase extends Block { @@ -37,4 +40,8 @@ public BlockBase(Material material, MapColor mapColor) { super(material, mapColor); } + public void getVariants(Item item, NonNullList variants) { + variants.add(new ItemStack(item)); + } + } diff --git a/src/main/java/com/elytradev/thermionics/block/BlockFirebox.java b/src/main/java/com/elytradev/thermionics/block/BlockFirebox.java index a8a0d16..48b51d1 100644 --- a/src/main/java/com/elytradev/thermionics/block/BlockFirebox.java +++ b/src/main/java/com/elytradev/thermionics/block/BlockFirebox.java @@ -24,6 +24,7 @@ package com.elytradev.thermionics.block; import com.elytradev.thermionics.Thermionics; +import com.elytradev.thermionics.gui.ContainerFirebox; import com.elytradev.thermionics.tileentity.TileEntityFirebox; import net.minecraft.block.ITileEntityProvider; @@ -50,7 +51,7 @@ public TileEntity createNewTileEntity(World worldIn, int meta) { @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (!world.isRemote) { - player.openGui(Thermionics.instance(), 0, world, pos.getX(), pos.getY(), pos.getZ()); + player.openGui(Thermionics.instance(), ContainerFirebox.ID, world, pos.getX(), pos.getY(), pos.getZ()); } else { } diff --git a/src/main/java/com/elytradev/thermionics/block/BlockOven.java b/src/main/java/com/elytradev/thermionics/block/BlockOven.java index 202391b..91e8ad9 100644 --- a/src/main/java/com/elytradev/thermionics/block/BlockOven.java +++ b/src/main/java/com/elytradev/thermionics/block/BlockOven.java @@ -23,10 +23,17 @@ */ package com.elytradev.thermionics.block; +import com.elytradev.thermionics.Thermionics; +import com.elytradev.thermionics.gui.ContainerOven; import com.elytradev.thermionics.tileentity.TileEntityOven; import net.minecraft.block.ITileEntityProvider; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class BlockOven extends BlockMachineBase implements ITileEntityProvider { @@ -40,4 +47,14 @@ public BlockOven() { public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityOven(); } + + @Override + public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { + if (!world.isRemote) { + player.openGui(Thermionics.instance(), ContainerOven.ID, world, pos.getX(), pos.getY(), pos.getZ()); + } else { + + } + return true; + } } diff --git a/src/main/java/com/elytradev/thermionics/block/BlockRoad.java b/src/main/java/com/elytradev/thermionics/block/BlockRoad.java index 4a75d59..058a43f 100644 --- a/src/main/java/com/elytradev/thermionics/block/BlockRoad.java +++ b/src/main/java/com/elytradev/thermionics/block/BlockRoad.java @@ -89,8 +89,13 @@ public void onEntityWalk(World world, BlockPos pos, Entity entity) { @Override public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList list) { + getVariants(itemIn, list); + } + + @Override + public void getVariants(Item item, NonNullList variants) { for(int i : VARIANT.getAllowedValues()) { - list.add(new ItemStack(itemIn, 1, i)); + variants.add(new ItemStack(item, 1, i)); } } } diff --git a/src/main/java/com/elytradev/thermionics/client/gui/ConcreteGui.java b/src/main/java/com/elytradev/thermionics/client/gui/ConcreteGui.java new file mode 100644 index 0000000..84f4749 --- /dev/null +++ b/src/main/java/com/elytradev/thermionics/client/gui/ConcreteGui.java @@ -0,0 +1,220 @@ +/** + * MIT License + * + * Copyright (c) 2017 Isaac Ellingson (Falkreon) and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.elytradev.thermionics.client.gui; + +import java.io.IOException; + +import com.elytradev.concrete.gui.ConcreteContainer; +import com.elytradev.concrete.gui.GuiDrawing; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.Slot; + +public class ConcreteGui extends GuiContainer { + public static final int PADDING = 8; + private ConcreteContainer container; + + //private IInventory playerInv; + + public ConcreteGui(InventoryPlayer playerInv, ConcreteContainer container) { + super(container); + this.container = container; + this.xSize = 18*9; + this.ySize = 18*8 + 6; + //this.playerInv = playerInv; + } + + /* + * RENDERING NOTES: + * + * * "width" and "height" are the width and height of the overall screen + * * "xSize" and "ySize" are the width and height of the panel to render + * * "left" and "top" are *actually* self-explanatory + * * coordinates start at 0,0 at the topleft of the screen. + */ + + //@Override + //public void drawScreen(int mouseX, int mouseY, float partialTicks) { + //} + + + /* + * These methods are called frequently and empty, meaning they're probably *meant* for subclasses to override to + * provide core GUI functionality. + */ + + @Override + public void initGui() { + //System.out.println("initGui"); + super.initGui(); + } + + //Will probably re-activate for animation! + //@Override + //public void updateScreen() { + // System.out.println("updateScreen"); + //} + + @Override + public void onGuiClosed() { + //System.out.println("onGuiClosed"); + super.onGuiClosed(); + } + + @Override + public boolean doesGuiPauseGame() { + //...yeah, we're going to go ahead and override that. + return false; + } + + /* + * While these methods are implemented in GuiScreen, chances are we'll be shadowing a lot of the GuiScreen methods + * in order to implement our own button protocol and more advanced features. + */ + + @Override + protected void keyTyped(char typedChar, int keyCode) throws IOException { + //System.out.println("keyTyped:"+Integer.toHexString(keyCode)+" ("+typedChar+")"); + if (typedChar=='e') { + this.mc.player.closeScreen(); + return; + } + super.keyTyped(typedChar, keyCode); + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + super.mouseClicked(mouseX, mouseY, mouseButton); + } + + + @Override + protected void mouseReleased(int mouseX, int mouseY, int state) { + super.mouseReleased(mouseX, mouseY, state); + } + + @Override + protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { + super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); + } + + @Override + protected void actionPerformed(GuiButton button) throws IOException { + super.actionPerformed(button); + } + + /* + * We'll probably wind up calling some of this manually, but they do useful things for us so we may leave + * them unharmed. + */ + + @Override + public void setWorldAndResolution(Minecraft mc, int width, int height) { + super.setWorldAndResolution(mc, width, height); + //System.out.println("setWorldAndResolution:"+width+"x"+height); + + guiLeft = (width / 2) - (xSize / 2); + guiTop = (height / 2) - (ySize / 2); + + } + + @Override + public void setGuiSize(int w, int h) { + super.setGuiSize(w, h); + //System.out.println("setGuiSize:"+w+"x"+h); + guiLeft = (width / 2) - (xSize / 2); + guiTop = (height / 2) - (ySize / 2); + + } + + /* (default impl calls setWorldAndResolution so we're good here.) + public void onResize(Minecraft mcIn, int w, int h) { + super.onResize(mcIn, w, h); + }*/ + + /* + * The following methods seem to be internal delegation tools; they poll the LWJGL Mouse and Keyboard objects, fire + * Forge events, and generally invisibly handle things for you that you Want Invisibly Handled. Chances are we won't + * be messing with these *at all* since they're some of the very few things in guis that work the way they should. + */ + /* + @Override + public void handleInput() throws IOException { + System.out.println("handleInput"); + super.handleInput(); + } + + @Override + public void handleMouseInput() throws IOException { + System.out.println("handleMouseInput"); + super.handleMouseInput(); + } + + @Override + public void handleKeyboardInput() throws IOException { + System.out.println("handleKeyboardInput"); + super.handleKeyboardInput(); + }*/ + + /* + * SPECIAL FUNCTIONS: Where possible, we want to draw everything based on *actual GUI state and composition* rather + * than relying on pre-baked textures that the programmer then needs to carefully match up their GUI to. + */ + + @Override + protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { + + //drawDefaultBackground(); + + GuiDrawing.drawGuiPanel(guiLeft-PADDING, guiTop-PADDING, xSize+((PADDING-1)*2), ySize+((PADDING-1)*2)); + //fontRenderer.drawString("Firebox", left+PADDING, top+PADDING, 0xFF404040); + + if (inventorySlots!=null) { + //RenderHelper.enableGUIStandardItemLighting(); + //GlStateManager.enableRescaleNormal(); + //OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F); + + for(Slot slot : inventorySlots.inventorySlots) { + GuiDrawing.drawItemSlot(guiLeft+slot.xPos-1, guiTop+slot.yPos-1); + + //itemRender.renderItemAndEffectIntoGUI(this.mc.player, slot.getStack(), left+slot.xPos+1, top+slot.yPos+1); + //slot.xPos + } + + //GlStateManager.disableRescaleNormal(); + //RenderHelper.disableStandardItemLighting(); + } + + fontRenderer.drawString(container.getLocalizedName(), guiLeft, guiTop, 0xFF404040); + //drawItemSlot(left+PADDING, top+PADDING+18); + //drawItemSlot(left+PADDING+18, top+PADDING+18); + //drawItemSlot(left+PADDING, top+PADDING+18+18); + + } +} diff --git a/src/main/java/com/elytradev/thermionics/client/gui/GuiTesting.java b/src/main/java/com/elytradev/thermionics/client/gui/GuiTesting.java deleted file mode 100644 index dd9f161..0000000 --- a/src/main/java/com/elytradev/thermionics/client/gui/GuiTesting.java +++ /dev/null @@ -1,741 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2017 Isaac Ellingson (Falkreon) and contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.elytradev.thermionics.client.gui; - -import java.io.IOException; - -import org.lwjgl.input.Keyboard; -import org.lwjgl.opengl.GL11; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.GuiButton; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.OpenGlHelper; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.Tessellator; -import net.minecraft.client.renderer.VertexBuffer; -import net.minecraft.client.renderer.vertex.DefaultVertexFormats; -import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.ClickType; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -public class GuiTesting extends GuiContainer { - public static final int PADDING = 6; - private IInventory playerInv; - private String debugName; - //private Container inventorySlotsIn; - //private int guiLeft = 0; - //private int guiTop = 0; - //private int xSize = 200; - //private int ySize = 200; - - public GuiTesting(InventoryPlayer playerInv, Container container, String debugName) { - super(container); - System.out.println("Init:"+debugName); - this.debugName = debugName; - this.playerInv = playerInv; - - //this.inventorySlotsIn = container; - } - - /* - @Override - protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { - System.out.println("DrawBackgroundLayer!"); - GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - this.mc.getTextureManager().bindTexture(FURNACE_GUI_TEXTURES); - int i = (this.width - this.xSize) / 2; - int j = (this.height - this.ySize) / 2; - //int i = -150; - //int j = -150; - this.drawTexturedModalRect(i, j, 0, 0, this.xSize, this.ySize); - - //if (TileEntityFurnace.isBurning(this.tileFurnace)) - //{ - //int k = 0;//this.getBurnLeftScaled(13); - //this.drawTexturedModalRect(i + 56, j + 36 + 12 - k, 176, 12 - k, 14, k + 1); - // } - - int l = 0;//this.getCookProgressScaled(24); - this.drawTexturedModalRect(i + 79, j + 34, 176, 14, l + 1, 16); - }*/ - - - /* - * RENDERING NOTES: - * - * * "width" and "height" are the width and height of the overall screen - * * "xSize" and "ySize" are the width and height of the panel to render - * * "left" and "top" are *actually* self-explanatory - * * coordinates start at 0,0 at the topleft of the screen. - */ - - //@Override - //public void drawScreen(int mouseX, int mouseY, float partialTicks) { - //} - - - /* - * These methods are called frequently and empty, meaning they're probably *meant* for subclasses to override to - * provide core GUI functionality. - */ - - @Override - public void initGui() { - System.out.println("initGui"); - super.initGui(); - } - - //@Override - //public void updateScreen() { - // System.out.println("updateScreen"); - //} - - @Override - public void onGuiClosed() { - System.out.println("onGuiClosed"); - super.onGuiClosed(); - } - - @Override - public boolean doesGuiPauseGame() { - //...yeah, we're going to go ahead and override that. - return false; - } - - /* - * While these methods are implemented in GuiScreen, chances are we'll be shadowing a lot of the GuiScreen methods - * in order to implement our own button protocol and more advanced features. - */ - - @Override - protected void keyTyped(char typedChar, int keyCode) throws IOException { - System.out.println("keyTyped:"+Integer.toHexString(keyCode)+" ("+typedChar+")"); - if (typedChar=='e') { - this.mc.player.closeScreen(); - return; - } - super.keyTyped(typedChar, keyCode); - } - - - /* - * The following two methods are verbatim from GuiContainer so we can triage bugs - */ - /* - private boolean isMouseOverSlot(Slot slotIn, int mouseX, int mouseY) { - return this.isPointInRegion(slotIn.xPos, slotIn.yPos, 16, 16, mouseX, mouseY); - } - - private Slot getSlotAtPosition(int x, int y) { - for (int i = 0; i < this.inventorySlots.inventorySlots.size(); ++i) { - Slot slot = (Slot)this.inventorySlots.inventorySlots.get(i); - - if (this.isMouseOverSlot(slot, x, y) && slot.canBeHovered()) { - return slot; - } - } - - return null; - }*/ - - /* Shadowed fields lifted from superclass. Hopefully this'll let us clean some code up */ - /* - boolean doubleClick = false; - boolean ignoreMouseUp = false; - boolean isRightMouseClick = false; - - Slot clickedSlot = null; - Slot currentDragTargetSlot = null; - Slot lastClickSlot = null; - Slot returningStackDestSlot = null; - - long lastClickTime = 0L; - long dragItemDropDelay = 0L; - long returningStackTime = 0L; - - int lastClickButton = 0; - int dragSplittingButton = 0; - int dragSplittingLimit = 0; - int dragSplittingRemnant = 0; - int touchUpX = 0; - int touchUpY = 0; - - ItemStack shiftClickedSlot = ItemStack.EMPTY; - ItemStack draggedStack = ItemStack.EMPTY; - ItemStack returningStack = ItemStack.EMPTY;*/ - /* - protected void superMouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - super.mouseClicked(mouseX, mouseY, mouseButton); - boolean flag = this.mc.gameSettings.keyBindPickBlock.isActiveAndMatches(mouseButton - 100); - Slot slot = this.getSlotAtPosition(mouseX, mouseY); - long i = Minecraft.getSystemTime(); - this.doubleClick = this.lastClickSlot == slot && i - this.lastClickTime < 250L && this.lastClickButton == mouseButton; - this.ignoreMouseUp = false; - - if (mouseButton == 0 || mouseButton == 1 || flag) { - int j = this.guiLeft; - int k = this.guiTop; - boolean flag1 = mouseX < j || mouseY < k || mouseX >= j + this.xSize || mouseY >= k + this.ySize; - if (slot != null) flag1 = false; // Forge, prevent dropping of items through slots outside of GUI boundaries - int l = -1; - - if (slot != null) { - l = slot.slotNumber; - } - - if (flag1) { - l = -999; - } - - if (this.mc.gameSettings.touchscreen && flag1 && this.mc.player.inventory.getItemStack().isEmpty()) { - this.mc.displayGuiScreen((GuiScreen)null); - return; - } - - if (l != -1) { - if (this.mc.gameSettings.touchscreen) { - if (slot != null && slot.getHasStack()) { - this.clickedSlot = slot; - this.draggedStack = ItemStack.EMPTY; - this.isRightMouseClick = mouseButton == 1; - } else { - this.clickedSlot = null; - } - } else if (!this.dragSplitting) { - if (this.mc.player.inventory.getItemStack().isEmpty()) { - if (this.mc.gameSettings.keyBindPickBlock.isActiveAndMatches(mouseButton - 100)) { - this.handleMouseClick(slot, l, mouseButton, ClickType.CLONE); - } else { - boolean flag2 = l != -999 && (Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54)); - ClickType clicktype = ClickType.PICKUP; - - if (flag2) - { - this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack().copy() : ItemStack.EMPTY; - clicktype = ClickType.QUICK_MOVE; - } - else if (l == -999) - { - clicktype = ClickType.THROW; - } - - this.handleMouseClick(slot, l, mouseButton, clicktype); - } - - this.ignoreMouseUp = true; - } - else - { - this.dragSplitting = true; - this.dragSplittingButton = mouseButton; - this.dragSplittingSlots.clear(); - - if (mouseButton == 0) - { - this.dragSplittingLimit = 0; - } - else if (mouseButton == 1) - { - this.dragSplittingLimit = 1; - } - else if (this.mc.gameSettings.keyBindPickBlock.isActiveAndMatches(mouseButton - 100)) - { - this.dragSplittingLimit = 2; - } - } - } - } - } - - this.lastClickSlot = slot; - this.lastClickTime = i; - this.lastClickButton = mouseButton; - }*/ - - - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - //Slot slot = this.getSlotAtPosition(mouseX, mouseY); - //System.out.println("mouseClicked:"+mouseX+","+mouseY+" button:"+mouseButton+" slot:"+((slot==null)?"none":slot.getSlotIndex()+"("+slot.getStack().getDisplayName()+")")); - System.out.println("mouseClicked:"+mouseX+","+mouseY+" button:"+mouseButton); - //superMouseClicked(mouseX, mouseY, mouseButton); - - - super.mouseClicked(mouseX, mouseY, mouseButton); - } - /* - protected void superMouseReleased(int mouseX, int mouseY, int state) { - //GuiScreen::mouseReleased(mouseX, mouseY, state); //Forge, Call parent to release buttons - //TODO: Manually release buttons - - Slot slot = this.getSlotAtPosition(mouseX, mouseY); - int i = this.guiLeft; - int j = this.guiTop; - boolean flag = mouseX < i || mouseY < j || mouseX >= i + this.xSize || mouseY >= j + this.ySize; - if (slot != null) flag = false; // Forge, prevent dropping of items through slots outside of GUI boundaries - int k = -1; - - if (slot != null) - { - k = slot.slotNumber; - } - - if (flag) - { - k = -999; - } - - if (this.doubleClick && slot != null && state == 0 && this.inventorySlots.canMergeSlot(ItemStack.EMPTY, slot)) - { - if (isShiftKeyDown()) - { - if (!this.shiftClickedSlot.isEmpty()) - { - for (Slot slot2 : this.inventorySlots.inventorySlots) - { - if (slot2 != null && slot2.canTakeStack(this.mc.player) && slot2.getHasStack() && slot2.isSameInventory(slot) && Container.canAddItemToSlot(slot2, this.shiftClickedSlot, true)) - { - this.handleMouseClick(slot2, slot2.slotNumber, state, ClickType.QUICK_MOVE); - } - } - } - } - else - { - this.handleMouseClick(slot, k, state, ClickType.PICKUP_ALL); - } - - this.doubleClick = false; - this.lastClickTime = 0L; - } - else - { - if (this.dragSplitting && this.dragSplittingButton != state) - { - this.dragSplitting = false; - this.dragSplittingSlots.clear(); - this.ignoreMouseUp = true; - return; - } - - if (this.ignoreMouseUp) - { - this.ignoreMouseUp = false; - return; - } - - if (this.clickedSlot != null && this.mc.gameSettings.touchscreen) - { - if (state == 0 || state == 1) - { - if (this.draggedStack.isEmpty() && slot != this.clickedSlot) - { - this.draggedStack = this.clickedSlot.getStack(); - } - - boolean flag2 = Container.canAddItemToSlot(slot, this.draggedStack, false); - - if (k != -1 && !this.draggedStack.isEmpty() && flag2) - { - this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, state, ClickType.PICKUP); - this.handleMouseClick(slot, k, 0, ClickType.PICKUP); - - if (this.mc.player.inventory.getItemStack().isEmpty()) - { - this.returningStack = ItemStack.EMPTY; - } - else - { - this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, state, ClickType.PICKUP); - this.touchUpX = mouseX - i; - this.touchUpY = mouseY - j; - this.returningStackDestSlot = this.clickedSlot; - this.returningStack = this.draggedStack; - this.returningStackTime = Minecraft.getSystemTime(); - } - } - else if (!this.draggedStack.isEmpty()) - { - this.touchUpX = mouseX - i; - this.touchUpY = mouseY - j; - this.returningStackDestSlot = this.clickedSlot; - this.returningStack = this.draggedStack; - this.returningStackTime = Minecraft.getSystemTime(); - } - - this.draggedStack = ItemStack.EMPTY; - this.clickedSlot = null; - } - } - else if (this.dragSplitting && !this.dragSplittingSlots.isEmpty()) - { - this.handleMouseClick((Slot)null, -999, Container.getQuickcraftMask(0, this.dragSplittingLimit), ClickType.QUICK_CRAFT); - - for (Slot slot1 : this.dragSplittingSlots) - { - this.handleMouseClick(slot1, slot1.slotNumber, Container.getQuickcraftMask(1, this.dragSplittingLimit), ClickType.QUICK_CRAFT); - } - - this.handleMouseClick((Slot)null, -999, Container.getQuickcraftMask(2, this.dragSplittingLimit), ClickType.QUICK_CRAFT); - } - else if (!this.mc.player.inventory.getItemStack().isEmpty()) - { - if (this.mc.gameSettings.keyBindPickBlock.isActiveAndMatches(state - 100)) - { - this.handleMouseClick(slot, k, state, ClickType.CLONE); - } - else - { - boolean flag1 = k != -999 && (Keyboard.isKeyDown(42) || Keyboard.isKeyDown(54)); - - if (flag1) - { - this.shiftClickedSlot = slot != null && slot.getHasStack() ? slot.getStack().copy() : ItemStack.EMPTY; - } - - this.handleMouseClick(slot, k, state, flag1 ? ClickType.QUICK_MOVE : ClickType.PICKUP); - } - } - } - - if (this.mc.player.inventory.getItemStack().isEmpty()) - { - this.lastClickTime = 0L; - } - - this.dragSplitting = false; - }*/ - - @Override - protected void mouseReleased(int mouseX, int mouseY, int state) { - System.out.println("mouseReleased:"+mouseX+","+mouseY+" state:"+state); - super.mouseReleased(mouseX, mouseY, state); - } - /* - protected void superMouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { - Slot slot = this.getSlotAtPosition(mouseX, mouseY); - ItemStack itemstack = this.mc.player.inventory.getItemStack(); - - if (this.clickedSlot != null && this.mc.gameSettings.touchscreen) - { - if (clickedMouseButton == 0 || clickedMouseButton == 1) - { - if (this.draggedStack.isEmpty()) - { - if (slot != this.clickedSlot && !this.clickedSlot.getStack().isEmpty()) - { - this.draggedStack = this.clickedSlot.getStack().copy(); - } - } - else if (this.draggedStack.getCount() > 1 && slot != null && Container.canAddItemToSlot(slot, this.draggedStack, false)) - { - long i = Minecraft.getSystemTime(); - - if (this.currentDragTargetSlot == slot) - { - if (i - this.dragItemDropDelay > 500L) - { - this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, ClickType.PICKUP); - this.handleMouseClick(slot, slot.slotNumber, 1, ClickType.PICKUP); - this.handleMouseClick(this.clickedSlot, this.clickedSlot.slotNumber, 0, ClickType.PICKUP); - this.dragItemDropDelay = i + 750L; - this.draggedStack.shrink(1); - } - } - else - { - this.currentDragTargetSlot = slot; - this.dragItemDropDelay = i; - } - } - } - } - else if (this.dragSplitting && slot != null && !itemstack.isEmpty() && (itemstack.getCount() > this.dragSplittingSlots.size() || this.dragSplittingLimit == 2) && Container.canAddItemToSlot(slot, itemstack, true) && slot.isItemValid(itemstack) && this.inventorySlots.canDragIntoSlot(slot)) - { - this.dragSplittingSlots.add(slot); - this.updateDragSplitting(); - } - }*/ - /* - private void updateDragSplitting() - { - ItemStack itemstack = this.mc.player.inventory.getItemStack(); - - if (!itemstack.isEmpty() && this.dragSplitting) - { - if (this.dragSplittingLimit == 2) - { - this.dragSplittingRemnant = itemstack.getMaxStackSize(); - } - else - { - this.dragSplittingRemnant = itemstack.getCount(); - - for (Slot slot : this.dragSplittingSlots) - { - ItemStack itemstack1 = itemstack.copy(); - ItemStack itemstack2 = slot.getStack(); - int i = itemstack2.isEmpty() ? 0 : itemstack2.getCount(); - Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack1, i); - int j = Math.min(itemstack1.getMaxStackSize(), slot.getItemStackLimit(itemstack1)); - - if (itemstack1.getCount() > j) - { - itemstack1.setCount(j); - } - - this.dragSplittingRemnant -= itemstack1.getCount() - i; - } - } - } - }*/ - - @Override - protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { - System.out.println("mouseClickMove:"+mouseX+","+mouseY+" button:"+clickedMouseButton+" sinceLastClick:"+timeSinceLastClick); - //superMouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); - super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); - } - - @Override - protected void actionPerformed(GuiButton button) throws IOException { - System.out.println("actionPerformed:"+button.displayString+" ("+button.id+")"); - super.actionPerformed(button); - } - - /* - * We'll probably wind up calling some of this manually, but they do useful things for us so we may leave - * them unharmed. - */ - - @Override - public void setWorldAndResolution(Minecraft mc, int width, int height) { - super.setWorldAndResolution(mc, width, height); - System.out.println("setWorldAndResolution:"+width+"x"+height); - - guiLeft = (width / 2) - (xSize / 2); - guiTop = (height / 2) - (ySize / 2); - - } - - @Override - public void setGuiSize(int w, int h) { - super.setGuiSize(w, h); - System.out.println("setGuiSize:"+w+"x"+h); - guiLeft = (width / 2) - (xSize / 2); - guiTop = (height / 2) - (ySize / 2); - - } - - /* (default impl calls setWorldAndResolution so we're good here.) - public void onResize(Minecraft mcIn, int w, int h) { - super.onResize(mcIn, w, h); - }*/ - - /* - * The following methods seem to be internal delegation tools; they poll the LWJGL Mouse and Keyboard objects, fire - * Forge events, and generally invisibly handle things for you that you Want Invisibly Handled. Chances are we won't - * be messing with these *at all* since they're some of the very few things in guis that work the way they should. - */ - /* - @Override - public void handleInput() throws IOException { - System.out.println("handleInput"); - super.handleInput(); - } - - @Override - public void handleMouseInput() throws IOException { - System.out.println("handleMouseInput"); - super.handleMouseInput(); - } - - @Override - public void handleKeyboardInput() throws IOException { - System.out.println("handleKeyboardInput"); - super.handleKeyboardInput(); - }*/ - - /* - * SPECIAL FUNCTIONS: Where possible, we want to draw everything based on *actual GUI state and composition* rather - * than relying on pre-baked textures that the programmer then needs to carefully match up their GUI to. - */ - - public static void rect(int left, int top, int width, int height, int color) { - if (width<=0) width=1; - if (height<=0) height=1; - - //float a = (float)(color >> 24 & 255) / 255.0F; - float r = (float)(color >> 16 & 255) / 255.0F; - float g = (float)(color >> 8 & 255) / 255.0F; - float b = (float)(color & 255) / 255.0F; - Tessellator tessellator = Tessellator.getInstance(); - VertexBuffer vertexbuffer = tessellator.getBuffer(); - GlStateManager.enableBlend(); - GlStateManager.disableTexture2D(); - GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); - GlStateManager.color(r, g, b, 1.0f); - vertexbuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); //I thought GL_QUADS was deprecated but okay, sure. - vertexbuffer.pos(left, top+height, 0.0D).endVertex(); - vertexbuffer.pos(left+width, top+height, 0.0D).endVertex(); - vertexbuffer.pos(left+width, top, 0.0D).endVertex(); - vertexbuffer.pos(left, top, 0.0D).endVertex(); - tessellator.draw(); - GlStateManager.enableTexture2D(); - GlStateManager.disableBlend(); - } - - public static void drawGuiPanel(int x, int y, int width, int height) { - rect(x+3, y+3, width-6, height-6, 0xC6C6C6); //Main panel area - rect(x+2, y+1, width-4, 2, 0xFFFFFF); //Top hilight - rect(x+2, y+height-3, width-4, 2, 0x555555); //Bottom shadow - rect(x+1, y+2, 2, height-4, 0xFFFFFF); //Left hilight - rect(x+width-3, y+2, 2, height-4, 0x555555); //Right shadow - rect(x+width-3, y+2, 1, 1, 0xC6C6C6); //Topright non-hilight/non-shadow transition pixel - rect(x+2, y+height-3, 1, 1, 0xC6C6C6); //Bottomleft non-hilight/non-shadow transition pixel - rect(x+3, y+3, 1, 1, 0xFFFFFF); //Topleft round hilight pixel - rect(x+width-4, y+height-4, 1, 1, 0x555555); //Bottomright round hilight pixel - rect(x+2, y, width-4, 1, 0x000000); //Top outline - rect(x, y+2, 1, height-4, 0x000000); //Left outline - rect(x+width-1, y+2, 1, height-4, 0x000000); //Right outline - rect(x+2, y+height-1, width-4, 1, 0x000000); //Bottom outline - rect(x+1, y+1, 1, 1, 0x000000); //Topleft round pixel - rect(x+1, y+height-2, 1, 1, 0x000000); //Bottomleft round pixel - rect(x+width-2, y+1, 1, 1, 0x000000); //Topright round pixel - rect(x+width-2, y+height-2, 1, 1, 0x000000); //Bottomright round pixel - } - - public static void drawItemSlot(int x, int y) { - rect(x, y, 17, 1, 0x373737); //Top shadow - rect(x, y+1, 1, 16, 0x373737); //Left shadow - rect(x+17, y+1, 1, 17, 0xFFFFFF); //Right hilight - rect(x+1, y+17, 17, 1, 0xFFFFFF); //Bottom hilight - } - /* - public static void drawSlot(Slot slotIn, Slot clickedSlot, ItemStack draggedStack) { - int i = slotIn.xPos; - int j = slotIn.yPos; - ItemStack itemstack = slotIn.getStack(); - boolean flag = false; - //boolean flag1 = slotIn == clickedSlot && !draggedStack.isEmpty() && !this.isRightMouseClick; - //ItemStack itemstack1 = this.mc.player.inventory.getItemStack(); - String s = null; - - //if (slotIn == this.clickedSlot && !this.draggedStack.isEmpty() && this.isRightMouseClick && !itemstack.isEmpty()) - //{ - // itemstack = itemstack.copy(); - // itemstack.setCount(itemstack.getCount() / 2); - //} - //else if (this.dragSplitting && this.dragSplittingSlots.contains(slotIn) && !itemstack1.isEmpty()) - //{ - // if (this.dragSplittingSlots.size() == 1) - // { - // return; - // } - - // if (Container.canAddItemToSlot(slotIn, itemstack1, true) && this.inventorySlots.canDragIntoSlot(slotIn)) - // { - // itemstack = itemstack1.copy(); - // flag = true; - // Container.computeStackSize(this.dragSplittingSlots, this.dragSplittingLimit, itemstack, slotIn.getStack().isEmpty() ? 0 : slotIn.getStack().getCount()); - // int k = Math.min(itemstack.getMaxStackSize(), slotIn.getItemStackLimit(itemstack)); - - // if (itemstack.getCount() > k) - // { - // s = TextFormatting.YELLOW.toString() + k; - // itemstack.setCount(k); - // } - // } - // else - // { - // this.dragSplittingSlots.remove(slotIn); - // this.updateDragSplitting(); - // } - //} - - //this.zLevel = 100.0F; - //this.itemRender.zLevel = 100.0F; - - //if (itemstack.isEmpty() && slotIn.canBeHovered()) { - //TextureAtlasSprite textureatlassprite = slotIn.getBackgroundSprite(); - - //if (textureatlassprite != null) { - // GlStateManager.disableLighting(); - //this.mc.getTextureManager().bindTexture(slotIn.getBackgroundLocation()); - //this.drawTexturedModalRect(i, j, textureatlassprite, 16, 16); - // GlStateManager.enableLighting(); - // flag1 = true; - //} - //} - - //if (!flag1) { - // if (flag) - //{ - // drawRect(i, j, i + 16, j + 16, -2130706433); - //} - - //GlStateManager.enableDepth(); - //itemRender.renderItemAndEffectIntoGUI(this.mc.player, itemstack, i, j); - //itemRender.renderItemOverlayIntoGUI(this.fontRenderer, itemstack, i, j, s); - //} - - //this.itemRender.zLevel = 0.0F; - //this.zLevel = 0.0F; - }*/ - - @Override - protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { - - //drawDefaultBackground(); - - drawGuiPanel(guiLeft, guiTop, xSize, ySize); - //fontRenderer.drawString("Firebox", left+PADDING, top+PADDING, 0xFF404040); - - if (inventorySlots!=null) { - //RenderHelper.enableGUIStandardItemLighting(); - //GlStateManager.enableRescaleNormal(); - //OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F); - - for(Slot slot : inventorySlots.inventorySlots) { - drawItemSlot(guiLeft+slot.xPos-1, guiTop+slot.yPos-1); - - //itemRender.renderItemAndEffectIntoGUI(this.mc.player, slot.getStack(), left+slot.xPos+1, top+slot.yPos+1); - //slot.xPos - } - - //GlStateManager.disableRescaleNormal(); - //RenderHelper.disableStandardItemLighting(); - } - //drawItemSlot(left+PADDING, top+PADDING+18); - //drawItemSlot(left+PADDING+18, top+PADDING+18); - //drawItemSlot(left+PADDING, top+PADDING+18+18); - - } -} diff --git a/src/main/java/com/elytradev/thermionics/data/ProbeDataSupport.java b/src/main/java/com/elytradev/thermionics/data/ProbeDataSupport.java index c245760..81760d0 100644 --- a/src/main/java/com/elytradev/thermionics/data/ProbeDataSupport.java +++ b/src/main/java/com/elytradev/thermionics/data/ProbeDataSupport.java @@ -34,12 +34,12 @@ import com.elytradev.thermionics.Thermionics; import com.elytradev.thermionics.api.IHeatStorage; import com.elytradev.thermionics.api.ISignalStorage; -import com.elytradev.thermionics.tileentity.TileEntityCableRF; import com.elytradev.thermionics.tileentity.TileEntityMachine; import com.google.common.collect.ImmutableList; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraftforge.common.capabilities.Capability; @@ -91,8 +91,8 @@ public void provideProbeData(List data) { .withBar(0, (int)(progress*100), 100, UnitDictionary.PERCENT)); } - if (machine.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) { - addInventoryData(machine.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null), data); + if (machine.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP)) { + addInventoryData(machine.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.UP), data); } //data.add(new ProbeData("MEMES: 9001")); diff --git a/src/main/java/com/elytradev/thermionics/data/SlotTesting.java b/src/main/java/com/elytradev/thermionics/data/SlotTesting.java deleted file mode 100644 index d145659..0000000 --- a/src/main/java/com/elytradev/thermionics/data/SlotTesting.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.elytradev.thermionics.data; - -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; - -public class SlotTesting extends Slot { - - public SlotTesting(IInventory inventoryIn, int index, int xPosition, int yPosition) { - super(inventoryIn, index, xPosition, yPosition); - } - - @Override - public boolean isItemValid(ItemStack stack) { - if (inventory instanceof ValidatedInventory) { - return ((ValidatedInventory) inventory).getPredicate(getSlotIndex()).test(stack); - } else { - return super.isItemValid(stack); - } - } -} diff --git a/src/main/java/com/elytradev/thermionics/data/ValidatedInventory.java b/src/main/java/com/elytradev/thermionics/data/ValidatedInventory.java deleted file mode 100644 index 2121266..0000000 --- a/src/main/java/com/elytradev/thermionics/data/ValidatedInventory.java +++ /dev/null @@ -1,160 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2017 Isaac Ellingson (Falkreon) and contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.elytradev.thermionics.data; - -import java.util.ArrayList; -import java.util.function.Predicate; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntityFurnace; -import net.minecraft.util.text.ITextComponent; - -public class ValidatedInventory implements IInventory { - private ArrayList> validators = new ArrayList<>(); - private final IInventory delegate; - - public ValidatedInventory(IInventory delegate) { - this.delegate = delegate; - } - - @SafeVarargs - public ValidatedInventory(IInventory delegate, Predicate... validators) { - this.delegate = delegate; - for(Predicate validator : validators) this.validators.add(validator); - } - - @Override - public String getName() { - return delegate.getName(); - } - - @Override - public boolean hasCustomName() { - return delegate.hasCustomName(); - } - - @Override - public ITextComponent getDisplayName() { - return delegate.getDisplayName(); - } - - @Override - public int getSizeInventory() { - return delegate.getSizeInventory(); - } - - @Override - public boolean isEmpty() { - return delegate.isEmpty(); - } - - @Override - public ItemStack getStackInSlot(int index) { - return delegate.getStackInSlot(index); - } - - @Override - public ItemStack decrStackSize(int index, int count) { - return delegate.decrStackSize(index, count); - } - - @Override - public ItemStack removeStackFromSlot(int index) { - return delegate.removeStackFromSlot(index); - } - - @Override - public void setInventorySlotContents(int index, ItemStack stack) { - delegate.setInventorySlotContents(index, stack); - } - - @Override - public int getInventoryStackLimit() { - return delegate.getInventoryStackLimit(); - } - - @Override - public void markDirty() { - delegate.markDirty(); - } - - @Override - public boolean isUsableByPlayer(EntityPlayer player) { - return delegate.isUsableByPlayer(player); - } - - @Override - public void openInventory(EntityPlayer player) { - delegate.openInventory(player); - } - - @Override - public void closeInventory(EntityPlayer player) { - delegate.closeInventory(player); - } - - @Override - public boolean isItemValidForSlot(int index, ItemStack stack) { - if (validators.size()>index) { - return validators.get(index).test(stack); - } else { - return true; - } - } - - @Override - public int getField(int id) { - return delegate.getField(id); - } - - @Override - public void setField(int id, int value) { - delegate.setField(id, value); - } - - @Override - public int getFieldCount() { - return delegate.getFieldCount(); - } - - @Override - public void clear() { - delegate.clear(); - } - - public Predicate getPredicate(int index) { - if (validators.size()>index) { - return validators.get(index); - } else { - return ANYTHING; - } - } - - public static Predicate ANYTHING = (it)->true; - public static Predicate NOTHING = (it)->false; - public static Predicate FURNACE_FUELS = TileEntityFurnace::isItemFuel; //This is actually the most correct/accurate way to read the furnace registry! - -} diff --git a/src/main/java/com/elytradev/thermionics/gui/ContainerFirebox.java b/src/main/java/com/elytradev/thermionics/gui/ContainerFirebox.java new file mode 100644 index 0000000..f3e6774 --- /dev/null +++ b/src/main/java/com/elytradev/thermionics/gui/ContainerFirebox.java @@ -0,0 +1,19 @@ +package com.elytradev.thermionics.gui; + +import com.elytradev.concrete.gui.ConcreteContainer; + +import net.minecraft.inventory.IInventory; + +public class ContainerFirebox extends ConcreteContainer { + public static final int ID = 0; + + public ContainerFirebox(IInventory player, IInventory container) { + super(player, container); + + initPlayerInventory(0, 18*4); + + initContainerSlot(0, 2,1); + initContainerSlot(1, 6,1); + } + +} diff --git a/src/main/java/com/elytradev/thermionics/gui/ContainerOven.java b/src/main/java/com/elytradev/thermionics/gui/ContainerOven.java new file mode 100644 index 0000000..e7f34f9 --- /dev/null +++ b/src/main/java/com/elytradev/thermionics/gui/ContainerOven.java @@ -0,0 +1,19 @@ +package com.elytradev.thermionics.gui; + +import com.elytradev.concrete.gui.ConcreteContainer; + +import net.minecraft.inventory.IInventory; + +public class ContainerOven extends ConcreteContainer { + public static final int ID = 1; + + public ContainerOven(IInventory player, IInventory container) { + super(player, container); + + initPlayerInventory(0, 18*4); + + initContainerSlot(0, 2,1); + initContainerSlot(1, 6,1); + } + +} diff --git a/src/main/java/com/elytradev/thermionics/gui/SlotValidated.java b/src/main/java/com/elytradev/thermionics/gui/SlotValidated.java deleted file mode 100644 index 372aef8..0000000 --- a/src/main/java/com/elytradev/thermionics/gui/SlotValidated.java +++ /dev/null @@ -1,162 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2017 Isaac Ellingson (Falkreon) and contributors - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package com.elytradev.thermionics.gui; - -import javax.annotation.Nullable; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import net.minecraftforge.items.IItemHandler; - -public class SlotValidated extends Slot { - private IItemHandler inventory; - private int index; - private boolean readonly = false; - - public SlotValidated(IItemHandler inventoryIn, int index, int xPosition, int yPosition) { - super(null, index, xPosition, yPosition); - this.inventory = inventoryIn; - this.index = index; - } - - @Override - public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack) { - return inventory.extractItem(index, stack.getCount(), false); - } - - @Override - public boolean isItemValid(ItemStack stack) { - return inventory.insertItem(index, stack, true).isEmpty(); - } - - @Override - public ItemStack getStack() { - return inventory.getStackInSlot(index); - } - - @Override - public boolean getHasStack() { - return !getStack().isEmpty(); - } - - @Override - public void putStack(ItemStack stack) { - //This method is sadly lacking in validation! If the inserted item is rejected, *it disappears*. So be careful. - inventory.insertItem(index, stack, false); - } - - @Override - public void onSlotChanged() { - //With the Capability interface, we can safely assume that this happens "under the hood" through messages fired - //from the bound data. - } - - - @Override - public int getSlotStackLimit() { - return inventory.getSlotLimit(this.slotNumber); - } - - @Override - public int getItemStackLimit(ItemStack stack) { - return Math.min(getSlotStackLimit(), stack.getMaxStackSize()); - } - - @Nullable - @SideOnly(Side.CLIENT) - @Override - public String getSlotTexture() { - return null; - } - - @Override - public ItemStack decrStackSize(int amount) { - return inventory.extractItem(index, amount, false); - } - - @Override - public boolean isHere(IInventory inv, int slotIn) { - return slotIn==index; //we can't verify whether the IInventory is correct! - } - - @Override - public boolean canTakeStack(EntityPlayer playerIn) { - - return (!this.readonly) && (inventory.extractItem(index, 1, true).isEmpty()); - } - - @SideOnly(Side.CLIENT) - @Override - public boolean canBeHovered() { - return this.readonly; - } - - /* Overridden Forge stuff. Mostly just hacking off the optional slot background textures. */ - - @SideOnly(Side.CLIENT) - @Override - public net.minecraft.util.ResourceLocation getBackgroundLocation() { - return net.minecraft.client.renderer.texture.TextureMap.LOCATION_BLOCKS_TEXTURE; - } - - @SideOnly(Side.CLIENT) - @Override - public void setBackgroundLocation(net.minecraft.util.ResourceLocation texture) { } - - @Override - public void setBackgroundName(String name) {} - - @SideOnly(Side.CLIENT) - @Override - public net.minecraft.client.renderer.texture.TextureAtlasSprite getBackgroundSprite() { - return null; - } - - @SideOnly(Side.CLIENT) - @Override - protected net.minecraft.client.renderer.texture.TextureMap getBackgroundMap() { - return null; - } - - /** - * Returns the slot number in the host IItemHandler (NOT the Slot index in the GuiContainer!) - */ - @Override - public int getSlotIndex() { - return this.index; - } - - @Override - public boolean isSameInventory(Slot other) { - if (other instanceof SlotValidated) { - return ((SlotValidated)other).inventory==this.inventory; - } else { - return false; - } - } -} diff --git a/src/main/java/com/elytradev/thermionics/gui/WBorderPanel.java b/src/main/java/com/elytradev/thermionics/gui/WBorderPanel.java deleted file mode 100644 index f1db392..0000000 --- a/src/main/java/com/elytradev/thermionics/gui/WBorderPanel.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.elytradev.thermionics.gui; - -import java.util.HashMap; - -import net.minecraft.util.EnumFacing; - -/** - * Like a JPanel with a BorderLayout - */ -public class WBorderPanel extends WPanel { - private HashMap orientations = new HashMap<>(); - - public void add(WWidget w, EnumFacing side) { - EnumFacing cleanSide = side; - if (side.equals(EnumFacing.DOWN)) cleanSide = EnumFacing.UP; - children.add(w); - orientations.put(cleanSide, w); - } -} diff --git a/src/main/java/com/elytradev/thermionics/gui/WPanel.java b/src/main/java/com/elytradev/thermionics/gui/WPanel.java index d18177e..9320177 100644 --- a/src/main/java/com/elytradev/thermionics/gui/WPanel.java +++ b/src/main/java/com/elytradev/thermionics/gui/WPanel.java @@ -1,8 +1,31 @@ +/** + * MIT License + * + * Copyright (c) 2017 Isaac Ellingson (Falkreon) and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package com.elytradev.thermionics.gui; import java.util.ArrayList; -import com.elytradev.thermionics.data.ContainerTesting; +import com.elytradev.concrete.gui.ConcreteContainer; /** * Comparable to swing's JPanel, except that this is the base class for containers too - there's no way to make a @@ -10,15 +33,10 @@ */ public class WPanel extends WWidget { protected ArrayList children = new ArrayList<>(); - - - /* handled by subclasses - public void add(WWidget w) { - children.add(w); - }*/ + protected boolean valid; @Override - public void createPeers(ContainerTesting c) { + public void createPeers(ConcreteContainer c) { for(WWidget child : children) { child.createPeers(c); } @@ -27,4 +45,18 @@ public void createPeers(ContainerTesting c) { public void remove(WWidget w) { children.remove(w); } + + @Override + public boolean canResize() { + return true; + } + + /** + * Uses this Panel's layout rules to reposition and resize components to fit nicely in the panel. + */ + public void layout() { + for(WWidget child : children) { + if (child instanceof WPanel) ((WPanel)child).layout(); + } + } } diff --git a/src/main/java/com/elytradev/thermionics/gui/WPanelHorizontal.java b/src/main/java/com/elytradev/thermionics/gui/WPanelHorizontal.java new file mode 100644 index 0000000..8724c49 --- /dev/null +++ b/src/main/java/com/elytradev/thermionics/gui/WPanelHorizontal.java @@ -0,0 +1,84 @@ +/** + * MIT License + * + * Copyright (c) 2017 Isaac Ellingson (Falkreon) and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.elytradev.thermionics.gui; + +import com.elytradev.concrete.gui.ConcreteContainer; + +/** + * Like a JPanel with a horizontal BoxLayout + * + *
    + *
  • If all children are nonresizable, they will wind up equally spaced horizontally, with their vertical position + * centered on this Panel's centerline. + *
  • If all children are resizable, they will wind up taking up the exact height of this Panel, and each component + * will split this Panel's horizontal space equally. + *
  • If some children are resizable and some children are not, each resizable child will attempt to grow equally to + * fill the unoccupied horizontal space, (and all resizable children will still be the exact height of this Panel). + *
+ */ +public class WPanelHorizontal extends WPanel { + + public void add(WWidget w) { + children.add(w); + } + + @Override + public void createPeers(ConcreteContainer c) { + for(WWidget child : children) { + child.createPeers(c); + } + } + + @Override + public void layout() { + + int unresizable = 0; + int numResizable = 0; + for(WWidget w : children) { + if (w.canResize()) { + numResizable++; + } else { + int wid = w.getWidth(); + unresizable += wid; + } + } + int resizeSpace = getWidth()-unresizable; + int resizeEach = resizeSpace / numResizable; + if (resizeEach<18) resizeEach = 18; //Don't squish things beyond a minimum reasonable size! Better for them to overlap :/ + + int centerline = this.getHeight()/2; + int curLeft = 0; + for(int i=0; iHeatStorageView.extractOnlyOf(heatStorage), ()->heatStorage); capabilities.registerForAllSides(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, - ()->new ValidatedItemStorageView(new MachineItemStorageView(itemStorage), TileEntityFirebox::validateItemInsert), ()->itemStorage); + ()->new ValidatedItemHandlerView(itemStorage), ()->itemStorage); } @Override @@ -138,7 +144,7 @@ public void update() { @Override public IInventory getContainerInventory() { - return new ValidatedInventory(itemStorage, ValidatedInventory.FURNACE_FUELS, ValidatedInventory.NOTHING, ValidatedInventory.NOTHING); + return new ValidatedInventoryView(itemStorage); } @Override @@ -149,11 +155,12 @@ public float getMachineProgress() { return progress; } + /* public static boolean validateItemInsert(int slot, ItemStack item) { if (slot==MachineItemStorageView.SLOT_MACHINE_INPUT) { return TileEntityFurnace.getItemBurnTime(item)>0; //Sadly, GameRegistry.getFuelValue returns 0 for vanilla burnables. } else { return true; } - } + }*/ } diff --git a/src/main/java/com/elytradev/thermionics/tileentity/TileEntityOven.java b/src/main/java/com/elytradev/thermionics/tileentity/TileEntityOven.java index 1efb645..fa4d11e 100644 --- a/src/main/java/com/elytradev/thermionics/tileentity/TileEntityOven.java +++ b/src/main/java/com/elytradev/thermionics/tileentity/TileEntityOven.java @@ -24,42 +24,49 @@ package com.elytradev.thermionics.tileentity; +import com.elytradev.concrete.inventory.ConcreteItemStorage; +import com.elytradev.concrete.inventory.IContainerInventoryHolder; +import com.elytradev.concrete.inventory.StandardMachineSlots; +import com.elytradev.concrete.inventory.ValidatedInventoryView; +import com.elytradev.concrete.inventory.ValidatedItemHandlerView; +import com.elytradev.concrete.inventory.Validators; import com.elytradev.thermionics.Thermionics; import com.elytradev.thermionics.api.impl.HeatStorage; import com.elytradev.thermionics.api.impl.HeatStorageView; import com.elytradev.thermionics.data.IMachineProgress; -import com.elytradev.thermionics.data.MachineItemStorageView; -import com.elytradev.thermionics.data.ObservableItemStorage; -import com.elytradev.thermionics.data.ValidatedItemStorageView; import com.google.common.primitives.Ints; +import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ITickable; -import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.items.CapabilityItemHandler; -public class TileEntityOven extends TileEntityMachine implements ITickable, IMachineProgress { - private static final int SLOT_WORK = 2; +public class TileEntityOven extends TileEntityMachine implements ITickable, IMachineProgress, IContainerInventoryHolder { private static final int H_PER_SMELT = 200; private static final int HEAT_EFFICIENCY = 2; - private ObservableItemStorage itemStorage; + private ConcreteItemStorage itemStorage; private HeatStorage heatStorage; private int progress = 0; public TileEntityOven() { - itemStorage = new ObservableItemStorage(3); heatStorage = new HeatStorage(600); + itemStorage = new ConcreteItemStorage(3) + .withName("tile.thermionics.machine.oven.name") + .withValidators(Validators.SMELTABLE, Validators.NOTHING, Validators.NOTHING) + .setCanExtract(0, false) + .setCanExtract(1, true) + .setCanExtract(2, false); itemStorage.listen(this::markDirty); heatStorage.listen(this::markDirty); capabilities.registerForAllSides(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, - ()->new ValidatedItemStorageView(new MachineItemStorageView(itemStorage), TileEntityOven::validateItemInsert), - ()->itemStorage); - capabilities.registerForAllSides(Thermionics.CAPABILITY_HEATSTORAGE, ()->HeatStorageView.insertOnlyOf(heatStorage), ()->heatStorage); + ()->new ValidatedItemHandlerView(itemStorage), ()->itemStorage); + capabilities.registerForAllSides(Thermionics.CAPABILITY_HEATSTORAGE, + ()->HeatStorageView.insertOnlyOf(heatStorage), ()->heatStorage); } @Override @@ -94,7 +101,7 @@ public void update() { //We're finished. Don't do *anything* until we can kick the item into the output slot. //Note: By now the "work-slot" has always already been replaced by a smelting result. - if (itemStorage.getStackInSlot(SLOT_WORK).isEmpty()) { + if (itemStorage.getStackInSlot(StandardMachineSlots.WORK).isEmpty()) { //Invalid state! Kick us back into a valid state. progress = 0; this.markDirty(); @@ -103,8 +110,8 @@ public void update() { //System.out.println("Smelt end step. workslot:"+itemStorage.getStackInSlot(SLOT_WORK)+" outputslot:"+itemStorage.getStackInSlot(MachineItemStorageView.SLOT_MACHINE_OUTPUT)); - ItemStack result = itemStorage.insertItem(MachineItemStorageView.SLOT_MACHINE_OUTPUT, itemStorage.getStackInSlot(SLOT_WORK), false); - itemStorage.setStackInSlot(SLOT_WORK, result); + ItemStack result = itemStorage.insertItem(StandardMachineSlots.OUTPUT, itemStorage.getStackInSlot(StandardMachineSlots.WORK), false); + itemStorage.setStackInSlot(StandardMachineSlots.WORK, result); //System.out.println("End End step. workslot:"+itemStorage.getStackInSlot(SLOT_WORK)+" outputslot:"+itemStorage.getStackInSlot(MachineItemStorageView.SLOT_MACHINE_OUTPUT)); if (result==null || result.isEmpty()) { @@ -125,7 +132,7 @@ public void update() { int heatAvailable = heatStorage.getHeatStored(); int heatToConsume = Ints.min(heatAvailable, HEAT_EFFICIENCY, heatNeeded); - if (itemStorage.getStackInSlot(MachineItemStorageView.SLOT_MACHINE_INPUT).isEmpty()) { + if (itemStorage.getStackInSlot(StandardMachineSlots.INPUT).isEmpty()) { if (progress>0) { progress = 0; markDirty(); @@ -155,20 +162,26 @@ public float getMachineProgress() { } private void doSmelt() { - if (itemStorage.getStackInSlot(SLOT_WORK).isEmpty()) { - ItemStack input = itemStorage.extractItem(MachineItemStorageView.SLOT_MACHINE_INPUT, 1, false); + if (itemStorage.getStackInSlot(StandardMachineSlots.WORK).isEmpty()) { + ItemStack input = itemStorage.extractItem(StandardMachineSlots.INPUT, 1, false); if (input.isEmpty()) return; ItemStack result = FurnaceRecipes.instance().getSmeltingResult(input).copy(); - itemStorage.setStackInSlot(SLOT_WORK, result); + itemStorage.setStackInSlot(StandardMachineSlots.WORK, result); } } + + @Override + public IInventory getContainerInventory() { + return new ValidatedInventoryView(itemStorage); + } + /* public static boolean validateItemInsert(int slot, ItemStack item) { if (slot==MachineItemStorageView.SLOT_MACHINE_INPUT) { return !FurnaceRecipes.instance().getSmeltingResult(item).isEmpty(); } else { return true; } - } + }*/ } diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index d89da64..ff03c17 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -4,7 +4,7 @@ "modid": "thermionics", "name": "Thermionics|Core", "description": "Creative Industrial Automation", - "version": "1.0.4", + "version": "1.0.7", "mcversion": "1.11.2", "url": "", "updateUrl": "",