mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-21 12:32:23 +00:00
Adding a preview slot to the centrifuge
This commit is contained in:
1 parent
52f233e84a
commit
b2b743398c
8 files changed
+63
-16
No files matched your search
@@ -14,8 +14,6 @@ import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.IContainerListener;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
|
||||
@@ -11,10 +11,13 @@
|
||||
package forestry.factory.gui;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import forestry.core.gui.ContainerSocketed;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.gui.slots.SlotLocked;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.core.network.packets.PacketItemStackDisplay;
|
||||
import forestry.factory.tiles.TileCentrifuge;
|
||||
|
||||
public class ContainerCentrifuge extends ContainerSocketed<TileCentrifuge> {
|
||||
@@ -23,14 +26,34 @@ public class ContainerCentrifuge extends ContainerSocketed<TileCentrifuge> {
|
||||
super(tile, player, 8, 84);
|
||||
|
||||
// Resource
|
||||
this.addSlotToContainer(new SlotFiltered(tile, 0, 30, 37));
|
||||
this.addSlotToContainer(new SlotFiltered(tile, 0, 16, 37));
|
||||
|
||||
// Craft Preview display
|
||||
addSlotToContainer(new SlotLocked(tile.getCraftPreviewInventory(), 0, 49, 37));
|
||||
|
||||
// Product Inventory
|
||||
for (int l = 0; l < 3; l++) {
|
||||
for (int k = 0; k < 3; k++) {
|
||||
addSlotToContainer(new SlotOutput(tile, 1 + k + l * 3, 98 + k * 18, 19 + l * 18));
|
||||
addSlotToContainer(new SlotOutput(tile, 1 + k + l * 3, 112 + k * 18, 19 + l * 18));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ItemStack oldCraftPreview;
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
|
||||
IInventory craftPreviewInventory = tile.getCraftPreviewInventory();
|
||||
|
||||
ItemStack newCraftPreview = craftPreviewInventory.getStackInSlot(0);
|
||||
if (!ItemStack.areItemStacksEqual(oldCraftPreview, newCraftPreview)) {
|
||||
oldCraftPreview = newCraftPreview;
|
||||
|
||||
PacketItemStackDisplay packet = new PacketItemStackDisplay(tile, newCraftPreview);
|
||||
sendPacketToListeners(packet);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class GuiCentrifuge extends GuiForestryTitled<ContainerCentrifuge, TileCe
|
||||
|
||||
public GuiCentrifuge(InventoryPlayer inventory, TileCentrifuge tile) {
|
||||
super(Constants.TEXTURE_PATH_GUI + "/centrifugesocket.png", new ContainerCentrifuge(inventory, tile), tile);
|
||||
widgetManager.add(new SocketWidget(this.widgetManager, 71, 37, tile, 0));
|
||||
widgetManager.add(new SocketWidget(this.widgetManager, 79, 37, tile, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -29,6 +29,7 @@ public class GuiCentrifuge extends GuiForestryTitled<ContainerCentrifuge, TileCe
|
||||
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
|
||||
|
||||
int progress = inventory.getProgressScaled(16);
|
||||
drawTexturedModalRect(guiLeft + 58, guiTop + 36 + 17 - progress, 176, 17 - progress, 4, progress);
|
||||
drawTexturedModalRect(guiLeft + 43, guiTop + 36 + 17 - progress, 176, 17 - progress, 4, progress);
|
||||
drawTexturedModalRect(guiLeft + 67, guiTop + 36 + 17 - progress, 176, 17 - progress, 4, progress);
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,8 @@ public class FactoryJeiPlugin extends BlankModPlugin {
|
||||
|
||||
registry.addRecipeClickArea(GuiBottler.class, 80, 37, 26, 22, ForestryRecipeCategoryUid.BOTTLER);
|
||||
registry.addRecipeClickArea(GuiCarpenter.class, 98, 48, 21, 26, ForestryRecipeCategoryUid.CARPENTER);
|
||||
registry.addRecipeClickArea(GuiCentrifuge.class, 52, 22, 16, 48, ForestryRecipeCategoryUid.CENTRIFUGE);
|
||||
registry.addRecipeClickArea(GuiCentrifuge.class, 38, 22, 38, 14, ForestryRecipeCategoryUid.CENTRIFUGE);
|
||||
registry.addRecipeClickArea(GuiCentrifuge.class, 38, 54, 38, 14, ForestryRecipeCategoryUid.CENTRIFUGE);
|
||||
registry.addRecipeClickArea(GuiFabricator.class, 121, 53, 18, 18, ForestryRecipeCategoryUid.FABRICATOR);
|
||||
registry.addRecipeClickArea(GuiFermenter.class, 72, 40, 32, 18, ForestryRecipeCategoryUid.FERMENTER);
|
||||
registry.addRecipeClickArea(GuiMoistener.class, 123, 35, 19, 21, ForestryRecipeCategoryUid.MOISTENER);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class CentrifugeRecipeCategory extends ForestryRecipeCategory {
|
||||
private final IDrawableAnimated arrow;
|
||||
|
||||
public CentrifugeRecipeCategory(IGuiHelper guiHelper) {
|
||||
super(guiHelper.createDrawable(guiTexture, 25, 18, 126, 54), "tile.for.centrifuge.name");
|
||||
super(guiHelper.createDrawable(guiTexture, 11, 18, 154, 54), "tile.for.centrifuge.name");
|
||||
|
||||
IDrawableStatic arrowDrawable = guiHelper.createDrawable(guiTexture, 176, 0, 4, 17);
|
||||
this.arrow = guiHelper.createAnimatedDrawable(arrowDrawable, 80, IDrawableAnimated.StartDirection.BOTTOM, false);
|
||||
@@ -57,7 +57,8 @@ public class CentrifugeRecipeCategory extends ForestryRecipeCategory {
|
||||
|
||||
@Override
|
||||
public void drawAnimations(@Nonnull Minecraft minecraft) {
|
||||
arrow.draw(minecraft, 33, 18);
|
||||
arrow.draw(minecraft, 32, 18);
|
||||
arrow.draw(minecraft, 56, 18);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -86,7 +87,7 @@ public class CentrifugeRecipeCategory extends ForestryRecipeCategory {
|
||||
if (i >= OUTPUTS.length) {
|
||||
return;
|
||||
}
|
||||
int x = 72 + OUTPUTS[i][0] * 18;
|
||||
int x = 100 + OUTPUTS[i][0] * 18;
|
||||
int y = OUTPUTS[i][1] * 18;
|
||||
int slotIndex = outputSlot + i;
|
||||
guiItemStacks.init(slotIndex, false, x, y);
|
||||
|
||||
@@ -55,7 +55,7 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
|
||||
|
||||
private final FilteredTank resourceTank;
|
||||
private final TankManager tankManager;
|
||||
private final InventoryAdapterTile craftingInventory;
|
||||
private final InventoryAdapterTile craftingInventory;
|
||||
private final InventoryCraftResult craftPreviewInventory;
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -16,11 +16,12 @@ import java.util.Collection;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.inventory.InventoryCraftResult;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import forestry.api.circuits.ChipsetManager;
|
||||
import forestry.api.circuits.CircuitSocketType;
|
||||
import forestry.api.circuits.ICircuitBoard;
|
||||
@@ -34,6 +35,7 @@ import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.tiles.IItemStackDisplay;
|
||||
import forestry.core.tiles.TilePowered;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.factory.gui.ContainerCentrifuge;
|
||||
@@ -41,12 +43,13 @@ import forestry.factory.gui.GuiCentrifuge;
|
||||
import forestry.factory.inventory.InventoryCentrifuge;
|
||||
import forestry.factory.recipes.CentrifugeRecipeManager;
|
||||
|
||||
public class TileCentrifuge extends TilePowered implements ISocketable, ISidedInventory {
|
||||
public class TileCentrifuge extends TilePowered implements ISocketable, ISidedInventory, IItemStackDisplay {
|
||||
private static final int TICKS_PER_RECIPE_TIME = 1;
|
||||
private static final int ENERGY_PER_WORK_CYCLE = 3200;
|
||||
private static final int ENERGY_PER_RECIPE_TIME = ENERGY_PER_WORK_CYCLE / 20;
|
||||
|
||||
private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets");
|
||||
private final InventoryCraftResult craftPreviewInventory;
|
||||
|
||||
private ICentrifugeRecipe currentRecipe;
|
||||
|
||||
@@ -55,6 +58,7 @@ public class TileCentrifuge extends TilePowered implements ISocketable, ISidedIn
|
||||
public TileCentrifuge() {
|
||||
super("centrifuge", 800, Constants.MACHINE_MAX_ENERGY);
|
||||
setInternalInventory(new InventoryCentrifuge(this));
|
||||
craftPreviewInventory = new InventoryCraftResult();
|
||||
}
|
||||
|
||||
/* LOADING & SAVING */
|
||||
@@ -114,10 +118,12 @@ public class TileCentrifuge extends TilePowered implements ISocketable, ISidedIn
|
||||
@Override
|
||||
public boolean workCycle() {
|
||||
if (tryAddPending()) {
|
||||
setCurrentPreviewItem();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!pendingProducts.isEmpty()) {
|
||||
setCurrentPreviewItem();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -130,8 +136,8 @@ public class TileCentrifuge extends TilePowered implements ISocketable, ISidedIn
|
||||
pendingProducts.addAll(products);
|
||||
|
||||
getInternalInventory().decrStackSize(InventoryCentrifuge.SLOT_RESOURCE, 1);
|
||||
|
||||
tryAddPending();
|
||||
|
||||
setCurrentPreviewItem();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -255,4 +261,21 @@ public class TileCentrifuge extends TilePowered implements ISocketable, ISidedIn
|
||||
public Object getContainer(EntityPlayer player, int data) {
|
||||
return new ContainerCentrifuge(player.inventory, this);
|
||||
}
|
||||
|
||||
public IInventory getCraftPreviewInventory() {
|
||||
return craftPreviewInventory;
|
||||
}
|
||||
|
||||
private void setCurrentPreviewItem(){
|
||||
if(!pendingProducts.isEmpty()){
|
||||
craftPreviewInventory.setInventorySlotContents(0, pendingProducts.peek());
|
||||
}else{
|
||||
craftPreviewInventory.setInventorySlotContents(0, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItemStackForDisplay(ItemStack itemStack) {
|
||||
craftPreviewInventory.setInventorySlotContents(0, itemStack);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user