diff --git a/src/main/java/techreborn/Core.java b/src/main/java/techreborn/Core.java index 1f0862270..27700c679 100644 --- a/src/main/java/techreborn/Core.java +++ b/src/main/java/techreborn/Core.java @@ -206,9 +206,9 @@ public class Core { public void LoadPackets(RegisterPacketEvent event) { event.registerPacket(PacketAesu.class, Side.SERVER); event.registerPacket(PacketIdsu.class, Side.SERVER); - event.registerPacket(PacketSetRecipe.class, Side.SERVER); event.registerPacket(PacketRollingMachineLock.class, Side.SERVER); event.registerPacket(PacketFusionControlSize.class, Side.SERVER); + event.registerPacket(PacketAutoCraftingTableLock.class, Side.SERVER); } @Mod.EventHandler diff --git a/src/main/java/techreborn/client/GuiHandler.java b/src/main/java/techreborn/client/GuiHandler.java index 21174ea77..deaf45ad5 100644 --- a/src/main/java/techreborn/client/GuiHandler.java +++ b/src/main/java/techreborn/client/GuiHandler.java @@ -32,7 +32,7 @@ import net.minecraftforge.fml.common.network.IGuiHandler; import techreborn.client.container.ContainerDestructoPack; import techreborn.client.container.IContainerProvider; import techreborn.client.gui.*; -import techreborn.client.gui.autocrafting.GuiAutoCrafting; +import techreborn.client.gui.GuiAutoCrafting; import techreborn.tiles.*; import techreborn.tiles.fusionReactor.TileFusionControlComputer; import techreborn.tiles.generator.*; diff --git a/src/main/java/techreborn/client/gui/GuiAutoCrafting.java b/src/main/java/techreborn/client/gui/GuiAutoCrafting.java new file mode 100644 index 000000000..e1a1648d5 --- /dev/null +++ b/src/main/java/techreborn/client/gui/GuiAutoCrafting.java @@ -0,0 +1,106 @@ +/* + * This file is part of TechReborn, licensed under the MIT License (MIT). + * + * Copyright (c) 2018 TechReborn + * + * 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 techreborn.client.gui; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.client.renderer.RenderItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.util.ResourceLocation; +import reborncore.common.network.NetworkManager; +import techreborn.packets.PacketAutoCraftingTableLock; +import techreborn.tiles.tier1.TileAutoCraftingTable; + +import java.io.IOException; + +import static net.minecraft.item.ItemStack.EMPTY; + +/** + * Created by modmuss50 on 20/06/2017. + */ +public class GuiAutoCrafting extends GuiBase { + + static final ResourceLocation RECIPE_BOOK_TEXTURE = new ResourceLocation("textures/gui/recipe_book.png"); + boolean showGui = true; + TileAutoCraftingTable tileAutoCraftingTable; + + public GuiAutoCrafting(EntityPlayer player, TileAutoCraftingTable tile) { + super(player, tile, tile.createContainer(player)); + this.tileAutoCraftingTable = tile; + } + + public void renderItemStack(ItemStack stack, int x, int y) { + if (stack != EMPTY) { + GlStateManager.enableBlend(); + GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); + RenderHelper.enableGUIStandardItemLighting(); + + RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem(); + itemRenderer.renderItemAndEffectIntoGUI(stack, x, y); + + GlStateManager.disableLighting(); + } + } + + @Override + protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { + super.drawGuiContainerForegroundLayer(mouseX, mouseY); + IRecipe recipe = tileAutoCraftingTable.getIRecipe(); + if (recipe != null) { + renderItemStack(recipe.getRecipeOutput(), 95, 42); + } + final Layer layer = Layer.FOREGROUND; + this.builder.drawMultiEnergyBar(this, 9, 26, (int) this.tileAutoCraftingTable.getEnergy(), (int) this.tileAutoCraftingTable.getMaxPower(), mouseX, mouseY, 0, layer); + this.builder.drawProgressBar(this, tileAutoCraftingTable.getProgress(), tileAutoCraftingTable.getMaxProgress(), 120, 44, mouseX, mouseY, TRBuilder.ProgressDirection.RIGHT, layer); + } + + @Override + protected void drawGuiContainerBackgroundLayer(final float f, int mouseX, int mouseY) { + super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY); + final Layer layer = Layer.BACKGROUND; + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + drawSlot(28 + (i * 18), 25 + (j * 18), layer); + } + } + drawOutputSlot(145, 42, layer); + drawOutputSlot(95, 42, layer); + drawString("Inventory", 8, 82, 4210752, layer); + + this.builder.drawLockButton(this, 145, 4, mouseX, mouseY, layer, tileAutoCraftingTable.locked); + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { + if (this.builder.isInRect(145 + getGuiLeft(), 4 + getGuiTop(), 20, 12, mouseX, mouseY)) { + NetworkManager.sendToServer(new PacketAutoCraftingTableLock(tileAutoCraftingTable, !tileAutoCraftingTable.locked)); + return; + } + super.mouseClicked(mouseX, mouseY, mouseButton); + } +} diff --git a/src/main/java/techreborn/client/gui/GuiBase.java b/src/main/java/techreborn/client/gui/GuiBase.java index 022963c9c..64f87fd8c 100644 --- a/src/main/java/techreborn/client/gui/GuiBase.java +++ b/src/main/java/techreborn/client/gui/GuiBase.java @@ -35,6 +35,7 @@ import net.minecraftforge.fml.relauncher.SideOnly; import org.lwjgl.input.Keyboard; import reborncore.api.tile.IUpgradeable; import reborncore.common.tile.TileLegacyMachineBase; +import sun.plugin.javascript.navig4.Layer; import techreborn.client.container.builder.BuiltContainer; import techreborn.client.gui.slot.GuiSlotConfiguration; import techreborn.client.gui.widget.GuiButtonPowerBar; @@ -135,8 +136,9 @@ public class GuiBase extends GuiContainer { upgrades = true; } } - builder.drawSlotTab(this, guiLeft, guiTop, mouseX, mouseY, upgrades); - + if(getMachine().hasSlotConfig()){ + builder.drawSlotTab(this, guiLeft, guiTop, mouseX, mouseY, upgrades); + } } public boolean drawPlayerSlots() { @@ -152,7 +154,7 @@ public class GuiBase extends GuiContainer { protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { this.buttonList.clear(); drawTitle(); - if(showSlotConfig){ + if(showSlotConfig && getMachine().hasSlotConfig()){ GuiSlotConfiguration.draw(this, mouseX, mouseY); } @@ -160,7 +162,7 @@ public class GuiBase extends GuiContainer { if(!upgrades){ offset = 80; } - if (builder.isInRect(guiLeft - 19, guiTop + 92 - offset, 12, 12, mouseX, mouseY)) { + if (builder.isInRect(guiLeft - 19, guiTop + 92 - offset, 12, 12, mouseX, mouseY) && getMachine().hasSlotConfig()) { List list = new ArrayList<>(); list.add("Configure slots"); GuiUtils.drawHoveringText(list, mouseX - guiLeft , mouseY - guiTop , width, height, -1, mc.fontRenderer); @@ -211,7 +213,7 @@ public class GuiBase extends GuiContainer { @Override protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - if(showSlotConfig){ + if(showSlotConfig && getMachine().hasSlotConfig()){ if(GuiSlotConfiguration.mouseClicked(mouseX, mouseY, mouseButton, this)){ return; } @@ -221,7 +223,7 @@ public class GuiBase extends GuiContainer { @Override protected void mouseClickMove(int mouseX, int mouseY, int clickedMouseButton, long timeSinceLastClick) { - if(showSlotConfig){ + if(showSlotConfig && getMachine().hasSlotConfig()){ GuiSlotConfiguration.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick, this); } super.mouseClickMove(mouseX, mouseY, clickedMouseButton, timeSinceLastClick); @@ -233,13 +235,13 @@ public class GuiBase extends GuiContainer { if(!upgrades){ offset = 80; } - if(isPointInRegion(-26, 84 - offset, 30, 30, mouseX, mouseY)){ + if(isPointInRegion(-26, 84 - offset, 30, 30, mouseX, mouseY) && getMachine().hasSlotConfig()){ showSlotConfig = !showSlotConfig; if(!showSlotConfig){ GuiSlotConfiguration.reset(); } } - if(showSlotConfig){ + if(showSlotConfig && getMachine().hasSlotConfig()){ if(GuiSlotConfiguration.mouseReleased(mouseX, mouseY, state, this)){ return; } diff --git a/src/main/java/techreborn/client/gui/autocrafting/GuiAutoCrafting.java b/src/main/java/techreborn/client/gui/autocrafting/GuiAutoCrafting.java deleted file mode 100644 index cbe097de8..000000000 --- a/src/main/java/techreborn/client/gui/autocrafting/GuiAutoCrafting.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * This file is part of TechReborn, licensed under the MIT License (MIT). - * - * Copyright (c) 2018 TechReborn - * - * 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 techreborn.client.gui.autocrafting; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.RenderItem; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.ClickType; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.item.crafting.ShapedRecipes; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.oredict.ShapedOreRecipe; -import reborncore.common.network.NetworkManager; -import techreborn.client.gui.GuiBase; -import techreborn.client.gui.TRBuilder; -import techreborn.packets.PacketSetRecipe; -import techreborn.tiles.tier1.TileAutoCraftingTable; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import static net.minecraft.item.ItemStack.EMPTY; - -/** - * Created by modmuss50 on 20/06/2017. - */ -public class GuiAutoCrafting extends GuiBase { - - static final ResourceLocation RECIPE_BOOK_TEXTURE = new ResourceLocation("textures/gui/recipe_book.png"); - GuiAutoCraftingRecipeSlector recipeSlector = new GuiAutoCraftingRecipeSlector(); - boolean showGui = true; - InventoryCrafting dummyInv; - TileAutoCraftingTable tileAutoCraftingTable; - - public GuiAutoCrafting(EntityPlayer player, TileAutoCraftingTable tile) { - super(player, tile, tile.createContainer(player)); - this.tileAutoCraftingTable = tile; - } - - @Override - public void updateScreen() { - super.updateScreen(); - recipeSlector.tick(); - } - - public void renderItemStack(ItemStack stack, int x, int y) { - if (stack != EMPTY) { - GlStateManager.enableBlend(); - GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); - RenderHelper.enableGUIStandardItemLighting(); - - RenderItem itemRenderer = Minecraft.getMinecraft().getRenderItem(); - itemRenderer.renderItemAndEffectIntoGUI(stack, x, y); - - GlStateManager.disableLighting(); - } - } - - @Override - protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { - super.drawGuiContainerForegroundLayer(mouseX, mouseY); - IRecipe recipe = tileAutoCraftingTable.getIRecipe(); - if (recipe != null) { - renderItemStack(recipe.getRecipeOutput(), 95, 42); - } - final Layer layer = Layer.FOREGROUND; - this.builder.drawMultiEnergyBar(this, 9, 26, (int) this.tileAutoCraftingTable.getEnergy(), (int) this.tileAutoCraftingTable.getMaxPower(), mouseX, mouseY, 0, layer); - this.builder.drawProgressBar(this, tileAutoCraftingTable.getProgress(), tileAutoCraftingTable.getMaxProgress(), 120, 44, mouseX, mouseY, TRBuilder.ProgressDirection.RIGHT, layer); - - int mX = mouseX - getGuiLeft(); - int mY = mouseY - getGuiTop(); - - if (recipe != null && !tileAutoCraftingTable.customRecipe) { - if (builder.isInRect(91, 66, 23, 23, mX, mY)) { - List list = new ArrayList<>(); - list.add("Click to clear"); - net.minecraftforge.fml.client.config.GuiUtils.drawHoveringText(list, mX, mY, width, height, -1, mc.fontRenderer); - GlStateManager.disableLighting(); - GlStateManager.color(1, 1, 1, 1); - } - } - } - - //Based of vanilla code - public void renderRecipe(IRecipe recipe, int x, int y) { - RenderHelper.enableGUIStandardItemLighting(); - GlStateManager.enableAlpha(); - mc.getTextureManager().bindTexture(RECIPE_BOOK_TEXTURE); - - this.drawTexturedModalRect(x, y, 152, 78, 24, 24); - - int recipeWidth = 3; - int recipeHeight = 3; - if (recipe instanceof ShapedRecipes) { - ShapedRecipes shapedrecipes = (ShapedRecipes) recipe; - recipeWidth = shapedrecipes.getWidth(); - recipeHeight = shapedrecipes.getHeight(); - } - if (recipe instanceof ShapedOreRecipe) { - ShapedOreRecipe shapedrecipes = (ShapedOreRecipe) recipe; - recipeWidth = shapedrecipes.getRecipeWidth(); - recipeHeight = shapedrecipes.getRecipeHeight(); - } - Iterator ingredients = recipe.getIngredients().iterator(); - for (int rHeight = 0; rHeight < recipeHeight; ++rHeight) { - int j1 = 3 + rHeight * 7; - for (int rWidth = 0; rWidth < recipeWidth; ++rWidth) { - if (ingredients.hasNext()) { - ItemStack[] aitemstack = ingredients.next().getMatchingStacks(); - if (aitemstack.length != 0) { - int l1 = 3 + rWidth * 7; - GlStateManager.pushMatrix(); - int i2 = (int) ((float) (x + l1) / 0.42F - 3.0F); - int j2 = (int) ((float) (y + j1) / 0.42F - 3.0F); - GlStateManager.scale(0.42F, 0.42F, 1.0F); - GlStateManager.enableLighting(); - mc.getRenderItem().renderItemAndEffectIntoGUI(aitemstack[0], i2, j2); - GlStateManager.disableLighting(); - GlStateManager.popMatrix(); - } - } - } - } - GlStateManager.disableAlpha(); - RenderHelper.disableStandardItemLighting(); - } - - @Override - protected void drawGuiContainerBackgroundLayer(final float f, int mouseX, int mouseY) { - super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY); - final Layer layer = Layer.BACKGROUND; - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { - drawSlot(28 + (i * 18), 25 + (j * 18), layer); - } - } - drawOutputSlot(145, 42, layer); - drawOutputSlot(95, 42, layer); - drawString("Inventory", 8, 82, 4210752, layer); - - IRecipe recipe = tileAutoCraftingTable.getIRecipe(); - if (recipe != null && !tileAutoCraftingTable.customRecipe) { - renderRecipe(recipe, guiLeft + 91, 66 + guiTop); - } - } - - @Override - public void initGui() { - super.initGui(); - recipeSlector.setGuiAutoCrafting(this); - dummyInv = new InventoryCrafting(new Container() { - @Override - public boolean canInteractWith(EntityPlayer playerIn) { - return false; - } - }, 3, 3); - for (int i = 0; i < 9; i++) { - dummyInv.setInventorySlotContents(i, ItemStack.EMPTY); - } - this.recipeSlector.func_194303_a(this.width, this.height, Minecraft.getMinecraft(), false, dummyInv); - this.guiLeft = this.recipeSlector.updateScreenPosition(false, this.width, this.xSize); - } - - @Override - public void drawScreen(int mouseX, int mouseY, float partialTicks) { - if (showGui) { - this.recipeSlector.render(mouseX, mouseY, 0.1F); - super.drawScreen(mouseX, mouseY, partialTicks); - this.recipeSlector.renderGhostRecipe(this.guiLeft, this.guiTop, false, partialTicks); - } else { - super.drawScreen(mouseX, mouseY, partialTicks); - } - this.recipeSlector.renderTooltip(this.guiLeft, this.guiTop, mouseX, mouseY); - } - - @Override - protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException { - if (!this.recipeSlector.mouseClicked(mouseX, mouseY, mouseButton)) { - super.mouseClicked(mouseX, mouseY, mouseButton); - } - int mX = mouseX - getGuiLeft(); - int mY = mouseY - getGuiTop(); - - mc.getTextureManager().bindTexture(TRBuilder.GUI_SHEET); - if (builder.isInRect(91, 66, 23, 23, mX, mY)) { - setRecipe(null, true); - } - } - - @Override - protected void keyTyped(char typedChar, int keyCode) throws IOException { - if (!this.recipeSlector.keyPressed(typedChar, keyCode)) { - super.keyTyped(typedChar, keyCode); - } - } - - @Override - protected void handleMouseClick(Slot slotIn, int slotId, int mouseButton, ClickType type) { - super.handleMouseClick(slotIn, slotId, mouseButton, type); - this.recipeSlector.slotClicked(slotIn); - } - - @Override - public void onGuiClosed() { - this.recipeSlector.removed(); - super.onGuiClosed(); - } - - public void setRecipe(IRecipe recipe, boolean custom) { - tileAutoCraftingTable.setCurrentRecipe(recipe, custom); - NetworkManager.sendToServer(new PacketSetRecipe(tileAutoCraftingTable, recipe, custom)); - } - -} diff --git a/src/main/java/techreborn/client/gui/autocrafting/GuiAutoCraftingRecipeSlector.java b/src/main/java/techreborn/client/gui/autocrafting/GuiAutoCraftingRecipeSlector.java deleted file mode 100644 index 0428ee88c..000000000 --- a/src/main/java/techreborn/client/gui/autocrafting/GuiAutoCraftingRecipeSlector.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * This file is part of TechReborn, licensed under the MIT License (MIT). - * - * Copyright (c) 2018 TechReborn - * - * 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 techreborn.client.gui.autocrafting; - -import net.minecraft.client.gui.GuiButtonToggle; -import net.minecraft.client.gui.recipebook.GuiRecipeBook; -import net.minecraft.client.gui.recipebook.RecipeList; -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.item.crafting.IRecipe; - -/** - * Created by modmuss50 on 20/06/2017. - */ -public class GuiAutoCraftingRecipeSlector extends GuiRecipeBook { - - GuiAutoCrafting guiAutoCrafting; - - @Override - public void initVisuals(boolean p_193014_1_, InventoryCrafting p_193014_2_) { - super.initVisuals(p_193014_1_, p_193014_2_); - //Pulls the button off the screen as we dont need it - toggleRecipesBtn = new GuiButtonToggle(0, -1000, -1000, 26, 16, false); - toggleRecipesBtn.initTextureValues(152, 41, 28, 18, RECIPE_BOOK); - //recipeBook.setGuiOpen(true); - } - - @Override - public boolean isVisible() { - return true; - } - - public void setContainerRecipe(IRecipe recipe) { - guiAutoCrafting.setRecipe(recipe, false); - } - - @Override - public boolean mouseClicked(int p_191862_1_, int p_191862_2_, int p_191862_3_) { - if (this.isVisible()) { - if (this.recipeBookPage.mouseClicked(p_191862_1_, p_191862_2_, p_191862_3_, (this.width - 147) / 2 - this.xOffset, (this.height - 166) / 2, 147, 166)) { - IRecipe irecipe = this.recipeBookPage.getLastClickedRecipe(); - RecipeList recipelist = this.recipeBookPage.getLastClickedRecipeList(); - - if (irecipe != null && recipelist != null) { - if (!recipelist.isCraftable(irecipe) && this.ghostRecipe.getRecipe() == irecipe) { - return false; - } - this.ghostRecipe.clear(); - setContainerRecipe(irecipe); - } - return true; - } - } - return super.mouseClicked(p_191862_1_, p_191862_2_, p_191862_3_); - } - - public void setGuiAutoCrafting(GuiAutoCrafting guiAutoCrafting) { - this.guiAutoCrafting = guiAutoCrafting; - } -} diff --git a/src/main/java/techreborn/packets/PacketSetRecipe.java b/src/main/java/techreborn/packets/PacketAutoCraftingTableLock.java similarity index 64% rename from src/main/java/techreborn/packets/PacketSetRecipe.java rename to src/main/java/techreborn/packets/PacketAutoCraftingTableLock.java index 33d0a4e4c..be1aa3adf 100644 --- a/src/main/java/techreborn/packets/PacketSetRecipe.java +++ b/src/main/java/techreborn/packets/PacketAutoCraftingTableLock.java @@ -24,58 +24,46 @@ package techreborn.packets; -import net.minecraft.item.crafting.IRecipe; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; import reborncore.common.network.ExtendedPacketBuffer; import reborncore.common.network.INetworkPacket; import techreborn.tiles.tier1.TileAutoCraftingTable; +import techreborn.tiles.tier1.TileRollingMachine; import java.io.IOException; -/** - * Created by modmuss50 on 20/06/2017. - */ -public class PacketSetRecipe implements INetworkPacket { +public class PacketAutoCraftingTableLock implements INetworkPacket { - BlockPos pos; - ResourceLocation recipe; - boolean custom; + BlockPos machinePos; + boolean locked; - public PacketSetRecipe(TileAutoCraftingTable tile, IRecipe recipe, boolean custom) { - this.pos = tile.getPos(); - if (recipe == null) { - this.recipe = new ResourceLocation(""); - } else { - this.recipe = recipe.getRegistryName(); - } - this.custom = custom; + public PacketAutoCraftingTableLock(TileAutoCraftingTable machine, boolean locked) { + this.machinePos = machine.getPos(); + this.locked = locked; } - public PacketSetRecipe() { + public PacketAutoCraftingTableLock() { } @Override public void writeData(ExtendedPacketBuffer buffer) throws IOException { - buffer.writeBlockPos(pos); - buffer.writeResourceLocation(recipe); - buffer.writeBoolean(custom); + buffer.writeBlockPos(machinePos); + buffer.writeBoolean(locked); } @Override public void readData(ExtendedPacketBuffer buffer) throws IOException { - pos = buffer.readBlockPos(); - recipe = buffer.readResourceLocation(); - custom = buffer.readBoolean(); + machinePos = buffer.readBlockPos(); + locked = buffer.readBoolean(); } @Override - public void processData(PacketSetRecipe message, MessageContext context) { - TileEntity tileEntity = context.getServerHandler().player.world.getTileEntity(message.pos); - if (tileEntity instanceof TileAutoCraftingTable) { - ((TileAutoCraftingTable) tileEntity).setCurrentRecipe(message.recipe, message.custom); + public void processData(PacketAutoCraftingTableLock message, MessageContext context) { + TileEntity tileEntity = context.getServerHandler().player.world.getTileEntity(machinePos); + if(tileEntity instanceof TileAutoCraftingTable){ + ((TileAutoCraftingTable) tileEntity).locked = locked; } } } diff --git a/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java b/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java index c28c64b94..99a75aa31 100644 --- a/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java +++ b/src/main/java/techreborn/tiles/tier1/TileAutoCraftingTable.java @@ -36,13 +36,13 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundCategory; -import net.minecraftforge.fml.common.registry.ForgeRegistries; import org.apache.commons.lang3.tuple.Pair; import reborncore.api.IToolDrop; import reborncore.api.tile.IInventoryProvider; import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.registration.RebornRegistry; import reborncore.common.registration.impl.ConfigRegistry; +import reborncore.common.tile.SlotConfiguration; import reborncore.common.util.Inventory; import reborncore.common.util.ItemUtils; import techreborn.client.container.IContainerProvider; @@ -55,80 +55,52 @@ import techreborn.lib.ModInfo; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; +import java.util.Objects; /** * Created by modmuss50 on 20/06/2017. */ @RebornRegistry(modID = ModInfo.MOD_ID) public class TileAutoCraftingTable extends TilePowerAcceptor - implements IToolDrop, IInventoryProvider, IContainerProvider { - + implements IToolDrop, IInventoryProvider, IContainerProvider { + @ConfigRegistry(config = "machines", category = "autocrafter", key = "AutoCrafterInput", comment = "AutoCrafting Table Max Input (Value in EU)") public static int maxInput = 32; @ConfigRegistry(config = "machines", category = "autocrafter", key = "AutoCrafterMaxEnergy", comment = "AutoCrafting Table Max Energy (Value in EU)") public static int maxEnergy = 10_000; - ResourceLocation currentRecipe; - public Inventory inventory = new Inventory(11, "TileAutoCraftingTable", 64, this); public int progress; public int maxProgress = 120; public int euTick = 10; - public Pair cachedRecipe; - public boolean customRecipe = false; + InventoryCrafting inventoryCrafting = null; IRecipe lastCustomRecipe = null; - + IRecipe lastRecipe = null; + + public boolean locked = true; + public TileAutoCraftingTable() { super(); } - public void setCurrentRecipe(IRecipe recipe, boolean customRecipe) { - if (recipe != null) { - currentRecipe = recipe.getRegistryName(); - } else { - currentRecipe = null; - } - - // Disabled due to performance issues - //this.customRecipe = customRecipe; - this.customRecipe = false; - cachedRecipe = null; - } - - public void setCurrentRecipe(ResourceLocation recipe, boolean customRecipe) { - currentRecipe = recipe; - // Disabled due to performance issues - //this.customRecipe = customRecipe; - this.customRecipe = false; - cachedRecipe = null; - } - @Nullable public IRecipe getIRecipe() { - if (customRecipe) { - InventoryCrafting crafting = getCraftingInventory(); - if(!crafting.isEmpty()){ - for (IRecipe testRecipe : CraftingManager.REGISTRY) { - if (testRecipe.matches(crafting, world)) { - return testRecipe; - } + InventoryCrafting crafting = getCraftingInventory(); + if (!crafting.isEmpty()) { + if(lastRecipe != null){ + if(lastRecipe.matches(crafting, world)){ + return lastRecipe; + } + } + for (IRecipe testRecipe : CraftingManager.REGISTRY) { + if (testRecipe.matches(crafting, world)) { + lastRecipe = testRecipe; + return testRecipe; } } } - if (currentRecipe == null) { - return null; - } - if (cachedRecipe == null || !cachedRecipe.getLeft().equals(currentRecipe)) { - IRecipe recipe = ForgeRegistries.RECIPES.getValue(currentRecipe); - if (recipe != null) { - cachedRecipe = Pair.of(currentRecipe, recipe); - return recipe; - } - cachedRecipe = null; - return null; - } - return cachedRecipe.getRight(); + return null; } public InventoryCrafting getCraftingInventory() { @@ -145,11 +117,8 @@ public class TileAutoCraftingTable extends TilePowerAcceptor } return inventoryCrafting; } - + public boolean canMake(IRecipe recipe) { - if (customRecipe) { - recipe = getIRecipe(); - } if (recipe != null && recipe.canFit(3, 3)) { boolean missingOutput = false; int[] stacksInSlots = new int[9]; @@ -161,14 +130,14 @@ public class TileAutoCraftingTable extends TilePowerAcceptor boolean foundIngredient = false; for (int i = 0; i < 9; i++) { ItemStack stack = inventory.getStackInSlot(i); - int requiredSize = customRecipe ? 1 : 0; - if(stack.getMaxStackSize() == 1){ + int requiredSize = locked ? 1 : 0; + if (stack.getMaxStackSize() == 1) { requiredSize = 0; } if (stacksInSlots[i] > requiredSize) { if (ingredient.apply(stack)) { - if(stack.getItem().getContainerItem() != null){ - if(!hasRoomForExtraItem(stack.getItem().getContainerItem(stack))){ + if (stack.getItem().getContainerItem() != null) { + if (!hasRoomForExtraItem(stack.getItem().getContainerItem(stack))) { continue; } } @@ -193,9 +162,9 @@ public class TileAutoCraftingTable extends TilePowerAcceptor return false; } - boolean hasRoomForExtraItem(ItemStack stack){ + boolean hasRoomForExtraItem(ItemStack stack) { ItemStack extraOutputSlot = getStackInSlot(10); - if(extraOutputSlot.isEmpty()){ + if (extraOutputSlot.isEmpty()) { return true; } return hasOutputSpace(stack, 10); @@ -215,17 +184,12 @@ public class TileAutoCraftingTable extends TilePowerAcceptor } public boolean make(IRecipe recipe) { - IRecipe recipe2 = recipe; - if (canMake(recipe2)) { - if (recipe2 == null && customRecipe) { - if (lastCustomRecipe == null) { - return false; - }//Should be uptodate as we just set it in canMake - recipe = lastCustomRecipe; - } - else if (recipe2 != null) { - for (int i = 0; i < recipe2.getIngredients().size(); i++) { - Ingredient ingredient = recipe2.getIngredients().get(i); + if (canMake(recipe)) { + if (recipe == null) { + return false; + } else if (recipe != null) { + for (int i = 0; i < recipe.getIngredients().size(); i++) { + Ingredient ingredient = recipe.getIngredients().get(i); //Looks for the best slot to take it from ItemStack bestSlot = inventory.getStackInSlot(i); if (ingredient.apply(bestSlot)) { @@ -244,12 +208,12 @@ public class TileAutoCraftingTable extends TilePowerAcceptor } ItemStack output = inventory.getStackInSlot(9); //TODO fire forge recipe event - ItemStack ouputStack = recipe2.getCraftingResult(getCraftingInventory()); + ItemStack ouputStack = recipe.getCraftingResult(getCraftingInventory()); if (output.isEmpty()) { inventory.setInventorySlotContents(9, ouputStack.copy()); } else { //TODO use ouputStack in someway? - output.grow(recipe2.getRecipeOutput().getCount()); + output.grow(recipe.getRecipeOutput().getCount()); } return true; } @@ -257,14 +221,14 @@ public class TileAutoCraftingTable extends TilePowerAcceptor return false; } - private void handleContainerItem(ItemStack stack){ - if(stack.getItem().hasContainerItem(stack)){ + private void handleContainerItem(ItemStack stack) { + if (stack.getItem().hasContainerItem(stack)) { ItemStack containerItem = stack.getItem().getContainerItem(stack); ItemStack extraOutputSlot = getStackInSlot(10); - if(hasOutputSpace(containerItem, 10)){ - if(extraOutputSlot.isEmpty()){ + if (hasOutputSpace(containerItem, 10)) { + if (extraOutputSlot.isEmpty()) { setInventorySlotContents(10, containerItem.copy()); - } else if(ItemUtils.isItemEqual(extraOutputSlot, containerItem, true, true) && extraOutputSlot.getMaxStackSize() < extraOutputSlot.getCount() + containerItem.getCount()) { + } else if (ItemUtils.isItemEqual(extraOutputSlot, containerItem, true, true) && extraOutputSlot.getMaxStackSize() < extraOutputSlot.getCount() + containerItem.getCount()) { extraOutputSlot.grow(1); } } @@ -280,7 +244,7 @@ public class TileAutoCraftingTable extends TilePowerAcceptor } return false; } - + public boolean isItemValidForRecipeSlot(IRecipe recipe, ItemStack stack, int slotID) { if (recipe == null) { return true; @@ -328,7 +292,7 @@ public class TileAutoCraftingTable extends TilePowerAcceptor } return -1; } - + public int getProgress() { return progress; } @@ -356,7 +320,7 @@ public class TileAutoCraftingTable extends TilePowerAcceptor return; } IRecipe recipe = getIRecipe(); - if (recipe != null || customRecipe) { + if (recipe != null) { if (progress >= maxProgress) { if (make(recipe)) { progress = 0; @@ -367,10 +331,12 @@ public class TileAutoCraftingTable extends TilePowerAcceptor progress++; if (progress == 1) { world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), ModSounds.AUTO_CRAFTING, - SoundCategory.BLOCKS, 0.3F, 0.8F); + SoundCategory.BLOCKS, 0.3F, 0.8F); } useEnergy(euTick); } + } else { + progress = 0; } } } @@ -379,6 +345,15 @@ public class TileAutoCraftingTable extends TilePowerAcceptor } } + //Easyest way to sync back to the client + public int getLockedInt() { + return locked ? 1 : 0; + } + + public void setLockedInt(int lockedInt) { + locked = lockedInt == 1; + } + @Override public double getBaseMaxPower() { return maxEnergy; @@ -403,35 +378,23 @@ public class TileAutoCraftingTable extends TilePowerAcceptor public boolean canProvideEnergy(EnumFacing enumFacing) { return false; } - + @Override public NBTTagCompound writeToNBT(NBTTagCompound tag) { - if (currentRecipe != null) { - tag.setString("currentRecipe", currentRecipe.toString()); - } - // Disable due to performance issues - // tag.setBoolean("customRecipe", customRecipe); - tag.setBoolean("customRecipe", false); return super.writeToNBT(tag); } @Override public void readFromNBT(NBTTagCompound tag) { - if (tag.hasKey("currentRecipe")) { - currentRecipe = new ResourceLocation(tag.getString("currentRecipe")); - } - // Disabled due to performance issues - //customRecipe = tag.getBoolean("customRecipe"); - customRecipe = false; super.readFromNBT(tag); } - + // TileLegacyMachineBase @Override public boolean canBeUpgraded() { return false; } - + @Override public boolean isItemValidForSlot(int index, ItemStack stack) { int bestSlot = findBestSlotForStack(getIRecipe(), stack); @@ -441,23 +404,48 @@ public class TileAutoCraftingTable extends TilePowerAcceptor return super.isItemValidForSlot(index, stack); } + @Override + public int[] getSlotsForFace(EnumFacing side) { + return new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + } + + @Override + public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction) { + if(index > 8){ + return false; + } + int bestSlot = findBestSlotForStack(getIRecipe(), stack); + if (bestSlot != -1) { + return index == bestSlot; + } + return true; + } + + @Override + public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) { + if(index > 8){ + return true; + } + return false; + } + //This machine doesnt have a facing @Override public EnumFacing getFacingEnum() { return EnumFacing.NORTH; } - + // IToolDrop @Override public ItemStack getToolDrop(EntityPlayer playerIn) { return new ItemStack(ModBlocks.AUTO_CRAFTING_TABLE, 1); } - + // IInventoryProvider @Override public IInventory getInventory() { return inventory; - } + } // IContainerProvider @Override @@ -470,6 +458,12 @@ public class TileAutoCraftingTable extends TilePowerAcceptor .outputSlot(9, 145, 42).outputSlot(10, 145, 70).syncEnergyValue() .syncIntegerValue(this::getProgress, this::setProgress) .syncIntegerValue(this::getMaxProgress, this::setMaxProgress) + .syncIntegerValue(this::getLockedInt, this::setLockedInt) .addInventory().create(this); } + + @Override + public boolean hasSlotConfig() { + return false; + } }