From 42865951a92df69194fffa8545f099a5aabb30a4 Mon Sep 17 00:00:00 2001 From: Nedelosk Date: Sun, 7 Jan 2018 02:18:11 +0100 Subject: [PATCH] Move the worktable into a separate module --- .../java/forestry/core/gui/GuiIdRegistry.java | 4 +- .../forestry/core/gui/slots/SlotCrafter.java | 4 +- .../inventory/InventoryGhostCrafting.java | 47 +- .../forestry/core/recipes/RecipeUtil.java | 2 +- .../java/forestry/factory/ModuleFactory.java | 9 - .../factory/blocks/BlockRegistryFactory.java | 4 - .../factory/blocks/BlockTypeFactoryPlain.java | 4 +- .../factory/gui/ContainerFabricator.java | 2 +- .../network/PacketRegistryFactory.java | 11 +- .../factory/recipes/jei/FactoryJeiPlugin.java | 7 +- .../forestry/factory/tiles/TileCarpenter.java | 2 +- .../factory/tiles/TileFabricator.java | 2 +- .../forestry/modules/ForestryModuleUids.java | 1 + .../java/forestry/modules/ModuleManager.java | 6 +- .../forestry/worktable/ModuleWorktable.java | 58 +++ .../blocks/BlockRegistryWorktable.java | 13 + .../worktable/blocks/BlockTypeWorktable.java | 29 ++ .../worktable/blocks/BlockWorktable.java | 20 + .../blocks}/package-info.java | 7 +- .../worktable/compat/WorktableJeiPlugin.java | 42 ++ .../WorktableRecipeTransferHandler.java | 21 +- .../worktable/compat/package-info.java | 10 + .../gui/ContainerWorktable.java | 20 +- .../gui/GuiWorktable.java | 10 +- .../forestry/worktable/gui/package-info.java | 10 + .../gui/widgets/ClearWorktable.java | 70 +-- .../gui/widgets/MemorizedRecipeSlot.java | 121 ++--- .../worktable/gui/widgets/package-info.java | 10 + .../inventory/InventoryCraftingForestry.java | 84 ++-- .../inventory/InventoryWorktable.java | 61 +-- .../worktable/inventory/package-info.java | 10 + .../network/PacketRegistryWorktable.java | 35 ++ .../worktable/network/package-info.java | 10 + .../packets/PacketWorktableMemoryUpdate.java | 122 ++--- .../packets/PacketWorktableRecipeRequest.java | 13 +- .../packets/PacketWorktableRecipeUpdate.java | 130 +++--- .../network/packets/package-info.java | 10 + .../java/forestry/worktable/package-info.java | 10 + .../recipes/MemorizedRecipe.java | 438 +++++++++--------- .../recipes/RecipeMemory.java | 10 +- .../worktable/recipes/package-info.java | 10 + .../tiles/ICrafterWorktable.java | 46 +- .../tiles/TileWorktable.java | 16 +- .../worktable/tiles/package-info.java | 10 + 44 files changed, 915 insertions(+), 646 deletions(-) rename src/main/java/forestry/{factory => core}/inventory/InventoryGhostCrafting.java (89%) create mode 100644 src/main/java/forestry/worktable/ModuleWorktable.java create mode 100644 src/main/java/forestry/worktable/blocks/BlockRegistryWorktable.java create mode 100644 src/main/java/forestry/worktable/blocks/BlockTypeWorktable.java create mode 100644 src/main/java/forestry/worktable/blocks/BlockWorktable.java rename src/main/java/forestry/{factory/gui/widgets => worktable/blocks}/package-info.java (52%) create mode 100644 src/main/java/forestry/worktable/compat/WorktableJeiPlugin.java rename src/main/java/forestry/{factory/recipes/jei => worktable/compat}/WorktableRecipeTransferHandler.java (89%) create mode 100644 src/main/java/forestry/worktable/compat/package-info.java rename src/main/java/forestry/{factory => worktable}/gui/ContainerWorktable.java (90%) mode change 100755 => 100644 rename src/main/java/forestry/{factory => worktable}/gui/GuiWorktable.java (91%) mode change 100755 => 100644 create mode 100644 src/main/java/forestry/worktable/gui/package-info.java rename src/main/java/forestry/{factory => worktable}/gui/widgets/ClearWorktable.java (90%) rename src/main/java/forestry/{factory => worktable}/gui/widgets/MemorizedRecipeSlot.java (91%) create mode 100644 src/main/java/forestry/worktable/gui/widgets/package-info.java rename src/main/java/forestry/{factory => worktable}/inventory/InventoryCraftingForestry.java (92%) rename src/main/java/forestry/{factory => worktable}/inventory/InventoryWorktable.java (91%) create mode 100644 src/main/java/forestry/worktable/inventory/package-info.java create mode 100644 src/main/java/forestry/worktable/network/PacketRegistryWorktable.java create mode 100644 src/main/java/forestry/worktable/network/package-info.java rename src/main/java/forestry/{factory => worktable}/network/packets/PacketWorktableMemoryUpdate.java (91%) rename src/main/java/forestry/{factory => worktable}/network/packets/PacketWorktableRecipeRequest.java (92%) rename src/main/java/forestry/{factory => worktable}/network/packets/PacketWorktableRecipeUpdate.java (91%) create mode 100644 src/main/java/forestry/worktable/network/packets/package-info.java create mode 100644 src/main/java/forestry/worktable/package-info.java rename src/main/java/forestry/{factory => worktable}/recipes/MemorizedRecipe.java (95%) rename src/main/java/forestry/{factory => worktable}/recipes/RecipeMemory.java (99%) create mode 100644 src/main/java/forestry/worktable/recipes/package-info.java rename src/main/java/forestry/{factory => worktable}/tiles/ICrafterWorktable.java (81%) rename src/main/java/forestry/{factory => worktable}/tiles/TileWorktable.java (95%) mode change 100755 => 100644 create mode 100644 src/main/java/forestry/worktable/tiles/package-info.java diff --git a/src/main/java/forestry/core/gui/GuiIdRegistry.java b/src/main/java/forestry/core/gui/GuiIdRegistry.java index a52da4b77..ff87193c6 100644 --- a/src/main/java/forestry/core/gui/GuiIdRegistry.java +++ b/src/main/java/forestry/core/gui/GuiIdRegistry.java @@ -28,9 +28,9 @@ import forestry.apiculture.tiles.TileBeeHouse; import forestry.core.items.ItemAlyzer; import forestry.core.items.ItemSolderingIron; import forestry.core.tiles.TileAnalyzer; -import forestry.database.tiles.TileDatabase; import forestry.core.tiles.TileEscritoire; import forestry.core.tiles.TileNaturalistChest; +import forestry.database.tiles.TileDatabase; import forestry.energy.tiles.TileEngineBiogas; import forestry.energy.tiles.TileEngineElectric; import forestry.energy.tiles.TileEnginePeat; @@ -44,7 +44,6 @@ import forestry.factory.tiles.TileMoistener; import forestry.factory.tiles.TileRaintank; import forestry.factory.tiles.TileSqueezer; import forestry.factory.tiles.TileStill; -import forestry.factory.tiles.TileWorktable; import forestry.farming.tiles.TileFarm; import forestry.greenhouse.items.ItemCamouflageSprayCan; import forestry.greenhouse.tiles.TileClimatiser; @@ -57,6 +56,7 @@ import forestry.mail.tiles.TileStampCollector; import forestry.mail.tiles.TileTrader; import forestry.storage.items.ItemBackpack; import forestry.storage.items.ItemBackpackNaturalist; +import forestry.worktable.tiles.TileWorktable; public class GuiIdRegistry { private static final Map, GuiId> classMap = new HashMap<>(); diff --git a/src/main/java/forestry/core/gui/slots/SlotCrafter.java b/src/main/java/forestry/core/gui/slots/SlotCrafter.java index c426de706..f940633ae 100755 --- a/src/main/java/forestry/core/gui/slots/SlotCrafter.java +++ b/src/main/java/forestry/core/gui/slots/SlotCrafter.java @@ -19,8 +19,8 @@ import net.minecraft.inventory.SlotCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; -import forestry.factory.inventory.InventoryCraftingForestry; -import forestry.factory.tiles.ICrafterWorktable; +import forestry.worktable.inventory.InventoryCraftingForestry; +import forestry.worktable.tiles.ICrafterWorktable; public class SlotCrafter extends Slot { diff --git a/src/main/java/forestry/factory/inventory/InventoryGhostCrafting.java b/src/main/java/forestry/core/inventory/InventoryGhostCrafting.java similarity index 89% rename from src/main/java/forestry/factory/inventory/InventoryGhostCrafting.java rename to src/main/java/forestry/core/inventory/InventoryGhostCrafting.java index b2484ab17..faa65b24a 100644 --- a/src/main/java/forestry/factory/inventory/InventoryGhostCrafting.java +++ b/src/main/java/forestry/core/inventory/InventoryGhostCrafting.java @@ -1,24 +1,23 @@ -/******************************************************************************* - * 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.factory.inventory; - -import forestry.core.inventory.InventoryAdapterTile; -import net.minecraft.tileentity.TileEntity; - -public class InventoryGhostCrafting extends InventoryAdapterTile { - public final static int SLOT_CRAFTING_1 = 0; - public final static int SLOT_CRAFTING_COUNT = 9; - public final static int SLOT_CRAFTING_RESULT = 9; - - public InventoryGhostCrafting(T tile, int size) { - super(tile, size, "CraftItems"); - } -} +/******************************************************************************* + * 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.core.inventory; + +import net.minecraft.tileentity.TileEntity; + +public class InventoryGhostCrafting extends InventoryAdapterTile { + public final static int SLOT_CRAFTING_1 = 0; + public final static int SLOT_CRAFTING_COUNT = 9; + public final static int SLOT_CRAFTING_RESULT = 9; + + public InventoryGhostCrafting(T tile, int size) { + super(tile, size, "CraftItems"); + } +} diff --git a/src/main/java/forestry/core/recipes/RecipeUtil.java b/src/main/java/forestry/core/recipes/RecipeUtil.java index 24a08719d..ecd088808 100755 --- a/src/main/java/forestry/core/recipes/RecipeUtil.java +++ b/src/main/java/forestry/core/recipes/RecipeUtil.java @@ -35,7 +35,7 @@ import forestry.api.recipes.RecipeManagers; import forestry.core.config.Constants; import forestry.core.fluids.Fluids; import forestry.core.utils.ItemStackUtil; -import forestry.factory.inventory.InventoryCraftingForestry; +import forestry.worktable.inventory.InventoryCraftingForestry; public abstract class RecipeUtil { diff --git a/src/main/java/forestry/factory/ModuleFactory.java b/src/main/java/forestry/factory/ModuleFactory.java index 0672efb6e..964e40f12 100644 --- a/src/main/java/forestry/factory/ModuleFactory.java +++ b/src/main/java/forestry/factory/ModuleFactory.java @@ -233,7 +233,6 @@ public class ModuleFactory extends BlankForestryModule { blocks.fabricator.init(); blocks.raintank.init(); - blocks.worktable.init(); Circuits.machineSpeedUpgrade1 = new CircuitSpeedUpgrade("machine.speed.boost.1", 0.125f, 0.05f); Circuits.machineSpeedUpgrade2 = new CircuitSpeedUpgrade("machine.speed.boost.2", 0.250f, 0.10f); @@ -624,13 +623,5 @@ public class ModuleFactory extends BlankForestryModule { '#', "blockGlass", 'X', "ingotIron", 'Y', coreItems.sturdyCasing); - - RecipeUtil.addRecipe("worktable", blocks.worktable, - "B", - "W", - "C", - 'B', Items.BOOK, - 'W', "craftingTableWood", - 'C', "chestWood"); } } diff --git a/src/main/java/forestry/factory/blocks/BlockRegistryFactory.java b/src/main/java/forestry/factory/blocks/BlockRegistryFactory.java index fb805d770..661b54ff0 100644 --- a/src/main/java/forestry/factory/blocks/BlockRegistryFactory.java +++ b/src/main/java/forestry/factory/blocks/BlockRegistryFactory.java @@ -26,7 +26,6 @@ public class BlockRegistryFactory extends BlockRegistry { public final BlockFactoryPlain fabricator; public final BlockFactoryPlain raintank; - public final BlockFactoryPlain worktable; public BlockRegistryFactory() { bottler = new BlockFactoryTESR(BlockTypeFactoryTesr.BOTTLER); @@ -58,8 +57,5 @@ public class BlockRegistryFactory extends BlockRegistry { raintank = new BlockFactoryPlain(BlockTypeFactoryPlain.RAINTANK); registerBlock(raintank, new ItemBlockNBT(raintank), "raintank"); - - worktable = new BlockFactoryPlain(BlockTypeFactoryPlain.WORKTABLE); - registerBlock(worktable, new ItemBlockNBT(worktable), "worktable"); } } diff --git a/src/main/java/forestry/factory/blocks/BlockTypeFactoryPlain.java b/src/main/java/forestry/factory/blocks/BlockTypeFactoryPlain.java index 2b78ba1d5..adf9f4b1f 100644 --- a/src/main/java/forestry/factory/blocks/BlockTypeFactoryPlain.java +++ b/src/main/java/forestry/factory/blocks/BlockTypeFactoryPlain.java @@ -16,12 +16,10 @@ import forestry.core.blocks.MachineProperties; import forestry.core.tiles.TileForestry; import forestry.factory.tiles.TileFabricator; import forestry.factory.tiles.TileRaintank; -import forestry.factory.tiles.TileWorktable; public enum BlockTypeFactoryPlain implements IBlockType { FABRICATOR(TileFabricator.class, "fabricator"), - RAINTANK(TileRaintank.class, "raintank"), - WORKTABLE(TileWorktable.class, "worktable"); + RAINTANK(TileRaintank.class, "raintank"); public static final BlockTypeFactoryPlain[] VALUES = values(); diff --git a/src/main/java/forestry/factory/gui/ContainerFabricator.java b/src/main/java/forestry/factory/gui/ContainerFabricator.java index fcb57e8d6..ac696658f 100755 --- a/src/main/java/forestry/factory/gui/ContainerFabricator.java +++ b/src/main/java/forestry/factory/gui/ContainerFabricator.java @@ -23,8 +23,8 @@ import forestry.core.gui.IContainerCrafting; import forestry.core.gui.slots.SlotCraftMatrix; import forestry.core.gui.slots.SlotFiltered; import forestry.core.gui.slots.SlotOutput; +import forestry.core.inventory.InventoryGhostCrafting; import forestry.factory.inventory.InventoryFabricator; -import forestry.factory.inventory.InventoryGhostCrafting; import forestry.factory.tiles.TileFabricator; public class ContainerFabricator extends ContainerLiquidTanks implements IContainerCrafting { diff --git a/src/main/java/forestry/factory/network/PacketRegistryFactory.java b/src/main/java/forestry/factory/network/PacketRegistryFactory.java index 790f9d2bf..3854b26d0 100644 --- a/src/main/java/forestry/factory/network/PacketRegistryFactory.java +++ b/src/main/java/forestry/factory/network/PacketRegistryFactory.java @@ -10,29 +10,24 @@ ******************************************************************************/ package forestry.factory.network; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + import forestry.core.network.IPacketRegistry; import forestry.core.network.PacketIdClient; import forestry.core.network.PacketIdServer; import forestry.factory.network.packets.PacketRecipeTransferRequest; import forestry.factory.network.packets.PacketRecipeTransferUpdate; -import forestry.factory.network.packets.PacketWorktableMemoryUpdate; -import forestry.factory.network.packets.PacketWorktableRecipeRequest; -import forestry.factory.network.packets.PacketWorktableRecipeUpdate; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; public class PacketRegistryFactory implements IPacketRegistry { @Override public void registerPacketsServer() { - PacketIdServer.WORKTABLE_RECIPE_REQUEST.setPacketHandler(new PacketWorktableRecipeRequest.Handler()); PacketIdServer.RECIPE_TRANSFER_REQUEST.setPacketHandler(new PacketRecipeTransferRequest.Handler()); } @Override @SideOnly(Side.CLIENT) public void registerPacketsClient() { - PacketIdClient.WORKTABLE_MEMORY_UPDATE.setPacketHandler(new PacketWorktableMemoryUpdate.Handler()); - PacketIdClient.WORKTABLE_CRAFTING_UPDATE.setPacketHandler(new PacketWorktableRecipeUpdate.Handler()); PacketIdClient.RECIPE_TRANSFER_UPDATE.setPacketHandler(new PacketRecipeTransferUpdate.Handler()); } } diff --git a/src/main/java/forestry/factory/recipes/jei/FactoryJeiPlugin.java b/src/main/java/forestry/factory/recipes/jei/FactoryJeiPlugin.java index cabccf989..38b71736a 100644 --- a/src/main/java/forestry/factory/recipes/jei/FactoryJeiPlugin.java +++ b/src/main/java/forestry/factory/recipes/jei/FactoryJeiPlugin.java @@ -48,7 +48,6 @@ import forestry.factory.recipes.jei.squeezer.SqueezerRecipeMaker; import forestry.factory.recipes.jei.still.StillRecipeCategory; import forestry.factory.recipes.jei.still.StillRecipeMaker; import forestry.modules.ForestryModuleUids; - import mezz.jei.api.IGuiHelper; import mezz.jei.api.IJeiHelpers; import mezz.jei.api.IModPlugin; @@ -56,7 +55,6 @@ import mezz.jei.api.IModRegistry; import mezz.jei.api.JEIPlugin; import mezz.jei.api.gui.BlankAdvancedGuiHandler; import mezz.jei.api.recipe.IRecipeCategoryRegistration; -import mezz.jei.api.recipe.VanillaRecipeCategoryUid; import mezz.jei.api.recipe.transfer.IRecipeTransferRegistry; @JEIPlugin @@ -130,16 +128,13 @@ public class FactoryJeiPlugin implements IModPlugin { registry.addRecipeCatalyst(new ItemStack(blocks.rainmaker), ForestryRecipeCategoryUid.RAINMAKER); registry.addRecipeCatalyst(new ItemStack(blocks.squeezer), ForestryRecipeCategoryUid.SQUEEZER); registry.addRecipeCatalyst(new ItemStack(blocks.still), ForestryRecipeCategoryUid.STILL); - registry.addRecipeCatalyst(new ItemStack(blocks.worktable), VanillaRecipeCategoryUid.CRAFTING); IRecipeTransferRegistry transferRegistry = registry.getRecipeTransferRegistry(); - transferRegistry.addRecipeTransferHandler(new WorktableRecipeTransferHandler(), VanillaRecipeCategoryUid.CRAFTING); transferRegistry.addRecipeTransferHandler(new CarpenterRecipeTransferHandler(), ForestryRecipeCategoryUid.CARPENTER); transferRegistry.addRecipeTransferHandler(new FabricatorRecipeTransferHandler(), ForestryRecipeCategoryUid.FABRICATOR); JeiUtil.addDescription(registry, - blocks.raintank, - blocks.worktable + blocks.raintank ); } diff --git a/src/main/java/forestry/factory/tiles/TileCarpenter.java b/src/main/java/forestry/factory/tiles/TileCarpenter.java index e444019c6..f7f66c5df 100644 --- a/src/main/java/forestry/factory/tiles/TileCarpenter.java +++ b/src/main/java/forestry/factory/tiles/TileCarpenter.java @@ -39,6 +39,7 @@ import forestry.core.fluids.FilteredTank; import forestry.core.fluids.FluidHelper; import forestry.core.fluids.TankManager; import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.inventory.InventoryGhostCrafting; import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.network.PacketBufferForestry; import forestry.core.recipes.RecipePair; @@ -50,7 +51,6 @@ import forestry.core.utils.InventoryUtil; import forestry.factory.gui.ContainerCarpenter; import forestry.factory.gui.GuiCarpenter; import forestry.factory.inventory.InventoryCarpenter; -import forestry.factory.inventory.InventoryGhostCrafting; import forestry.factory.recipes.CarpenterRecipeManager; public class TileCarpenter extends TilePowered implements ISidedInventory, ILiquidTankTile, IItemStackDisplay { diff --git a/src/main/java/forestry/factory/tiles/TileFabricator.java b/src/main/java/forestry/factory/tiles/TileFabricator.java index 331139f77..19745410f 100755 --- a/src/main/java/forestry/factory/tiles/TileFabricator.java +++ b/src/main/java/forestry/factory/tiles/TileFabricator.java @@ -42,6 +42,7 @@ import forestry.core.fluids.TankManager; import forestry.core.inventory.IInventoryAdapter; import forestry.core.inventory.InventoryAdapter; import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.inventory.InventoryGhostCrafting; import forestry.core.inventory.watchers.ISlotPickupWatcher; import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.items.ICraftingPlan; @@ -53,7 +54,6 @@ import forestry.core.utils.InventoryUtil; import forestry.factory.gui.ContainerFabricator; import forestry.factory.gui.GuiFabricator; import forestry.factory.inventory.InventoryFabricator; -import forestry.factory.inventory.InventoryGhostCrafting; import forestry.factory.recipes.FabricatorRecipeManager; import forestry.factory.recipes.FabricatorSmeltingRecipeManager; diff --git a/src/main/java/forestry/modules/ForestryModuleUids.java b/src/main/java/forestry/modules/ForestryModuleUids.java index b87e5c1f9..fe4f8c8c9 100644 --- a/src/main/java/forestry/modules/ForestryModuleUids.java +++ b/src/main/java/forestry/modules/ForestryModuleUids.java @@ -8,6 +8,7 @@ public class ForestryModuleUids { public static final String CORE = "core"; public static final String ENERGY = "energy"; public static final String FACTORY = "factory"; + public static final String WORKTABLE = "worktable"; public static final String FARMING = "farming"; public static final String GREENHOUSE = "greenhouse"; public static final String FLUIDS = "fluids"; diff --git a/src/main/java/forestry/modules/ModuleManager.java b/src/main/java/forestry/modules/ModuleManager.java index 125c5729d..2f9c83bd5 100644 --- a/src/main/java/forestry/modules/ModuleManager.java +++ b/src/main/java/forestry/modules/ModuleManager.java @@ -15,6 +15,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Lists; +import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -93,6 +94,7 @@ public class ModuleManager implements IModuleManager { return ImmutableSet.copyOf(sortedModules.values()); } + @Nullable private static IForestryModule getModuleCore(List forestryModules) { for (IForestryModule module : forestryModules) { ForestryModule info = module.getClass().getAnnotation(ForestryModule.class); @@ -110,7 +112,7 @@ public class ModuleManager implements IModuleManager { Set toLoad = new HashSet<>(); Set modulesToLoad = new HashSet<>(); - ImmutableList allModules = ImmutableList.copyOf(modules.values().stream().flatMap(x -> x.stream()).collect(Collectors.toList())); + ImmutableList allModules = ImmutableList.copyOf(modules.values().stream().flatMap(Collection::stream).collect(Collectors.toList())); for(IModuleContainer container : moduleContainers.values()){ String containerID = container.getID(); @@ -169,7 +171,7 @@ public class ModuleManager implements IModuleManager { changed = true; ForestryModule info = module.getClass().getAnnotation(ForestryModule.class); String moduleId = info.moduleID(); - toLoad.remove(moduleId); + toLoad.remove(new ResourceLocation(moduleId)); Log.warning("Module {} is missing dependencies: {}", moduleId, dependencies); } } diff --git a/src/main/java/forestry/worktable/ModuleWorktable.java b/src/main/java/forestry/worktable/ModuleWorktable.java new file mode 100644 index 000000000..d0ce23586 --- /dev/null +++ b/src/main/java/forestry/worktable/ModuleWorktable.java @@ -0,0 +1,58 @@ +package forestry.worktable; + +import com.google.common.base.Preconditions; + +import javax.annotation.Nullable; + +import net.minecraft.init.Items; + +import forestry.api.modules.ForestryModule; +import forestry.core.config.Constants; +import forestry.core.network.IPacketRegistry; +import forestry.core.recipes.RecipeUtil; +import forestry.modules.BlankForestryModule; +import forestry.modules.ForestryModuleUids; +import forestry.worktable.blocks.BlockRegistryWorktable; +import forestry.worktable.network.PacketRegistryWorktable; + +@ForestryModule(containerID = Constants.MOD_ID, moduleID = ForestryModuleUids.WORKTABLE, name = "Worktable", author = "Nedelosk", url = Constants.URL, unlocalizedDescription = "for.module.worktable.description") +public class ModuleWorktable extends BlankForestryModule { + @Nullable + private static BlockRegistryWorktable blocks; + + public static BlockRegistryWorktable getBlocks() { + Preconditions.checkState(blocks != null); + return blocks; + } + + @Override + public void registerItemsAndBlocks() { + blocks = new BlockRegistryWorktable(); + } + + + @Override + public IPacketRegistry getPacketRegistry() { + return new PacketRegistryWorktable(); + } + + @Override + public void doInit() { + BlockRegistryWorktable blocks = getBlocks(); + + blocks.worktable.init(); + } + + @Override + public void registerRecipes() { + BlockRegistryWorktable blocks = getBlocks(); + + RecipeUtil.addRecipe("worktable", blocks.worktable, + "B", + "W", + "C", + 'B', Items.BOOK, + 'W', "craftingTableWood", + 'C', "chestWood"); + } +} diff --git a/src/main/java/forestry/worktable/blocks/BlockRegistryWorktable.java b/src/main/java/forestry/worktable/blocks/BlockRegistryWorktable.java new file mode 100644 index 000000000..01aadef0b --- /dev/null +++ b/src/main/java/forestry/worktable/blocks/BlockRegistryWorktable.java @@ -0,0 +1,13 @@ +package forestry.worktable.blocks; + +import forestry.core.blocks.BlockRegistry; +import forestry.core.items.ItemBlockNBT; + +public class BlockRegistryWorktable extends BlockRegistry { + public final BlockWorktable worktable; + + public BlockRegistryWorktable() { + worktable = new BlockWorktable(BlockTypeWorktable.WORKTABLE); + registerBlock(worktable, new ItemBlockNBT(worktable), "worktable"); + } +} diff --git a/src/main/java/forestry/worktable/blocks/BlockTypeWorktable.java b/src/main/java/forestry/worktable/blocks/BlockTypeWorktable.java new file mode 100644 index 000000000..2b7d103bb --- /dev/null +++ b/src/main/java/forestry/worktable/blocks/BlockTypeWorktable.java @@ -0,0 +1,29 @@ +package forestry.worktable.blocks; + +import forestry.core.blocks.IBlockType; +import forestry.core.blocks.IMachineProperties; +import forestry.core.blocks.MachineProperties; +import forestry.core.tiles.TileForestry; +import forestry.worktable.tiles.TileWorktable; + +public enum BlockTypeWorktable implements IBlockType { + WORKTABLE(TileWorktable.class, "worktable"); + + public static final BlockTypeWorktable[] VALUES = values(); + + private final IMachineProperties machineProperties; + + BlockTypeWorktable(Class teClass, String name) { + this.machineProperties = new MachineProperties<>(teClass, name); + } + + @Override + public IMachineProperties getMachineProperties() { + return machineProperties; + } + + @Override + public String getName() { + return getMachineProperties().getName(); + } +} diff --git a/src/main/java/forestry/worktable/blocks/BlockWorktable.java b/src/main/java/forestry/worktable/blocks/BlockWorktable.java new file mode 100644 index 000000000..769b47354 --- /dev/null +++ b/src/main/java/forestry/worktable/blocks/BlockWorktable.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * 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.blocks; + +import forestry.core.blocks.BlockBase; + +public class BlockWorktable extends BlockBase { + public BlockWorktable(BlockTypeWorktable worktable) { + super(worktable); + setHarvestLevel("pickaxe", 0); + } +} diff --git a/src/main/java/forestry/factory/gui/widgets/package-info.java b/src/main/java/forestry/worktable/blocks/package-info.java similarity index 52% rename from src/main/java/forestry/factory/gui/widgets/package-info.java rename to src/main/java/forestry/worktable/blocks/package-info.java index 3c38d4a82..c19f6552b 100644 --- a/src/main/java/forestry/factory/gui/widgets/package-info.java +++ b/src/main/java/forestry/worktable/blocks/package-info.java @@ -1,9 +1,10 @@ @ParametersAreNonnullByDefault @FieldsAreNonnullByDefault @MethodsReturnNonnullByDefault -package forestry.factory.gui.widgets; +package forestry.worktable.blocks; import javax.annotation.ParametersAreNonnullByDefault; -import forestry.core.utils.FieldsAreNonnullByDefault; -import mcp.MethodsReturnNonnullByDefault; \ No newline at end of file +import mcp.MethodsReturnNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/worktable/compat/WorktableJeiPlugin.java b/src/main/java/forestry/worktable/compat/WorktableJeiPlugin.java new file mode 100644 index 000000000..35c575214 --- /dev/null +++ b/src/main/java/forestry/worktable/compat/WorktableJeiPlugin.java @@ -0,0 +1,42 @@ +package forestry.worktable.compat; + +import com.google.common.base.Preconditions; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.api.core.ForestryAPI; +import forestry.core.config.Constants; +import forestry.core.utils.JeiUtil; +import forestry.modules.ForestryModuleUids; +import forestry.worktable.ModuleWorktable; +import forestry.worktable.blocks.BlockRegistryWorktable; +import mezz.jei.api.IModPlugin; +import mezz.jei.api.IModRegistry; +import mezz.jei.api.JEIPlugin; +import mezz.jei.api.recipe.VanillaRecipeCategoryUid; +import mezz.jei.api.recipe.transfer.IRecipeTransferRegistry; + +@JEIPlugin +@SideOnly(Side.CLIENT) +public class WorktableJeiPlugin implements IModPlugin { + + @Override + public void register(IModRegistry registry) { + if(!ForestryAPI.enabledModules.contains(new ResourceLocation(Constants.MOD_ID, ForestryModuleUids.WORKTABLE))){ + return; + } + BlockRegistryWorktable blocks = ModuleWorktable.getBlocks(); + Preconditions.checkNotNull(blocks); + + registry.addRecipeCatalyst(new ItemStack(blocks.worktable), VanillaRecipeCategoryUid.CRAFTING); + + IRecipeTransferRegistry transferRegistry = registry.getRecipeTransferRegistry(); + transferRegistry.addRecipeTransferHandler(new WorktableRecipeTransferHandler(), VanillaRecipeCategoryUid.CRAFTING); + + JeiUtil.addDescription(registry, blocks.worktable); + } +} diff --git a/src/main/java/forestry/factory/recipes/jei/WorktableRecipeTransferHandler.java b/src/main/java/forestry/worktable/compat/WorktableRecipeTransferHandler.java similarity index 89% rename from src/main/java/forestry/factory/recipes/jei/WorktableRecipeTransferHandler.java rename to src/main/java/forestry/worktable/compat/WorktableRecipeTransferHandler.java index c7b88322e..e1e2d6992 100644 --- a/src/main/java/forestry/factory/recipes/jei/WorktableRecipeTransferHandler.java +++ b/src/main/java/forestry/worktable/compat/WorktableRecipeTransferHandler.java @@ -1,23 +1,24 @@ -package forestry.factory.recipes.jei; +package forestry.worktable.compat; import javax.annotation.Nullable; import java.util.List; import java.util.Map; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + import forestry.core.recipes.RecipeUtil; -import forestry.factory.gui.ContainerWorktable; -import forestry.factory.inventory.InventoryCraftingForestry; -import forestry.factory.recipes.MemorizedRecipe; +import forestry.worktable.gui.ContainerWorktable; +import forestry.worktable.inventory.InventoryCraftingForestry; +import forestry.worktable.recipes.MemorizedRecipe; import mezz.jei.api.gui.IGuiIngredient; import mezz.jei.api.gui.IRecipeLayout; import mezz.jei.api.recipe.transfer.IRecipeTransferError; import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.util.NonNullList; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) class WorktableRecipeTransferHandler implements IRecipeTransferHandler { diff --git a/src/main/java/forestry/worktable/compat/package-info.java b/src/main/java/forestry/worktable/compat/package-info.java new file mode 100644 index 000000000..11df28bd3 --- /dev/null +++ b/src/main/java/forestry/worktable/compat/package-info.java @@ -0,0 +1,10 @@ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.worktable.compat; + +import javax.annotation.ParametersAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/factory/gui/ContainerWorktable.java b/src/main/java/forestry/worktable/gui/ContainerWorktable.java old mode 100755 new mode 100644 similarity index 90% rename from src/main/java/forestry/factory/gui/ContainerWorktable.java rename to src/main/java/forestry/worktable/gui/ContainerWorktable.java index 2b451b481..9bcab54c5 --- a/src/main/java/forestry/factory/gui/ContainerWorktable.java +++ b/src/main/java/forestry/worktable/gui/ContainerWorktable.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.factory.gui; +package forestry.worktable.gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -24,18 +24,18 @@ 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.factory.inventory.InventoryCraftingForestry; -import forestry.factory.inventory.InventoryGhostCrafting; -import forestry.factory.inventory.InventoryWorktable; -import forestry.factory.network.packets.PacketWorktableMemoryUpdate; -import forestry.factory.network.packets.PacketWorktableRecipeRequest; -import forestry.factory.network.packets.PacketWorktableRecipeUpdate; -import forestry.factory.recipes.MemorizedRecipe; -import forestry.factory.recipes.RecipeMemory; -import forestry.factory.tiles.TileWorktable; +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 implements IContainerCrafting, IGuiSelectable { private final InventoryCraftingForestry craftMatrix = new InventoryCraftingForestry(this); diff --git a/src/main/java/forestry/factory/gui/GuiWorktable.java b/src/main/java/forestry/worktable/gui/GuiWorktable.java old mode 100755 new mode 100644 similarity index 91% rename from src/main/java/forestry/factory/gui/GuiWorktable.java rename to src/main/java/forestry/worktable/gui/GuiWorktable.java index ee70f98f7..e7ea1a31b --- a/src/main/java/forestry/factory/gui/GuiWorktable.java +++ b/src/main/java/forestry/worktable/gui/GuiWorktable.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.factory.gui; +package forestry.worktable.gui; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.EntityPlayer; @@ -20,10 +20,10 @@ import forestry.core.gui.buttons.StandardButtonTextureSets; import forestry.core.network.packets.PacketGuiSelectRequest; import forestry.core.utils.NetworkUtil; import forestry.core.utils.SoundUtil; -import forestry.factory.gui.widgets.ClearWorktable; -import forestry.factory.gui.widgets.MemorizedRecipeSlot; -import forestry.factory.recipes.RecipeMemory; -import forestry.factory.tiles.TileWorktable; +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 { private static final int SPACING = 18; diff --git a/src/main/java/forestry/worktable/gui/package-info.java b/src/main/java/forestry/worktable/gui/package-info.java new file mode 100644 index 000000000..7b074d82b --- /dev/null +++ b/src/main/java/forestry/worktable/gui/package-info.java @@ -0,0 +1,10 @@ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.worktable.gui; + +import javax.annotation.ParametersAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/factory/gui/widgets/ClearWorktable.java b/src/main/java/forestry/worktable/gui/widgets/ClearWorktable.java similarity index 90% rename from src/main/java/forestry/factory/gui/widgets/ClearWorktable.java rename to src/main/java/forestry/worktable/gui/widgets/ClearWorktable.java index 748bc74fb..cccadd7e7 100644 --- a/src/main/java/forestry/factory/gui/widgets/ClearWorktable.java +++ b/src/main/java/forestry/worktable/gui/widgets/ClearWorktable.java @@ -1,35 +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.factory.gui.widgets; - -import forestry.core.gui.widgets.Widget; -import forestry.core.gui.widgets.WidgetManager; -import forestry.core.utils.SoundUtil; -import forestry.factory.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(); - } -} +/******************************************************************************* + * 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(); + } +} diff --git a/src/main/java/forestry/factory/gui/widgets/MemorizedRecipeSlot.java b/src/main/java/forestry/worktable/gui/widgets/MemorizedRecipeSlot.java similarity index 91% rename from src/main/java/forestry/factory/gui/widgets/MemorizedRecipeSlot.java rename to src/main/java/forestry/worktable/gui/widgets/MemorizedRecipeSlot.java index 871f81029..c1e3f71f3 100644 --- a/src/main/java/forestry/factory/gui/widgets/MemorizedRecipeSlot.java +++ b/src/main/java/forestry/worktable/gui/widgets/MemorizedRecipeSlot.java @@ -1,60 +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.factory.gui.widgets; - -import forestry.core.gui.widgets.ItemStackWidgetBase; -import forestry.core.gui.widgets.WidgetManager; -import forestry.core.render.TextureManagerForestry; -import forestry.core.utils.SoundUtil; -import forestry.factory.gui.ContainerWorktable; -import forestry.factory.recipes.RecipeMemory; -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.client.renderer.texture.TextureAtlasSprite; -import net.minecraft.item.ItemStack; - -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(); - } - } -} +/******************************************************************************* + * 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(); + } + } +} diff --git a/src/main/java/forestry/worktable/gui/widgets/package-info.java b/src/main/java/forestry/worktable/gui/widgets/package-info.java new file mode 100644 index 000000000..132159f5b --- /dev/null +++ b/src/main/java/forestry/worktable/gui/widgets/package-info.java @@ -0,0 +1,10 @@ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.worktable.gui.widgets; + +import javax.annotation.ParametersAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/factory/inventory/InventoryCraftingForestry.java b/src/main/java/forestry/worktable/inventory/InventoryCraftingForestry.java similarity index 92% rename from src/main/java/forestry/factory/inventory/InventoryCraftingForestry.java rename to src/main/java/forestry/worktable/inventory/InventoryCraftingForestry.java index e486a8f15..a6eecf3e3 100644 --- a/src/main/java/forestry/factory/inventory/InventoryCraftingForestry.java +++ b/src/main/java/forestry/worktable/inventory/InventoryCraftingForestry.java @@ -1,42 +1,42 @@ -/******************************************************************************* - * 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.factory.inventory; - -import forestry.core.gui.ContainerDummy; -import forestry.factory.gui.ContainerWorktable; - -import net.minecraft.inventory.Container; -import net.minecraft.inventory.InventoryCrafting; - -public class InventoryCraftingForestry extends InventoryCrafting { - private final Container eventHandlerIn; - - public InventoryCraftingForestry(ContainerWorktable containerWorktable) { - this(containerWorktable, 3, 3); - } - - public InventoryCraftingForestry() { - this(ContainerDummy.instance, 3, 3); - } - - private InventoryCraftingForestry(Container eventHandlerIn, int width, int height) { - super(eventHandlerIn, width, height); - this.eventHandlerIn = eventHandlerIn; - } - - public InventoryCraftingForestry copy() { - InventoryCraftingForestry copy = new InventoryCraftingForestry(this.eventHandlerIn, getWidth(), getHeight()); - for (int slot = 0; slot < getSizeInventory(); slot++) { - copy.setInventorySlotContents(slot, getStackInSlot(slot).copy()); - } - return copy; - } -} +/******************************************************************************* + * 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.inventory; + +import net.minecraft.inventory.Container; +import net.minecraft.inventory.InventoryCrafting; + +import forestry.core.gui.ContainerDummy; +import forestry.worktable.gui.ContainerWorktable; + +public class InventoryCraftingForestry extends InventoryCrafting { + private final Container eventHandlerIn; + + public InventoryCraftingForestry(ContainerWorktable containerWorktable) { + this(containerWorktable, 3, 3); + } + + public InventoryCraftingForestry() { + this(ContainerDummy.instance, 3, 3); + } + + private InventoryCraftingForestry(Container eventHandlerIn, int width, int height) { + super(eventHandlerIn, width, height); + this.eventHandlerIn = eventHandlerIn; + } + + public InventoryCraftingForestry copy() { + InventoryCraftingForestry copy = new InventoryCraftingForestry(this.eventHandlerIn, getWidth(), getHeight()); + for (int slot = 0; slot < getSizeInventory(); slot++) { + copy.setInventorySlotContents(slot, getStackInSlot(slot).copy()); + } + return copy; + } +} diff --git a/src/main/java/forestry/factory/inventory/InventoryWorktable.java b/src/main/java/forestry/worktable/inventory/InventoryWorktable.java similarity index 91% rename from src/main/java/forestry/factory/inventory/InventoryWorktable.java rename to src/main/java/forestry/worktable/inventory/InventoryWorktable.java index 334828a55..46d19b44a 100644 --- a/src/main/java/forestry/factory/inventory/InventoryWorktable.java +++ b/src/main/java/forestry/worktable/inventory/InventoryWorktable.java @@ -1,30 +1,31 @@ -/******************************************************************************* - * 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.factory.inventory; - -import forestry.core.inventory.InventoryAdapterTile; -import forestry.core.utils.SlotUtil; -import forestry.factory.tiles.TileWorktable; -import net.minecraft.item.ItemStack; - -public class InventoryWorktable extends InventoryAdapterTile { - public final static short SLOT_INVENTORY_1 = 0; - public final static short SLOT_INVENTORY_COUNT = 18; - - public InventoryWorktable(TileWorktable worktable) { - super(worktable, 18, "Items"); - } - - @Override - public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { - return SlotUtil.isSlotInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); - } -} +/******************************************************************************* + * 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.inventory; + +import net.minecraft.item.ItemStack; + +import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.utils.SlotUtil; +import forestry.worktable.tiles.TileWorktable; + +public class InventoryWorktable extends InventoryAdapterTile { + public final static short SLOT_INVENTORY_1 = 0; + public final static short SLOT_INVENTORY_COUNT = 18; + + public InventoryWorktable(TileWorktable worktable) { + super(worktable, 18, "Items"); + } + + @Override + public boolean canSlotAccept(int slotIndex, ItemStack itemStack) { + return SlotUtil.isSlotInRange(slotIndex, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT); + } +} diff --git a/src/main/java/forestry/worktable/inventory/package-info.java b/src/main/java/forestry/worktable/inventory/package-info.java new file mode 100644 index 000000000..3f8fdf346 --- /dev/null +++ b/src/main/java/forestry/worktable/inventory/package-info.java @@ -0,0 +1,10 @@ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.worktable.inventory; + +import javax.annotation.ParametersAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/worktable/network/PacketRegistryWorktable.java b/src/main/java/forestry/worktable/network/PacketRegistryWorktable.java new file mode 100644 index 000000000..b78993dd3 --- /dev/null +++ b/src/main/java/forestry/worktable/network/PacketRegistryWorktable.java @@ -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.network; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.core.network.IPacketRegistry; +import forestry.core.network.PacketIdClient; +import forestry.core.network.PacketIdServer; +import forestry.worktable.network.packets.PacketWorktableMemoryUpdate; +import forestry.worktable.network.packets.PacketWorktableRecipeRequest; +import forestry.worktable.network.packets.PacketWorktableRecipeUpdate; + +public class PacketRegistryWorktable implements IPacketRegistry { + @Override + public void registerPacketsServer() { + PacketIdServer.WORKTABLE_RECIPE_REQUEST.setPacketHandler(new PacketWorktableRecipeRequest.Handler()); + } + + @Override + @SideOnly(Side.CLIENT) + public void registerPacketsClient() { + PacketIdClient.WORKTABLE_MEMORY_UPDATE.setPacketHandler(new PacketWorktableMemoryUpdate.Handler()); + PacketIdClient.WORKTABLE_CRAFTING_UPDATE.setPacketHandler(new PacketWorktableRecipeUpdate.Handler()); + } +} diff --git a/src/main/java/forestry/worktable/network/package-info.java b/src/main/java/forestry/worktable/network/package-info.java new file mode 100644 index 000000000..5ef58c6d9 --- /dev/null +++ b/src/main/java/forestry/worktable/network/package-info.java @@ -0,0 +1,10 @@ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.worktable.network; + +import javax.annotation.ParametersAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/factory/network/packets/PacketWorktableMemoryUpdate.java b/src/main/java/forestry/worktable/network/packets/PacketWorktableMemoryUpdate.java similarity index 91% rename from src/main/java/forestry/factory/network/packets/PacketWorktableMemoryUpdate.java rename to src/main/java/forestry/worktable/network/packets/PacketWorktableMemoryUpdate.java index 3fe583488..f32b4bbc4 100644 --- a/src/main/java/forestry/factory/network/packets/PacketWorktableMemoryUpdate.java +++ b/src/main/java/forestry/worktable/network/packets/PacketWorktableMemoryUpdate.java @@ -1,60 +1,62 @@ -/******************************************************************************* - * 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.factory.network.packets; - -import java.io.IOException; - -import forestry.core.network.ForestryPacket; -import forestry.core.network.IForestryPacketClient; -import forestry.core.network.IForestryPacketHandlerClient; -import forestry.core.network.PacketBufferForestry; -import forestry.core.network.PacketIdClient; -import forestry.core.tiles.TileUtil; -import forestry.factory.recipes.RecipeMemory; -import forestry.factory.tiles.TileWorktable; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.math.BlockPos; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -public class PacketWorktableMemoryUpdate extends ForestryPacket implements IForestryPacketClient { - private final BlockPos pos; - private final RecipeMemory recipeMemory; - - public PacketWorktableMemoryUpdate(TileWorktable worktable) { - this.pos = worktable.getPos(); - this.recipeMemory = worktable.getMemory(); - } - - @Override - public PacketIdClient getPacketId() { - return PacketIdClient.WORKTABLE_MEMORY_UPDATE; - } - - @Override - protected void writeData(PacketBufferForestry data) throws IOException { - data.writeBlockPos(pos); - recipeMemory.writeData(data); - } - - @SideOnly(Side.CLIENT) - public static class Handler implements IForestryPacketHandlerClient { - @Override - public void onPacketData(PacketBufferForestry data, EntityPlayer player) throws IOException { - BlockPos pos = data.readBlockPos(); - - TileWorktable tile = TileUtil.getTile(player.world, pos, TileWorktable.class); - if (tile != null) { - tile.getMemory().readData(data); - } - } - } -} +/******************************************************************************* + * 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.network.packets; + +import java.io.IOException; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.math.BlockPos; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.core.network.ForestryPacket; +import forestry.core.network.IForestryPacketClient; +import forestry.core.network.IForestryPacketHandlerClient; +import forestry.core.network.PacketBufferForestry; +import forestry.core.network.PacketIdClient; +import forestry.core.tiles.TileUtil; +import forestry.worktable.recipes.RecipeMemory; +import forestry.worktable.tiles.TileWorktable; + +public class PacketWorktableMemoryUpdate extends ForestryPacket implements IForestryPacketClient { + private final BlockPos pos; + private final RecipeMemory recipeMemory; + + public PacketWorktableMemoryUpdate(TileWorktable worktable) { + this.pos = worktable.getPos(); + this.recipeMemory = worktable.getMemory(); + } + + @Override + public PacketIdClient getPacketId() { + return PacketIdClient.WORKTABLE_MEMORY_UPDATE; + } + + @Override + protected void writeData(PacketBufferForestry data) throws IOException { + data.writeBlockPos(pos); + recipeMemory.writeData(data); + } + + @SideOnly(Side.CLIENT) + public static class Handler implements IForestryPacketHandlerClient { + @Override + public void onPacketData(PacketBufferForestry data, EntityPlayer player) throws IOException { + BlockPos pos = data.readBlockPos(); + + TileWorktable tile = TileUtil.getTile(player.world, pos, TileWorktable.class); + if (tile != null) { + tile.getMemory().readData(data); + } + } + } +} diff --git a/src/main/java/forestry/factory/network/packets/PacketWorktableRecipeRequest.java b/src/main/java/forestry/worktable/network/packets/PacketWorktableRecipeRequest.java similarity index 92% rename from src/main/java/forestry/factory/network/packets/PacketWorktableRecipeRequest.java rename to src/main/java/forestry/worktable/network/packets/PacketWorktableRecipeRequest.java index 23d397e2d..40f61daea 100644 --- a/src/main/java/forestry/factory/network/packets/PacketWorktableRecipeRequest.java +++ b/src/main/java/forestry/worktable/network/packets/PacketWorktableRecipeRequest.java @@ -8,10 +8,13 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.factory.network.packets; +package forestry.worktable.network.packets; import java.io.IOException; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.util.math.BlockPos; + import forestry.core.network.ForestryPacket; import forestry.core.network.IForestryPacketHandlerServer; import forestry.core.network.IForestryPacketServer; @@ -19,11 +22,9 @@ import forestry.core.network.PacketBufferForestry; import forestry.core.network.PacketIdServer; import forestry.core.tiles.TileUtil; import forestry.core.utils.NetworkUtil; -import forestry.factory.gui.ContainerWorktable; -import forestry.factory.recipes.MemorizedRecipe; -import forestry.factory.tiles.TileWorktable; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.util.math.BlockPos; +import forestry.worktable.gui.ContainerWorktable; +import forestry.worktable.recipes.MemorizedRecipe; +import forestry.worktable.tiles.TileWorktable; /** * Used to sync the worktable crafting grid from Client to Server. diff --git a/src/main/java/forestry/factory/network/packets/PacketWorktableRecipeUpdate.java b/src/main/java/forestry/worktable/network/packets/PacketWorktableRecipeUpdate.java similarity index 91% rename from src/main/java/forestry/factory/network/packets/PacketWorktableRecipeUpdate.java rename to src/main/java/forestry/worktable/network/packets/PacketWorktableRecipeUpdate.java index 652c5556c..1e41f8395 100644 --- a/src/main/java/forestry/factory/network/packets/PacketWorktableRecipeUpdate.java +++ b/src/main/java/forestry/worktable/network/packets/PacketWorktableRecipeUpdate.java @@ -1,65 +1,65 @@ -/******************************************************************************* - * 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.factory.network.packets; - -import javax.annotation.Nullable; -import java.io.IOException; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.util.math.BlockPos; - -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -import forestry.core.network.ForestryPacket; -import forestry.core.network.IForestryPacketClient; -import forestry.core.network.IForestryPacketHandlerClient; -import forestry.core.network.PacketBufferForestry; -import forestry.core.network.PacketIdClient; -import forestry.core.tiles.TileUtil; -import forestry.factory.recipes.MemorizedRecipe; -import forestry.factory.tiles.TileWorktable; - -/** - * Used to sync the worktable crafting result from Server to Client. - */ -public class PacketWorktableRecipeUpdate extends ForestryPacket implements IForestryPacketClient { - private final BlockPos pos; - @Nullable - private final MemorizedRecipe recipe; - - public PacketWorktableRecipeUpdate(TileWorktable worktable) { - this.pos = worktable.getPos(); - this.recipe = worktable.getCurrentRecipe(); - } - - @Override - public PacketIdClient getPacketId() { - return PacketIdClient.WORKTABLE_CRAFTING_UPDATE; - } - - @Override - protected void writeData(PacketBufferForestry data) { - data.writeBlockPos(pos); - data.writeStreamable(recipe); - } - - @SideOnly(Side.CLIENT) - public static class Handler implements IForestryPacketHandlerClient { - @Override - public void onPacketData(PacketBufferForestry data, EntityPlayer player) throws IOException { - BlockPos pos = data.readBlockPos(); - MemorizedRecipe recipe = data.readStreamable(MemorizedRecipe::new); - - TileUtil.actOnTile(player.world, pos, TileWorktable.class, tile -> tile.setCurrentRecipe(recipe)); - } - } -} +/******************************************************************************* + * 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.network.packets; + +import javax.annotation.Nullable; +import java.io.IOException; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.math.BlockPos; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import forestry.core.network.ForestryPacket; +import forestry.core.network.IForestryPacketClient; +import forestry.core.network.IForestryPacketHandlerClient; +import forestry.core.network.PacketBufferForestry; +import forestry.core.network.PacketIdClient; +import forestry.core.tiles.TileUtil; +import forestry.worktable.recipes.MemorizedRecipe; +import forestry.worktable.tiles.TileWorktable; + +/** + * Used to sync the worktable crafting result from Server to Client. + */ +public class PacketWorktableRecipeUpdate extends ForestryPacket implements IForestryPacketClient { + private final BlockPos pos; + @Nullable + private final MemorizedRecipe recipe; + + public PacketWorktableRecipeUpdate(TileWorktable worktable) { + this.pos = worktable.getPos(); + this.recipe = worktable.getCurrentRecipe(); + } + + @Override + public PacketIdClient getPacketId() { + return PacketIdClient.WORKTABLE_CRAFTING_UPDATE; + } + + @Override + protected void writeData(PacketBufferForestry data) { + data.writeBlockPos(pos); + data.writeStreamable(recipe); + } + + @SideOnly(Side.CLIENT) + public static class Handler implements IForestryPacketHandlerClient { + @Override + public void onPacketData(PacketBufferForestry data, EntityPlayer player) throws IOException { + BlockPos pos = data.readBlockPos(); + MemorizedRecipe recipe = data.readStreamable(MemorizedRecipe::new); + + TileUtil.actOnTile(player.world, pos, TileWorktable.class, tile -> tile.setCurrentRecipe(recipe)); + } + } +} diff --git a/src/main/java/forestry/worktable/network/packets/package-info.java b/src/main/java/forestry/worktable/network/packets/package-info.java new file mode 100644 index 000000000..a3e345b2c --- /dev/null +++ b/src/main/java/forestry/worktable/network/packets/package-info.java @@ -0,0 +1,10 @@ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.worktable.network.packets; + +import javax.annotation.ParametersAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/worktable/package-info.java b/src/main/java/forestry/worktable/package-info.java new file mode 100644 index 000000000..36284b1eb --- /dev/null +++ b/src/main/java/forestry/worktable/package-info.java @@ -0,0 +1,10 @@ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.worktable; + +import javax.annotation.ParametersAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/factory/recipes/MemorizedRecipe.java b/src/main/java/forestry/worktable/recipes/MemorizedRecipe.java similarity index 95% rename from src/main/java/forestry/factory/recipes/MemorizedRecipe.java rename to src/main/java/forestry/worktable/recipes/MemorizedRecipe.java index 8f8b2d6dd..8c8ef764e 100644 --- a/src/main/java/forestry/factory/recipes/MemorizedRecipe.java +++ b/src/main/java/forestry/worktable/recipes/MemorizedRecipe.java @@ -1,219 +1,219 @@ -/******************************************************************************* - * 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.factory.recipes; - -import javax.annotation.Nullable; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.nbt.NBTTagString; -import net.minecraft.util.ResourceLocation; -import net.minecraft.world.World; - -import net.minecraftforge.fml.common.registry.ForgeRegistries; - -import forestry.api.core.INbtReadable; -import forestry.api.core.INbtWritable; -import forestry.core.network.IStreamable; -import forestry.core.network.PacketBufferForestry; -import forestry.core.utils.InventoryUtil; -import forestry.core.utils.NBTUtilForestry; -import forestry.factory.inventory.InventoryCraftingForestry; - -public final class MemorizedRecipe implements INbtWritable, INbtReadable, IStreamable { - private InventoryCraftingForestry craftMatrix = new InventoryCraftingForestry(); - private List recipes = new ArrayList<>(); - private int selectedRecipe; - private long lastUsed; - private boolean locked; - - public MemorizedRecipe(PacketBufferForestry data) throws IOException { - readData(data); - } - - public MemorizedRecipe(NBTTagCompound nbt) { - readFromNBT(nbt); - } - - public MemorizedRecipe(InventoryCraftingForestry craftMatrix, List recipes) { - InventoryUtil.deepCopyInventoryContents(craftMatrix, this.craftMatrix); - this.recipes = recipes; - } - - public InventoryCraftingForestry getCraftMatrix() { - return craftMatrix; - } - - public void setCraftMatrix(InventoryCraftingForestry craftMatrix) { - this.craftMatrix = craftMatrix; - } - - public void incrementRecipe() { - selectedRecipe++; - if (selectedRecipe >= recipes.size()) { - selectedRecipe = 0; - } - } - - public void decrementRecipe() { - selectedRecipe--; - if (selectedRecipe < 0) { - selectedRecipe = recipes.size() - 1; - } - } - - public boolean hasRecipeConflict() { - return recipes.size() > 1; - } - - public void removeRecipeConflicts() { - IRecipe recipe = getSelectedRecipe(); - recipes.clear(); - recipes.add(recipe); - selectedRecipe = 0; - } - - public ItemStack getOutputIcon() { - IRecipe selectedRecipe = getSelectedRecipe(); - if (selectedRecipe != null) { - ItemStack recipeOutput = selectedRecipe.getCraftingResult(craftMatrix); - if (!recipeOutput.isEmpty()) { - return recipeOutput; - } - } - return ItemStack.EMPTY; - } - - public ItemStack getCraftingResult(InventoryCrafting inventoryCrafting, World world) { - IRecipe selectedRecipe = getSelectedRecipe(); - if (selectedRecipe != null && selectedRecipe.matches(inventoryCrafting, world)) { - ItemStack recipeOutput = selectedRecipe.getCraftingResult(inventoryCrafting); - if (!recipeOutput.isEmpty()) { - return recipeOutput; - } - } - return ItemStack.EMPTY; - } - - @Nullable - public IRecipe getSelectedRecipe() { - if (recipes.isEmpty()) { - return null; - } else { - return recipes.get(selectedRecipe); - } - } - - public boolean hasRecipe(@Nullable IRecipe recipe) { - return this.recipes.contains(recipe); - } - - public void updateLastUse(long lastUsed) { - this.lastUsed = lastUsed; - } - - public long getLastUsed() { - return lastUsed; - } - - public void toggleLock() { - locked = !locked; - } - - public boolean isLocked() { - return locked; - } - - /* INbtWritable */ - @Override - public final void readFromNBT(NBTTagCompound nbttagcompound) { - InventoryUtil.readFromNBT(craftMatrix, nbttagcompound); - lastUsed = nbttagcompound.getLong("LastUsed"); - locked = nbttagcompound.getBoolean("Locked"); - - if (nbttagcompound.hasKey("SelectedRecipe")) { - selectedRecipe = nbttagcompound.getInteger("SelectedRecipe"); - } - - recipes.clear(); - NBTTagList recipesNbt = nbttagcompound.getTagList("Recipes", NBTUtilForestry.EnumNBTType.STRING.ordinal()); - for (int i = 0; i < recipesNbt.tagCount(); i++) { - String recipeKey = recipesNbt.getStringTagAt(i); - ResourceLocation key = new ResourceLocation(recipeKey); - IRecipe recipe = ForgeRegistries.RECIPES.getValue(key); - if (recipe != null) { - recipes.add(recipe); - } - } - - if (selectedRecipe > recipes.size()) { - selectedRecipe = 0; - } - } - - @Override - public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { - InventoryUtil.writeToNBT(craftMatrix, nbttagcompound); - nbttagcompound.setLong("LastUsed", lastUsed); - nbttagcompound.setBoolean("Locked", locked); - nbttagcompound.setInteger("SelectedRecipe", selectedRecipe); - - NBTTagList recipesNbt = new NBTTagList(); - for (IRecipe recipe : recipes) { - ResourceLocation recipeKey = ForgeRegistries.RECIPES.getKey(recipe); - if (recipeKey != null) { - recipesNbt.appendTag(new NBTTagString(recipeKey.toString())); - } - } - nbttagcompound.setTag("Recipes", recipesNbt); - - return nbttagcompound; - } - - /* IStreamable */ - @Override - public void writeData(PacketBufferForestry data) { - data.writeInventory(craftMatrix); - data.writeBoolean(locked); - data.writeVarInt(selectedRecipe); - - data.writeVarInt(recipes.size()); - for (IRecipe recipe: recipes) { - ResourceLocation recipeId = ForgeRegistries.RECIPES.getKey(recipe); - if (recipeId != null) { - data.writeString(recipeId.toString()); - } - } - } - - @Override - public void readData(PacketBufferForestry data) throws IOException { - data.readInventory(craftMatrix); - locked = data.readBoolean(); - selectedRecipe = data.readVarInt(); - - recipes.clear(); - int recipeCount = data.readVarInt(); - for (int i = 0; i < recipeCount; i++) { - String recipeId = data.readString(); - IRecipe recipe = ForgeRegistries.RECIPES.getValue(new ResourceLocation(recipeId)); - if (recipe != null) { - recipes.add(recipe); - } - } - } -} +/******************************************************************************* + * 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.recipes; + +import javax.annotation.Nullable; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagString; +import net.minecraft.util.ResourceLocation; +import net.minecraft.world.World; + +import net.minecraftforge.fml.common.registry.ForgeRegistries; + +import forestry.api.core.INbtReadable; +import forestry.api.core.INbtWritable; +import forestry.core.network.IStreamable; +import forestry.core.network.PacketBufferForestry; +import forestry.core.utils.InventoryUtil; +import forestry.core.utils.NBTUtilForestry; +import forestry.worktable.inventory.InventoryCraftingForestry; + +public final class MemorizedRecipe implements INbtWritable, INbtReadable, IStreamable { + private InventoryCraftingForestry craftMatrix = new InventoryCraftingForestry(); + private List recipes = new ArrayList<>(); + private int selectedRecipe; + private long lastUsed; + private boolean locked; + + public MemorizedRecipe(PacketBufferForestry data) throws IOException { + readData(data); + } + + public MemorizedRecipe(NBTTagCompound nbt) { + readFromNBT(nbt); + } + + public MemorizedRecipe(InventoryCraftingForestry craftMatrix, List recipes) { + InventoryUtil.deepCopyInventoryContents(craftMatrix, this.craftMatrix); + this.recipes = recipes; + } + + public InventoryCraftingForestry getCraftMatrix() { + return craftMatrix; + } + + public void setCraftMatrix(InventoryCraftingForestry craftMatrix) { + this.craftMatrix = craftMatrix; + } + + public void incrementRecipe() { + selectedRecipe++; + if (selectedRecipe >= recipes.size()) { + selectedRecipe = 0; + } + } + + public void decrementRecipe() { + selectedRecipe--; + if (selectedRecipe < 0) { + selectedRecipe = recipes.size() - 1; + } + } + + public boolean hasRecipeConflict() { + return recipes.size() > 1; + } + + public void removeRecipeConflicts() { + IRecipe recipe = getSelectedRecipe(); + recipes.clear(); + recipes.add(recipe); + selectedRecipe = 0; + } + + public ItemStack getOutputIcon() { + IRecipe selectedRecipe = getSelectedRecipe(); + if (selectedRecipe != null) { + ItemStack recipeOutput = selectedRecipe.getCraftingResult(craftMatrix); + if (!recipeOutput.isEmpty()) { + return recipeOutput; + } + } + return ItemStack.EMPTY; + } + + public ItemStack getCraftingResult(InventoryCrafting inventoryCrafting, World world) { + IRecipe selectedRecipe = getSelectedRecipe(); + if (selectedRecipe != null && selectedRecipe.matches(inventoryCrafting, world)) { + ItemStack recipeOutput = selectedRecipe.getCraftingResult(inventoryCrafting); + if (!recipeOutput.isEmpty()) { + return recipeOutput; + } + } + return ItemStack.EMPTY; + } + + @Nullable + public IRecipe getSelectedRecipe() { + if (recipes.isEmpty()) { + return null; + } else { + return recipes.get(selectedRecipe); + } + } + + public boolean hasRecipe(@Nullable IRecipe recipe) { + return this.recipes.contains(recipe); + } + + public void updateLastUse(long lastUsed) { + this.lastUsed = lastUsed; + } + + public long getLastUsed() { + return lastUsed; + } + + public void toggleLock() { + locked = !locked; + } + + public boolean isLocked() { + return locked; + } + + /* INbtWritable */ + @Override + public final void readFromNBT(NBTTagCompound nbttagcompound) { + InventoryUtil.readFromNBT(craftMatrix, nbttagcompound); + lastUsed = nbttagcompound.getLong("LastUsed"); + locked = nbttagcompound.getBoolean("Locked"); + + if (nbttagcompound.hasKey("SelectedRecipe")) { + selectedRecipe = nbttagcompound.getInteger("SelectedRecipe"); + } + + recipes.clear(); + NBTTagList recipesNbt = nbttagcompound.getTagList("Recipes", NBTUtilForestry.EnumNBTType.STRING.ordinal()); + for (int i = 0; i < recipesNbt.tagCount(); i++) { + String recipeKey = recipesNbt.getStringTagAt(i); + ResourceLocation key = new ResourceLocation(recipeKey); + IRecipe recipe = ForgeRegistries.RECIPES.getValue(key); + if (recipe != null) { + recipes.add(recipe); + } + } + + if (selectedRecipe > recipes.size()) { + selectedRecipe = 0; + } + } + + @Override + public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) { + InventoryUtil.writeToNBT(craftMatrix, nbttagcompound); + nbttagcompound.setLong("LastUsed", lastUsed); + nbttagcompound.setBoolean("Locked", locked); + nbttagcompound.setInteger("SelectedRecipe", selectedRecipe); + + NBTTagList recipesNbt = new NBTTagList(); + for (IRecipe recipe : recipes) { + ResourceLocation recipeKey = ForgeRegistries.RECIPES.getKey(recipe); + if (recipeKey != null) { + recipesNbt.appendTag(new NBTTagString(recipeKey.toString())); + } + } + nbttagcompound.setTag("Recipes", recipesNbt); + + return nbttagcompound; + } + + /* IStreamable */ + @Override + public void writeData(PacketBufferForestry data) { + data.writeInventory(craftMatrix); + data.writeBoolean(locked); + data.writeVarInt(selectedRecipe); + + data.writeVarInt(recipes.size()); + for (IRecipe recipe: recipes) { + ResourceLocation recipeId = ForgeRegistries.RECIPES.getKey(recipe); + if (recipeId != null) { + data.writeString(recipeId.toString()); + } + } + } + + @Override + public void readData(PacketBufferForestry data) throws IOException { + data.readInventory(craftMatrix); + locked = data.readBoolean(); + selectedRecipe = data.readVarInt(); + + recipes.clear(); + int recipeCount = data.readVarInt(); + for (int i = 0; i < recipeCount; i++) { + String recipeId = data.readString(); + IRecipe recipe = ForgeRegistries.RECIPES.getValue(new ResourceLocation(recipeId)); + if (recipe != null) { + recipes.add(recipe); + } + } + } +} diff --git a/src/main/java/forestry/factory/recipes/RecipeMemory.java b/src/main/java/forestry/worktable/recipes/RecipeMemory.java similarity index 99% rename from src/main/java/forestry/factory/recipes/RecipeMemory.java rename to src/main/java/forestry/worktable/recipes/RecipeMemory.java index f20184e48..424f39985 100644 --- a/src/main/java/forestry/factory/recipes/RecipeMemory.java +++ b/src/main/java/forestry/worktable/recipes/RecipeMemory.java @@ -8,16 +8,12 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.factory.recipes; +package forestry.worktable.recipes; import javax.annotation.Nullable; import java.io.IOException; import java.util.LinkedList; -import forestry.api.core.INbtWritable; -import forestry.core.network.IStreamable; -import forestry.core.network.PacketBufferForestry; - import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.nbt.NBTTagCompound; @@ -26,6 +22,10 @@ import net.minecraft.nbt.NBTTagList; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import forestry.api.core.INbtWritable; +import forestry.core.network.IStreamable; +import forestry.core.network.PacketBufferForestry; + public class RecipeMemory implements INbtWritable, IStreamable { private static final int capacity = 9; diff --git a/src/main/java/forestry/worktable/recipes/package-info.java b/src/main/java/forestry/worktable/recipes/package-info.java new file mode 100644 index 000000000..3fa144174 --- /dev/null +++ b/src/main/java/forestry/worktable/recipes/package-info.java @@ -0,0 +1,10 @@ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.worktable.recipes; + +import javax.annotation.ParametersAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; \ No newline at end of file diff --git a/src/main/java/forestry/factory/tiles/ICrafterWorktable.java b/src/main/java/forestry/worktable/tiles/ICrafterWorktable.java similarity index 81% rename from src/main/java/forestry/factory/tiles/ICrafterWorktable.java rename to src/main/java/forestry/worktable/tiles/ICrafterWorktable.java index bcf662a6a..f760adf92 100644 --- a/src/main/java/forestry/factory/tiles/ICrafterWorktable.java +++ b/src/main/java/forestry/worktable/tiles/ICrafterWorktable.java @@ -1,24 +1,22 @@ -package forestry.factory.tiles; - -import javax.annotation.Nullable; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.world.World; - -import forestry.factory.inventory.InventoryCraftingForestry; - -public interface ICrafterWorktable { - ItemStack getResult(InventoryCrafting inventoryCrafting, World world); - - boolean canTakeStack(int slotIndex); - - boolean onCraftingStart(EntityPlayer player); - - void onCraftingComplete(EntityPlayer player); - - @Nullable - IRecipe getRecipeUsed(); -} +package forestry.worktable.tiles; + +import javax.annotation.Nullable; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; + +public interface ICrafterWorktable { + ItemStack getResult(InventoryCrafting inventoryCrafting, World world); + + boolean canTakeStack(int slotIndex); + + boolean onCraftingStart(EntityPlayer player); + + void onCraftingComplete(EntityPlayer player); + + @Nullable + IRecipe getRecipeUsed(); +} diff --git a/src/main/java/forestry/factory/tiles/TileWorktable.java b/src/main/java/forestry/worktable/tiles/TileWorktable.java old mode 100755 new mode 100644 similarity index 95% rename from src/main/java/forestry/factory/tiles/TileWorktable.java rename to src/main/java/forestry/worktable/tiles/TileWorktable.java index 62ee4872c..d215bcf44 --- a/src/main/java/forestry/factory/tiles/TileWorktable.java +++ b/src/main/java/forestry/worktable/tiles/TileWorktable.java @@ -8,7 +8,7 @@ * Various Contributors including, but not limited to: * SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges ******************************************************************************/ -package forestry.factory.tiles; +package forestry.worktable.tiles; import com.google.common.base.Preconditions; @@ -34,19 +34,19 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import forestry.core.inventory.InventoryAdapterTile; +import forestry.core.inventory.InventoryGhostCrafting; import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.network.PacketBufferForestry; import forestry.core.recipes.RecipeUtil; import forestry.core.tiles.TileBase; import forestry.core.utils.InventoryUtil; import forestry.core.utils.ItemStackUtil; -import forestry.factory.gui.ContainerWorktable; -import forestry.factory.gui.GuiWorktable; -import forestry.factory.inventory.InventoryCraftingForestry; -import forestry.factory.inventory.InventoryGhostCrafting; -import forestry.factory.inventory.InventoryWorktable; -import forestry.factory.recipes.MemorizedRecipe; -import forestry.factory.recipes.RecipeMemory; +import forestry.worktable.gui.ContainerWorktable; +import forestry.worktable.gui.GuiWorktable; +import forestry.worktable.inventory.InventoryCraftingForestry; +import forestry.worktable.inventory.InventoryWorktable; +import forestry.worktable.recipes.MemorizedRecipe; +import forestry.worktable.recipes.RecipeMemory; public class TileWorktable extends TileBase implements ICrafterWorktable { private RecipeMemory recipeMemory; diff --git a/src/main/java/forestry/worktable/tiles/package-info.java b/src/main/java/forestry/worktable/tiles/package-info.java new file mode 100644 index 000000000..ae19e57e6 --- /dev/null +++ b/src/main/java/forestry/worktable/tiles/package-info.java @@ -0,0 +1,10 @@ +@ParametersAreNonnullByDefault +@FieldsAreNonnullByDefault +@MethodsReturnNonnullByDefault +package forestry.worktable.tiles; + +import javax.annotation.ParametersAreNonnullByDefault; + +import mcp.MethodsReturnNonnullByDefault; + +import forestry.core.utils.FieldsAreNonnullByDefault; \ No newline at end of file