Move the worktable into a separate module

This commit is contained in:
Nedelosk committed 2018-01-07 02:18:11 +01:00
1 parent a058c3f8c9
commit 42865951a9
44 files changed
+915 -646

No files matched your search

@@ -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<Class<? extends IGuiHandlerForestry>, GuiId> classMap = new HashMap<>();
@@ -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 {
@@ -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<T extends TileEntity> extends InventoryAdapterTile<T> {
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<T extends TileEntity> extends InventoryAdapterTile<T> {
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");
}
}
@@ -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 {
@@ -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");
}
}
@@ -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");
}
}
@@ -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();
@@ -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<TileFabricator> implements IContainerCrafting {
@@ -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());
}
}
@@ -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
);
}
@@ -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 {
@@ -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;
@@ -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";
@@ -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<IForestryModule> forestryModules) {
for (IForestryModule module : forestryModules) {
ForestryModule info = module.getClass().getAnnotation(ForestryModule.class);
@@ -110,7 +112,7 @@ public class ModuleManager implements IModuleManager {
Set<ResourceLocation> toLoad = new HashSet<>();
Set<IForestryModule> modulesToLoad = new HashSet<>();
ImmutableList<IForestryModule> allModules = ImmutableList.copyOf(modules.values().stream().flatMap(x -> x.stream()).collect(Collectors.toList()));
ImmutableList<IForestryModule> 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);
}
}
@@ -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");
}
}
@@ -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");
}
}
@@ -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;
<T extends TileForestry> BlockTypeWorktable(Class<T> teClass, String name) {
this.machineProperties = new MachineProperties<>(teClass, name);
}
@Override
public IMachineProperties getMachineProperties() {
return machineProperties;
}
@Override
public String getName() {
return getMachineProperties().getName();
}
}
@@ -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<BlockTypeWorktable> {
public BlockWorktable(BlockTypeWorktable worktable) {
super(worktable);
setHarvestLevel("pickaxe", 0);
}
}
@@ -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;
import mcp.MethodsReturnNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
@@ -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);
}
}
@@ -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<ContainerWorktable> {
@@ -0,0 +1,10 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.worktable.compat;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
@@ -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<TileWorktable> implements IContainerCrafting, IGuiSelectable {
private final InventoryCraftingForestry craftMatrix = new InventoryCraftingForestry(this);
@@ -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<ContainerWorktable> {
private static final int SPACING = 18;
@@ -0,0 +1,10 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.worktable.gui;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
@@ -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();
}
}
@@ -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();
}
}
}
@@ -0,0 +1,10 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.worktable.gui.widgets;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
@@ -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;
}
}
@@ -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<TileWorktable> {
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<TileWorktable> {
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);
}
}
@@ -0,0 +1,10 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.worktable.inventory;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
@@ -0,0 +1,35 @@
/*******************************************************************************
* Copyright (c) 2011-2014 SirSengir.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.worktable.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());
}
}
@@ -0,0 +1,10 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.worktable.network;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
@@ -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);
}
}
}
}
@@ -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.
@@ -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));
}
}
}
@@ -0,0 +1,10 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.worktable.network.packets;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
@@ -0,0 +1,10 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.worktable;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
@@ -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<IRecipe> 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<IRecipe> 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<IRecipe> 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<IRecipe> 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);
}
}
}
}
@@ -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;
@@ -0,0 +1,10 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.worktable.recipes;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
@@ -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();
}
@@ -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;
@@ -0,0 +1,10 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.worktable.tiles;
import javax.annotation.ParametersAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;