mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-28 15:36:18 +00:00
Move the worktable into a separate module
This commit is contained in:
1 parent
a058c3f8c9
commit
42865951a9
44 files changed
+915
-646
No files matched your search
@@ -0,0 +1,167 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.worktable.gui;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
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 forestry.core.gui.ContainerTile;
|
||||
import forestry.core.gui.IContainerCrafting;
|
||||
import forestry.core.gui.IGuiSelectable;
|
||||
import forestry.core.gui.slots.SlotCraftMatrix;
|
||||
import forestry.core.gui.slots.SlotCrafter;
|
||||
import forestry.core.inventory.InventoryGhostCrafting;
|
||||
import forestry.core.network.packets.PacketGuiSelectRequest;
|
||||
import forestry.core.utils.ItemStackUtil;
|
||||
import forestry.core.utils.NetworkUtil;
|
||||
import forestry.worktable.inventory.InventoryCraftingForestry;
|
||||
import forestry.worktable.inventory.InventoryWorktable;
|
||||
import forestry.worktable.network.packets.PacketWorktableMemoryUpdate;
|
||||
import forestry.worktable.network.packets.PacketWorktableRecipeRequest;
|
||||
import forestry.worktable.network.packets.PacketWorktableRecipeUpdate;
|
||||
import forestry.worktable.recipes.MemorizedRecipe;
|
||||
import forestry.worktable.recipes.RecipeMemory;
|
||||
import forestry.worktable.tiles.TileWorktable;
|
||||
|
||||
public class ContainerWorktable extends ContainerTile<TileWorktable> implements IContainerCrafting, IGuiSelectable {
|
||||
private final InventoryCraftingForestry craftMatrix = new InventoryCraftingForestry(this);
|
||||
private long lastMemoryUpdate;
|
||||
private boolean craftMatrixChanged = false;
|
||||
|
||||
public ContainerWorktable(EntityPlayer player, TileWorktable tile) {
|
||||
super(tile, player.inventory, 8, 136);
|
||||
|
||||
IInventory craftingDisplay = tile.getCraftingDisplay();
|
||||
IInventory internalInventory = tile.getInternalInventory();
|
||||
|
||||
// Internal inventory
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int k = 0; k < 9; k++) {
|
||||
addSlotToContainer(new Slot(internalInventory, InventoryWorktable.SLOT_INVENTORY_1 + k + i * 9, 8 + k * 18, 90 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// Crafting matrix
|
||||
for (int l = 0; l < 3; l++) {
|
||||
for (int k1 = 0; k1 < 3; k1++) {
|
||||
addSlotToContainer(new SlotCraftMatrix(this, craftingDisplay, k1 + l * 3, 11 + k1 * 18, 20 + l * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// CraftResult display
|
||||
addSlotToContainer(new SlotCrafter(player, craftMatrix, craftingDisplay, tile, InventoryGhostCrafting.SLOT_CRAFTING_RESULT, 77, 38));
|
||||
|
||||
for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
|
||||
onCraftMatrixChanged(tile.getCraftingDisplay(), i);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
if (craftMatrixChanged) {
|
||||
craftMatrixChanged = false;
|
||||
tile.setCurrentRecipe(craftMatrix);
|
||||
sendPacketToListeners(new PacketWorktableRecipeUpdate(tile));
|
||||
}
|
||||
|
||||
super.detectAndSendChanges();
|
||||
|
||||
if (lastMemoryUpdate != tile.getMemory().getLastUpdate()) {
|
||||
lastMemoryUpdate = tile.getMemory().getLastUpdate();
|
||||
sendPacketToListeners(new PacketWorktableMemoryUpdate(tile));
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCraftMatrix() {
|
||||
IInventory crafting = tile.getCraftingDisplay();
|
||||
for (int i = 0; i < crafting.getSizeInventory(); i++) {
|
||||
onCraftMatrixChanged(crafting, i);
|
||||
}
|
||||
}
|
||||
|
||||
// Fired when SlotCraftMatrix detects a change.
|
||||
// Direct changes to the underlying inventory are not detected, only slot changes.
|
||||
@Override
|
||||
public void onCraftMatrixChanged(IInventory iinventory, int slot) {
|
||||
if (slot >= craftMatrix.getSizeInventory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ItemStack stack = iinventory.getStackInSlot(slot);
|
||||
ItemStack currentStack = craftMatrix.getStackInSlot(slot);
|
||||
|
||||
if (!ItemStackUtil.isIdenticalItem(stack, currentStack)) {
|
||||
craftMatrix.setInventorySlotContents(slot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
// Fired when this container's craftMatrix detects a change
|
||||
@Override
|
||||
public void onCraftMatrixChanged(IInventory iinventory) {
|
||||
craftMatrixChanged = true;
|
||||
}
|
||||
|
||||
/* Gui Selection Handling */
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void clearRecipe() {
|
||||
sendRecipeClick(-1, 0);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static void sendRecipeClick(int mouseButton, int recipeIndex) {
|
||||
NetworkUtil.sendToServer(new PacketGuiSelectRequest(mouseButton, recipeIndex));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleSelectionRequest(EntityPlayerMP player, int primary, int secondary) {
|
||||
switch (primary) {
|
||||
case -1: { // clicked clear button
|
||||
tile.clearCraftMatrix();
|
||||
updateCraftMatrix();
|
||||
sendPacketToListeners(new PacketWorktableRecipeUpdate(tile));
|
||||
break;
|
||||
}
|
||||
case 0: { // clicked a memorized recipe
|
||||
tile.chooseRecipeMemory(secondary);
|
||||
updateCraftMatrix();
|
||||
sendPacketToListeners(new PacketWorktableRecipeUpdate(tile));
|
||||
break;
|
||||
}
|
||||
case 1: { // right clicked a memorized recipe
|
||||
long time = player.world.getTotalWorldTime();
|
||||
RecipeMemory memory = tile.getMemory();
|
||||
memory.toggleLock(time, secondary);
|
||||
break;
|
||||
}
|
||||
case 100: { // clicked previous recipe conflict button
|
||||
tile.choosePreviousConflictRecipe();
|
||||
sendPacketToListeners(new PacketWorktableRecipeUpdate(tile));
|
||||
break;
|
||||
}
|
||||
case 101: { // clicked next recipe conflict button
|
||||
tile.chooseNextConflictRecipe();
|
||||
sendPacketToListeners(new PacketWorktableRecipeUpdate(tile));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void sendWorktableRecipeRequest(MemorizedRecipe recipe) {
|
||||
NetworkUtil.sendToServer(new PacketWorktableRecipeRequest(tile, recipe));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.worktable.gui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.gui.GuiForestryTitled;
|
||||
import forestry.core.gui.buttons.GuiBetterButton;
|
||||
import forestry.core.gui.buttons.StandardButtonTextureSets;
|
||||
import forestry.core.network.packets.PacketGuiSelectRequest;
|
||||
import forestry.core.utils.NetworkUtil;
|
||||
import forestry.core.utils.SoundUtil;
|
||||
import forestry.worktable.gui.widgets.ClearWorktable;
|
||||
import forestry.worktable.gui.widgets.MemorizedRecipeSlot;
|
||||
import forestry.worktable.recipes.RecipeMemory;
|
||||
import forestry.worktable.tiles.TileWorktable;
|
||||
|
||||
public class GuiWorktable extends GuiForestryTitled<ContainerWorktable> {
|
||||
private static final int SPACING = 18;
|
||||
|
||||
private final TileWorktable tile;
|
||||
private boolean hasRecipeConflict = false;
|
||||
|
||||
public GuiWorktable(EntityPlayer player, TileWorktable tile) {
|
||||
super(Constants.TEXTURE_PATH_GUI + "/worktable2.png", new ContainerWorktable(player, tile), tile);
|
||||
this.tile = tile;
|
||||
|
||||
this.ySize = 218;
|
||||
|
||||
RecipeMemory recipeMemory = tile.getMemory();
|
||||
|
||||
int slot = 0;
|
||||
for (int y = 0; y < 3; y++) {
|
||||
int yPos = 20 + y * SPACING;
|
||||
for (int x = 0; x < 3; x++) {
|
||||
int xPos = 110 + x * SPACING;
|
||||
MemorizedRecipeSlot memorizedRecipeSlot = new MemorizedRecipeSlot(widgetManager, xPos, yPos, recipeMemory, slot++);
|
||||
widgetManager.add(memorizedRecipeSlot);
|
||||
}
|
||||
}
|
||||
|
||||
widgetManager.add(new ClearWorktable(widgetManager, 66, 19));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
super.updateScreen();
|
||||
|
||||
if (hasRecipeConflict != tile.hasRecipeConflict()) {
|
||||
hasRecipeConflict = tile.hasRecipeConflict();
|
||||
if (hasRecipeConflict) {
|
||||
addButtons();
|
||||
} else {
|
||||
buttonList.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addButtons() {
|
||||
buttonList.add(new GuiBetterButton(0, guiLeft + 76, guiTop + 56, StandardButtonTextureSets.LEFT_BUTTON_SMALL));
|
||||
buttonList.add(new GuiBetterButton(1, guiLeft + 85, guiTop + 56, StandardButtonTextureSets.RIGHT_BUTTON_SMALL));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) {
|
||||
int id = 100 + button.id;
|
||||
NetworkUtil.sendToServer(new PacketGuiSelectRequest(id, 0));
|
||||
SoundUtil.playButtonClick();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addLedgers() {
|
||||
addErrorLedger(tile);
|
||||
addHintLedger("worktable");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.worktable.gui;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
@@ -0,0 +1,35 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.worktable.gui.widgets;
|
||||
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
import forestry.core.utils.SoundUtil;
|
||||
import forestry.worktable.gui.ContainerWorktable;
|
||||
|
||||
public class ClearWorktable extends Widget {
|
||||
|
||||
public ClearWorktable(WidgetManager manager, int xPos, int yPos) {
|
||||
super(manager, xPos, yPos);
|
||||
width = 7;
|
||||
height = 7;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int startX, int startY) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
|
||||
ContainerWorktable.clearRecipe();
|
||||
SoundUtil.playButtonClick();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.worktable.gui.widgets;
|
||||
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.gui.widgets.ItemStackWidgetBase;
|
||||
import forestry.core.gui.widgets.WidgetManager;
|
||||
import forestry.core.render.TextureManagerForestry;
|
||||
import forestry.core.utils.SoundUtil;
|
||||
import forestry.worktable.gui.ContainerWorktable;
|
||||
import forestry.worktable.recipes.RecipeMemory;
|
||||
|
||||
public class MemorizedRecipeSlot extends ItemStackWidgetBase {
|
||||
private static final TextureAtlasSprite lockIcon = TextureManagerForestry.getInstance().getDefault("slots/locked");
|
||||
private final RecipeMemory recipeMemory;
|
||||
private final int slotNumber;
|
||||
|
||||
public MemorizedRecipeSlot(WidgetManager manager, int xPos, int yPos, RecipeMemory recipeMemory, int slot) {
|
||||
super(manager, xPos, yPos);
|
||||
this.recipeMemory = recipeMemory;
|
||||
this.slotNumber = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack() {
|
||||
return recipeMemory.getRecipeDisplayOutput(slotNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int startX, int startY) {
|
||||
super.draw(startX, startY);
|
||||
|
||||
GlStateManager.disableDepth();
|
||||
|
||||
if (recipeMemory.isLocked(slotNumber)) {
|
||||
TextureManagerForestry.getInstance().bindGuiTextureMap();
|
||||
manager.gui.drawTexturedModalRect(startX + xPos, startY + yPos, lockIcon, 16, 16);
|
||||
}
|
||||
|
||||
GlStateManager.enableDepth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
|
||||
if (!getItemStack().isEmpty()) {
|
||||
ContainerWorktable.sendRecipeClick(mouseButton, slotNumber);
|
||||
SoundUtil.playButtonClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.worktable.gui.widgets;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
Reference in new issue
Block a user