diff --git a/client/src/main/java/client/gui/container/GuiContainer.java b/client/src/main/java/client/gui/container/GuiContainer.java index 32bea171..0f91ecbd 100755 --- a/client/src/main/java/client/gui/container/GuiContainer.java +++ b/client/src/main/java/client/gui/container/GuiContainer.java @@ -655,7 +655,7 @@ public abstract class GuiContainer extends Gui } Slot slot = this.getSlotAtPosition(mouseX, mouseY); if(slot != null && Bind.CRAFT.isDown() && slot.canCheatItem() && slot.getHasStack() && this.gm.player.inventoryContainer.getSingleRecipe(slot.getStack()) != null) { - this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.CRAFT_ITEM, slot.slotNumber)); + this.gm.player.client.addToSendQueue(new CPacketAction(CPacketAction.Action.CRAFT_SINGLE, slot.slotNumber)); this.ignoreMouseUp = true; return; } @@ -1026,7 +1026,7 @@ public abstract class GuiContainer extends Gui this.gm.player.client.addToSendQueue(new CPacketCheat(ITEM_LIST.get(idx).getItem(), slot < 0 ? slot : -2 - slot, full)); } else { - this.cheatStack = ITEM_LIST.get(idx).copy(full ? ITEM_LIST.get(idx).getMaxStackSize() : 1); + this.cheatStack = ITEM_LIST.get(idx).copy(full ? Math.min(ITEM_LIST.get(idx).getMaxStackSize(), 100) : 1); } return true; } diff --git a/client/src/main/java/client/gui/container/GuiCrafting.java b/client/src/main/java/client/gui/container/GuiCrafting.java index a5c13c54..7744704d 100755 --- a/client/src/main/java/client/gui/container/GuiCrafting.java +++ b/client/src/main/java/client/gui/container/GuiCrafting.java @@ -12,11 +12,11 @@ public class GuiCrafting extends GuiContainer { public GuiCrafting(EntityNPC inv, World world, BlockWorkbench type) { super(new ContainerWorkbench(inv, world, LocalPos.ORIGIN, type)); this.type = type; - this.ySize = 36 + 18 * ((inv.getInventoryCapacity() + 11) / 12) + 18 * this.type.getSize(); + this.ySize = 36 + 18 * ((inv.getInventoryCapacity() + 11) / 12) + 18 * 3; } public void addElements() { this.label(this.type.getDisplay(), 8, 16); - this.label("Inventar", 8, 36 - 8 + 18 * this.type.getSize()); + this.label("Inventar", 8, 36 - 8 + 18 * 3); } } diff --git a/client/src/main/java/client/network/ClientPlayer.java b/client/src/main/java/client/network/ClientPlayer.java index 0a3f07e9..ad761735 100755 --- a/client/src/main/java/client/network/ClientPlayer.java +++ b/client/src/main/java/client/network/ClientPlayer.java @@ -1128,7 +1128,7 @@ public class ClientPlayer implements IClientPlayer // flag = true; // guicontainercreative.getSelectedTabIndex() != CheatTab.tabInventory.getIndex(); // } - if (packetIn.getWindowId() == 0 && packetIn.getSlot() >= 5 + Equipment.ARMOR_SLOTS && packetIn.getSlot() < 5 + Equipment.ARMOR_SLOTS + entityplayer.getInventoryCapacity()) + if (packetIn.getWindowId() == 0 && packetIn.getSlot() >= Equipment.ARMOR_SLOTS && packetIn.getSlot() < Equipment.ARMOR_SLOTS + entityplayer.getInventoryCapacity()) { ItemStack itemstack = entityplayer.inventoryContainer.getSlot(packetIn.getSlot()).getStack(); diff --git a/common/src/main/java/common/block/tech/BlockWorkbench.java b/common/src/main/java/common/block/tech/BlockWorkbench.java index c6175b41..25712193 100755 --- a/common/src/main/java/common/block/tech/BlockWorkbench.java +++ b/common/src/main/java/common/block/tech/BlockWorkbench.java @@ -15,17 +15,17 @@ import common.world.World; public class BlockWorkbench extends Block { - private final int size; + private final int tier; - public BlockWorkbench(int size) + public BlockWorkbench(int tier) { super(Material.WOOD); this.setTab(CheatTab.TECHNOLOGY); - this.size = size; + this.tier = tier; } - public int getSize() { - return this.size; + public int getTier() { + return this.tier; } public boolean onUse(World worldIn, LocalPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ) diff --git a/common/src/main/java/common/entity/animal/EntitySheep.java b/common/src/main/java/common/entity/animal/EntitySheep.java index 34f4c984..5f2c3976 100755 --- a/common/src/main/java/common/entity/animal/EntitySheep.java +++ b/common/src/main/java/common/entity/animal/EntitySheep.java @@ -14,15 +14,11 @@ import common.entity.item.EntityItem; import common.entity.npc.EntityNPC; import common.entity.types.EntityAnimal; import common.entity.types.EntityLiving; -import common.init.CraftingRegistry; import common.init.ItemRegistry; import common.init.Items; import common.init.SoundEvent; -import common.inventory.Container; -import common.inventory.InventoryCrafting; import common.item.Item; import common.item.ItemStack; -import common.item.material.ItemDye; import common.item.tool.ItemTool; import common.pathfinding.PathNavigateGround; import common.rng.Random; @@ -35,22 +31,6 @@ import common.world.World; public class EntitySheep extends EntityAnimal { - /** - * Internal crafting inventory used to check the result of mixing dyes corresponding to the fleece color when - * breeding sheep. - */ - private final InventoryCrafting inventoryCrafting = new InventoryCrafting(new Container() - { - public boolean canInteractWith(EntityNPC playerIn) - { - return false; - } - }, 2, 1); - - /** - * Used to control movement as well as wool regrowth. Set to 40 on handleHealthUpdate and counts down with each - * tick. - */ private int sheepTimer; private EntityAIEatGrass entityAIEatGrass = new EntityAIEatGrass(this); @@ -298,7 +278,7 @@ public class EntitySheep extends EntityAnimal { EntitySheep entitysheep = (EntitySheep)ageable; EntitySheep entitysheep1 = new EntitySheep(this.worldObj); - entitysheep1.setFleeceColor(this.getDyeColorMixFromParents(this, entitysheep)); + entitysheep1.setFleeceColor(this.worldObj.rand.chance() ? this.getFleeceColor() : entitysheep.getFleeceColor()); return entitysheep1; } @@ -323,27 +303,6 @@ public class EntitySheep extends EntityAnimal return livingdata; } - private Color getDyeColorMixFromParents(EntityAnimal father, EntityAnimal mother) - { - Color i = ((EntitySheep)father).getFleeceColor(); - Color j = ((EntitySheep)mother).getFleeceColor(); - this.inventoryCrafting.setInventorySlotContents(0, new ItemStack(ItemDye.getByColor(i))); - this.inventoryCrafting.setInventorySlotContents(1, new ItemStack(ItemDye.getByColor(j))); - ItemStack itemstack = CraftingRegistry.getMatching(this.inventoryCrafting); - Color k; - - if (itemstack != null && itemstack.getItem() instanceof ItemDye dye) - { - k = dye.getColor(); - } - else - { - k = this.worldObj.rand.chance() ? i : j; - } - - return k; - } - public float getEyeHeight() { return 0.95F * this.height; diff --git a/common/src/main/java/common/init/BlockRegistry.java b/common/src/main/java/common/init/BlockRegistry.java index 8345e4d6..da4a6fe8 100755 --- a/common/src/main/java/common/init/BlockRegistry.java +++ b/common/src/main/java/common/init/BlockRegistry.java @@ -543,9 +543,9 @@ public abstract class BlockRegistry { register("core", new BlockCore().setHardness(1.5F).setResistance(10.0F).setSound(SoundType.STONE).setDisplay("Chunk-Lade-Kern")); register("mob_spawner", (new BlockMobSpawner()).setHardness(3.0F).setResistance(8.0F).setSound(SoundType.STONE).setDisplay("Mob-Spawner")); - register("workbench", (new BlockWorkbench(3)).setHardness(2.5F).setSound(SoundType.WOOD).setDisplay("Werkbank")); - register("construction_table", (new BlockWorkbench(4)).setHardness(2.5F).setSound(SoundType.WOOD).setDisplay("Konstruktionstisch")); - register("assembly_unit", (new BlockWorkbench(5)).setHardness(2.5F).setSound(SoundType.WOOD).setDisplay("Fertigungseinheit")); + register("workbench", (new BlockWorkbench(1)).setHardness(2.5F).setSound(SoundType.WOOD).setDisplay("Werkbank")); + register("construction_table", (new BlockWorkbench(2)).setHardness(2.5F).setSound(SoundType.WOOD).setDisplay("Konstruktionstisch")); + register("assembly_unit", (new BlockWorkbench(3)).setHardness(2.5F).setSound(SoundType.WOOD).setDisplay("Fertigungseinheit")); BlockFurnace stone_furnace = (BlockFurnace)register("stone_furnace", new BlockFurnace(200, 100).setDisplay("Steinofen")); register("lit_stone_furnace", new BlockFurnace(stone_furnace)); diff --git a/common/src/main/java/common/init/CraftingRegistry.java b/common/src/main/java/common/init/CraftingRegistry.java index a0260752..d95a13d7 100755 --- a/common/src/main/java/common/init/CraftingRegistry.java +++ b/common/src/main/java/common/init/CraftingRegistry.java @@ -1,34 +1,25 @@ package common.init; -import java.util.Collections; -import java.util.Comparator; import java.util.List; -import java.util.Map; -import java.util.Set; - -import common.block.artificial.BlockBed; -import common.block.artificial.BlockCarpet; -import common.block.artificial.BlockStainedGlass; -import common.block.artificial.BlockStainedGlassPane; -import common.block.artificial.BlockWool; -import common.block.natural.BlockColoredClay; import common.collect.Lists; -import common.collect.Maps; -import common.inventory.InventoryCrafting; +import common.entity.npc.EntityNPC; +import common.inventory.IInventory; import common.item.Item; import common.item.ItemStack; -import common.item.material.ItemDye; -import common.util.Color; import common.util.Equipment; public abstract class CraftingRegistry { - private static final List recipes = Lists.newArrayList(); + private static final List RECIPES = Lists.newArrayList(); - private static void registerTools(ToolMaterial material, Item item, String name) { + private static void registerTools(int tier, ToolMaterial material, Item item, String name) { for(Equipment tool : Equipment.values()) { - if(tool.getRecipe().length > 0 && tool.canRegister(material)) - add(new ItemStack(ItemRegistry.byName(name + "_" + tool.getName())), tool.getRecipe(), '#', Items.stick, 'X', item); + if((tool.getRecipeItems() > 0 || tool.getRecipeSticks() > 0) && tool.canRegister(material)) { + if(tool.getRecipeSticks() > 0) + add(tier, new ItemStack(ItemRegistry.byName(name + "_" + tool.getName())), tool.getRecipeItems(), item, tool.getRecipeSticks(), Items.stick); + else + add(tier, new ItemStack(ItemRegistry.byName(name + "_" + tool.getName())), tool.getRecipeItems(), item); + } } } @@ -37,26 +28,27 @@ public abstract class CraftingRegistry for(OreType ore : OreType.values()) { Item item = ItemRegistry.byName(ore.item); ore.material.addRepairItem(item); - registerTools(ore.material, item, ore.name); + registerTools(1, ore.material, item, ore.name); Item block = ItemRegistry.byName(ore.name + "_block"); - add(new ItemStack(block), "###", "###", "###", '#', item); - add(new ItemStack(item, 9), "#", '#', block); + add(1, new ItemStack(block), 9, item); + add(1, new ItemStack(item, 9), block); } for(MetalType metal : MetalType.values()) { Item item = ItemRegistry.byName(metal.isPowder ? (metal.name + "_powder") : (metal.name + "_ingot")); metal.material.addRepairItem(item); - registerTools(metal.material, item, metal.name); + registerTools(1, metal.material, item, metal.name); Item block = ItemRegistry.byName(metal.name + "_block"); - add(new ItemStack(block), "###", "###", "###", '#', item); - add(new ItemStack(item, 9), "#", '#', block); + add(1, new ItemStack(block), 9, item); + add(1, new ItemStack(item, 9), block); } for(ToolType tool : ToolType.values()) { for(String itm : tool.items) { Item item = ItemRegistry.byName(itm); tool.material.addRepairItem(item); - registerTools(tool.material, item, tool.name); + registerTools(1, tool.material, item, tool.name); } } + /* for(MineralType mineral : MineralType.values()) { Item item = ItemRegistry.byName(mineral.name + "_block"); Item carved = ItemRegistry.byName(mineral.name + "_ornaments"); @@ -153,9 +145,6 @@ public abstract class CraftingRegistry add(new ItemStack(BlockCarpet.getByColor(color).getItem(), 3), "##", '#', BlockWool.getByColor(color).getItem()); } - recipes.add(new RecipesDyes()); - recipes.add(new RecipeRepairItem()); - add(new ItemStack(Items.paper, 3), "###", '#', Items.reeds); addShapeless(new ItemStack(Items.book, 1), Items.paper, Items.paper, Items.paper, Items.leather); for(WoodType wood : WoodType.values()) { @@ -282,287 +271,189 @@ public abstract class CraftingRegistry add(new ItemStack(Items.construction_table), "---", "-#-", "---", '#', Items.workbench, '-', Items.iron_ingot); add(new ItemStack(Items.bedrock), "#####", "#####", "#####", "#####", "#####", '#', Items.obsidian); - - Collections.sort(recipes, new Comparator() - { - public int compare(IRecipe r1, IRecipe r2) - { - return r1 instanceof ShapelessRecipes && r2 instanceof ShapedRecipes ? 1 : (r2 instanceof ShapelessRecipes && r1 instanceof ShapedRecipes ? -1 : (r2.getRecipeSize() < r1.getRecipeSize() ? -1 : (r2.getRecipeSize() > r1.getRecipeSize() ? 1 : 0))); - } - }); - } - - private static ShapedRecipes add(ItemStack stack, Object ... recipeComponents) - { - String s = ""; - int i = 0; - int j = 0; - int k = 0; - - if (recipeComponents[i] instanceof String[]) - { - String[] astring = (String[])((String[])recipeComponents[i++]); - - for (int l = 0; l < astring.length; ++l) - { - String s2 = astring[l]; - ++k; - j = s2.length(); - s = s + s2; - } - } - else - { - while (recipeComponents[i] instanceof String) - { - String s1 = (String)recipeComponents[i++]; - ++k; - j = s1.length(); - s = s + s1; - } - } - - Map map; - - for (map = Maps.newHashMap(); i < recipeComponents.length; i += 2) - { - Character character = (Character)recipeComponents[i]; - ItemStack itemstack = null; - - if (recipeComponents[i + 1] instanceof Item) - { - itemstack = new ItemStack((Item)recipeComponents[i + 1]); - } - else if (recipeComponents[i + 1] instanceof ItemStack) - { - itemstack = (ItemStack)recipeComponents[i + 1]; - } - else - { - throw new IllegalArgumentException("Invalid shaped recipe: unknown type " + recipeComponents[i + 1].getClass().getName() + "!"); - } - - map.put(character, itemstack); - } - - ItemStack[] aitemstack = new ItemStack[j * k]; - - for (int i1 = 0; i1 < j * k; ++i1) - { - char c0 = s.charAt(i1); - - if (map.containsKey(Character.valueOf(c0))) - { - aitemstack[i1] = ((ItemStack)map.get(Character.valueOf(c0))).copy(); - } - else - { - aitemstack[i1] = null; - } - } - - ShapedRecipes shapedrecipes = new ShapedRecipes(j, k, aitemstack, stack); - recipes.add(shapedrecipes); - return shapedrecipes; - } - - private static void addShapeless(ItemStack stack, Object ... recipeComponents) - { - List list = Lists.newArrayList(); - - for (Object object : recipeComponents) - { - if (object instanceof ItemStack) - { - list.add(((ItemStack)object).copy()); - } - else if (object instanceof Item) - { - list.add(new ItemStack((Item)object)); - } - else - { - throw new IllegalArgumentException("Invalid shapeless recipe: unknown type " + object.getClass().getName() + "!"); - } - } - - recipes.add(new ShapelessRecipes(stack, list)); - } - - public static ItemStack getMatching(InventoryCrafting inv) - { - for (IRecipe irecipe : recipes) - { - if (irecipe.matches(inv)) - { - return irecipe.getCraftingResult(inv); - } - } - - return null; + */ } - public static ItemStack[] getRemaining(InventoryCrafting inv) - { - for (IRecipe irecipe : recipes) - { - if (irecipe.matches(inv)) - { - return irecipe.getRemainingItems(inv); - } - } + private static void add(int tier, ItemStack stack, Object... recipeComponents) { + List list = Lists.newArrayList(); + int amount = 0; + for(Object object : recipeComponents) { + if(object instanceof Integer amt) { + if(amt <= 0) + throw new IllegalArgumentException("Ungültiges Rezept: Anzahl muss mindestens 1 betragen"); + amount = amt; + } + else if(object instanceof ItemStack item) { + if(amount != 0) + throw new IllegalArgumentException("Ungültiges Rezept: Kann keine Anzahl mit einem Stapel kombinieren"); + list.add(item.copy()); + } + else if(object instanceof Item item) { + list.add(new ItemStack(item, amount == 0 ? 1 : amount)); + amount = 0; + } + else { + throw new IllegalArgumentException("Ungültiges Rezept: unbekannter Typ " + object.getClass().getName()); + } + } + RECIPES.add(new IRecipe(RECIPES.size(), tier, list.toArray(new ItemStack[list.size()]), stack)); + } - ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()]; + private static boolean matches(IInventory input, IInventory output, IRecipe recipe, int tier, boolean allowDrop) { + if(tier < recipe.getTier()) + return false; + if(input != null) { + for(ItemStack stack : recipe.getRequiredItems()) { + int amount = stack.getSize(); + int size = input instanceof EntityNPC entity ? entity.getInventoryCapacity() : input.getSizeInventory(); + for(int z = 0; z < size && amount > 0; z++) { + ItemStack current = input.getStackInSlot(z); + if(current != null && stack.itemEquals(current) && stack.dataEquals(current)) { + amount -= Math.min(amount, current.getSize()); + if(amount <= 0) + break; + } + } + if(amount > 0) + return false; + } + } + if(output != null && (!allowDrop || !(output instanceof EntityNPC))) { + for(ItemStack stack : recipe.getCraftedItems()) { + int amount = stack.getSize(); + int size = output instanceof EntityNPC entity ? entity.getInventoryCapacity() : output.getSizeInventory(); + for(int z = 0; z < size && amount > 0; z++) { + ItemStack current = output.getStackInSlot(z); + if(current == null) { + amount = 0; + break; + } + else if(current != null && stack.itemEquals(current) && stack.dataEquals(current)) { + int incr = Math.min(amount, current.getMaxStackSize() - current.getSize()); + if(incr > 0) { + amount -= incr; + if(amount <= 0) + break; + } + } + } + if(amount > 0) + return false; + } + } + return true; + } + + public static void doCrafting(IInventory input, IInventory output, int tier, IRecipe recipe) { + if(matches(input, output, recipe, tier, false)) + swapItems(input, output, recipe); + } + + public static void doCrafting(EntityNPC entity, int tier, int id) { + if(id >= 0 && id < RECIPES.size()) { + IRecipe recipe = RECIPES.get(id); + if(matches(entity, entity, recipe, tier, true)) + swapItems(entity, entity, recipe); + } + } - for (int i = 0; i < aitemstack.length; ++i) - { - aitemstack[i] = inv.getStackInSlot(i); - } + public static List getMatching(EntityNPC entity, int tier) { + List list = Lists.newArrayList(); + for(IRecipe recipe : RECIPES) { + if(matches(entity, entity, recipe, tier, true)) + list.add(recipe); + } + return list; + } - return aitemstack; - } + private static void swapItems(IInventory input, IInventory output, IRecipe recipe) { + for(ItemStack stack : recipe.getRequiredItems()) { + int amount = stack.getSize(); + int size = input instanceof EntityNPC entity ? entity.getInventoryCapacity() : input.getSizeInventory(); + for(int z = 0; z < size && amount > 0; z++) { + ItemStack current = input.getStackInSlot(z); + if(current != null && stack.itemEquals(current) && stack.dataEquals(current)) { + int decr = Math.min(amount, current.getSize()); + input.decrStackSize(z, decr); + amount -= decr; + if(amount <= 0) + break; + } + } + } + for(ItemStack stack : recipe.getCraftedItems()) { + int amount = stack.getSize(); + int size = output instanceof EntityNPC entity ? entity.getInventoryCapacity() : output.getSizeInventory(); + for(int z = 0; z < size && amount > 0; z++) { + ItemStack current = output.getStackInSlot(z); + if(current == null) { + output.setInventorySlotContents(z, stack.copy(amount)); + amount = 0; + break; + } + else if(current != null && stack.itemEquals(current) && stack.dataEquals(current)) { + int incr = Math.min(amount, current.getMaxStackSize() - current.getSize()); + if(incr > 0) { + current.incrSize(incr); + output.setInventorySlotContents(z, current); + amount -= incr; + if(amount <= 0) + break; + } + } + } + if(amount > 0 && output instanceof EntityNPC entity) + entity.dropItem(stack.copy(amount), false); + } + } - public static void getRecipeList(Set set) - { - for (IRecipe irecipe : recipes) - { - if (irecipe.getRecipeOutput() != null) - { - set.add(irecipe.getRecipeOutput().getItem()); - } - } - } - - private static interface IRecipe { - boolean matches(InventoryCrafting inv); - ItemStack getCraftingResult(InventoryCrafting inv); - int getRecipeSize(); - ItemStack getRecipeOutput(); - ItemStack[] getRemainingItems(InventoryCrafting inv); - } - - private static class RecipeRepairItem implements IRecipe - { - /** - * Used to check if a recipe matches current crafting inventory - */ - public boolean matches(InventoryCrafting inv) - { - List list = Lists.newArrayList(); + public static List getRecipeList(int tier) { + List list = Lists.newArrayList(); + for(IRecipe irecipe : RECIPES) { + if(irecipe.getTier() <= tier) + list.add(irecipe); + } + return list; + } - for (int i = 0; i < inv.getSizeInventory(); ++i) - { - ItemStack itemstack = inv.getStackInSlot(i); + public static class IRecipe { + private final int id; + private final int tier; + private final ItemStack[] recipeItems; + private final ItemStack[] recipeOutput; - if (itemstack != null) - { - list.add(itemstack); + public IRecipe(int id, int tier, ItemStack[] inputs, ItemStack output) { + this.id = id; + this.tier = tier; + this.recipeItems = inputs; + List out = Lists.newArrayList(output); + for(ItemStack stack : inputs) { + if(stack.getItem().hasContainerItem()) + out.add(new ItemStack(stack.getItem().getContainerItem())); + } + this.recipeOutput = out.toArray(new ItemStack[out.size()]); + } - if (list.size() > 1) - { - ItemStack itemstack1 = (ItemStack)list.get(0); + public int getId() { + return this.id; + } - if (itemstack.getItem() != itemstack1.getItem() || itemstack1.getSize() != 1 || itemstack.getSize() != 1 || !itemstack1.getItem().isDamageable()) - { - return false; - } - } - } - } + public int getTier() { + return this.tier; + } - return list.size() == 2; - } + public ItemStack[] getRequiredItems() { + return this.recipeItems; + } - /** - * Returns an Item that is the result of this recipe - */ - public ItemStack getCraftingResult(InventoryCrafting inv) - { - List list = Lists.newArrayList(); + public ItemStack[] getCraftedItems() { + return this.recipeOutput; + } + } - for (int i = 0; i < inv.getSizeInventory(); ++i) - { - ItemStack itemstack = inv.getStackInSlot(i); - - if (itemstack != null) - { - list.add(itemstack); - - if (list.size() > 1) - { - ItemStack itemstack1 = (ItemStack)list.get(0); - - if (itemstack.getItem() != itemstack1.getItem() || itemstack1.getSize() != 1 || itemstack.getSize() != 1 || !itemstack1.getItem().isDamageable()) - { - return null; - } - } - } - } - - if (list.size() == 2) - { - ItemStack itemstack2 = (ItemStack)list.get(0); - ItemStack itemstack3 = (ItemStack)list.get(1); - - if (itemstack2.getItem() == itemstack3.getItem() && itemstack2.getSize() == 1 && itemstack3.getSize() == 1 && itemstack2.getItem().isDamageable()) - { - Item item = itemstack2.getItem(); - int j = item.getMaxDamage() - itemstack2.getItemDamage(); - int k = item.getMaxDamage() - itemstack3.getItemDamage(); - int l = j + k + item.getMaxDamage() * 5 / 100; - int i1 = item.getMaxDamage() - l; - - if (i1 < 0) - { - i1 = 0; - } - - ItemStack stack = new ItemStack(itemstack2.getItem()); - stack.setItemDamage(i1); - return stack; - } - } - - return null; - } - - /** - * Returns the size of the recipe area - */ - public int getRecipeSize() - { - return 4; - } - - public ItemStack getRecipeOutput() - { - return null; - } - - public ItemStack[] getRemainingItems(InventoryCrafting inv) - { - ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()]; - - for (int i = 0; i < aitemstack.length; ++i) - { - ItemStack itemstack = inv.getStackInSlot(i); - - if (itemstack != null && itemstack.getItem().hasContainerItem()) - { - aitemstack[i] = new ItemStack(itemstack.getItem().getContainerItem()); - } - } - - return aitemstack; - } - } - + /* private static class RecipesDyes implements IRecipe { - /** - * Used to check if a recipe matches current crafting inventory - */ public boolean matches(InventoryCrafting inv) { ItemStack itemstack = null; @@ -598,9 +489,6 @@ public abstract class CraftingRegistry return itemstack != null && !list.isEmpty(); } - /** - * Returns an Item that is the result of this recipe - */ public ItemStack getCraftingResult(InventoryCrafting inv) { ItemStack itemstack = null; @@ -677,9 +565,6 @@ public abstract class CraftingRegistry } } - /** - * Returns the size of the recipe area - */ public int getRecipeSize() { return 10; @@ -707,223 +592,5 @@ public abstract class CraftingRegistry return aitemstack; } } - - private static class ShapedRecipes implements IRecipe - { - /** How many horizontal slots this recipe is wide. */ - private final int recipeWidth; - - /** How many vertical slots this recipe uses. */ - private final int recipeHeight; - - /** Is a array of ItemStack that composes the recipe. */ - private final ItemStack[] recipeItems; - - /** Is the ItemStack that you get when craft the recipe. */ - private final ItemStack recipeOutput; - - public ShapedRecipes(int width, int height, ItemStack[] p_i1917_3_, ItemStack output) - { - this.recipeWidth = width; - this.recipeHeight = height; - this.recipeItems = p_i1917_3_; - this.recipeOutput = output; - } - - public ItemStack getRecipeOutput() - { - return this.recipeOutput; - } - - public ItemStack[] getRemainingItems(InventoryCrafting inv) - { - ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()]; - - for (int i = 0; i < aitemstack.length; ++i) - { - ItemStack itemstack = inv.getStackInSlot(i); - - if (itemstack != null && itemstack.getItem().hasContainerItem()) - { - aitemstack[i] = new ItemStack(itemstack.getItem().getContainerItem()); - } - } - - return aitemstack; - } - - /** - * Used to check if a recipe matches current crafting inventory - */ - public boolean matches(InventoryCrafting inv) - { - for (int i = 0; i <= inv.getWidth() - this.recipeWidth; ++i) - { - for (int j = 0; j <= inv.getHeight() - this.recipeHeight; ++j) - { - if (this.checkMatch(inv, i, j, true)) - { - return true; - } - - if (this.checkMatch(inv, i, j, false)) - { - return true; - } - } - } - - return false; - } - - /** - * Checks if the region of a crafting inventory is match for the recipe. - */ - private boolean checkMatch(InventoryCrafting inv, int xPos, int yPos, boolean mirror) - { - for (int x = 0; x < inv.getWidth(); ++x) - { - for (int y = 0; y < inv.getHeight(); ++y) - { - int rx = x - xPos; - int ry = y - yPos; - ItemStack stack = null; - - if (rx >= 0 && ry >= 0 && rx < this.recipeWidth && ry < this.recipeHeight) - { - if (mirror) - { - stack = this.recipeItems[this.recipeWidth - rx - 1 + ry * this.recipeWidth]; - } - else - { - stack = this.recipeItems[rx + ry * this.recipeWidth]; - } - } - - ItemStack ingredient = inv.getStackInRowAndColumn(x, y); - - if (ingredient != null || stack != null) - { - if (ingredient == null && stack != null || ingredient != null && stack == null) - { - return false; - } - - if (stack.getItem() != ingredient.getItem()) - { - return false; - } - } - } - } - - return true; - } - - /** - * Returns an Item that is the result of this recipe - */ - public ItemStack getCraftingResult(InventoryCrafting inv) - { - return this.getRecipeOutput().copy(); - } - - /** - * Returns the size of the recipe area - */ - public int getRecipeSize() - { - return this.recipeWidth * this.recipeHeight; - } - } - - private static class ShapelessRecipes implements IRecipe - { - /** Is the ItemStack that you get when craft the recipe. */ - private final ItemStack recipeOutput; - private final List recipeItems; - - public ShapelessRecipes(ItemStack output, List inputList) - { - this.recipeOutput = output; - this.recipeItems = inputList; - } - - public ItemStack getRecipeOutput() - { - return this.recipeOutput; - } - - public ItemStack[] getRemainingItems(InventoryCrafting inv) - { - ItemStack[] aitemstack = new ItemStack[inv.getSizeInventory()]; - - for (int i = 0; i < aitemstack.length; ++i) - { - ItemStack itemstack = inv.getStackInSlot(i); - - if (itemstack != null && itemstack.getItem().hasContainerItem()) - { - aitemstack[i] = new ItemStack(itemstack.getItem().getContainerItem()); - } - } - - return aitemstack; - } - - /** - * Used to check if a recipe matches current crafting inventory - */ - public boolean matches(InventoryCrafting inv) - { - List list = Lists.newArrayList(this.recipeItems); - - for (int i = 0; i < inv.getHeight(); ++i) - { - for (int j = 0; j < inv.getWidth(); ++j) - { - ItemStack itemstack = inv.getStackInRowAndColumn(j, i); - - if (itemstack != null) - { - boolean flag = false; - - for (ItemStack itemstack1 : list) - { - if (itemstack.getItem() == itemstack1.getItem()) - { - flag = true; - list.remove(itemstack1); - break; - } - } - - if (!flag) - { - return false; - } - } - } - } - - return list.isEmpty(); - } - - /** - * Returns an Item that is the result of this recipe - */ - public ItemStack getCraftingResult(InventoryCrafting inv) - { - return this.recipeOutput.copy(); - } - - /** - * Returns the size of the recipe area - */ - public int getRecipeSize() - { - return this.recipeItems.size(); - } - } + */ } diff --git a/common/src/main/java/common/inventory/Container.java b/common/src/main/java/common/inventory/Container.java index 313ceec8..b7fe2b4a 100755 --- a/common/src/main/java/common/inventory/Container.java +++ b/common/src/main/java/common/inventory/Container.java @@ -526,14 +526,6 @@ public abstract class Container } } - /** - * Callback for when the crafting matrix is changed. - */ - public void onCraftMatrixChanged(IInventory inventoryIn) - { - this.detectAndSendChanges(); - } - /** * args: slotID, itemStack to put in slot */ diff --git a/common/src/main/java/common/inventory/ContainerEnchantment.java b/common/src/main/java/common/inventory/ContainerEnchantment.java index ef6b286f..c299527c 100755 --- a/common/src/main/java/common/inventory/ContainerEnchantment.java +++ b/common/src/main/java/common/inventory/ContainerEnchantment.java @@ -38,7 +38,7 @@ public class ContainerEnchantment extends Container public void markDirty() { super.markDirty(); - ContainerEnchantment.this.onCraftMatrixChanged(this); + ContainerEnchantment.this.onChanged(this); } }; this.rand = new Random(); @@ -126,7 +126,7 @@ public class ContainerEnchantment extends Container } } - public void onCraftMatrixChanged(IInventory inventoryIn) + private void onChanged(IInventory inventoryIn) { if (inventoryIn == this.table) { @@ -248,7 +248,7 @@ public class ContainerEnchantment extends Container this.table.markDirty(); this.seed = player.getEnchSeed(); - this.onCraftMatrixChanged(this.table); + this.onChanged(this.table); } } diff --git a/common/src/main/java/common/inventory/ContainerMerchant.java b/common/src/main/java/common/inventory/ContainerMerchant.java index 12e47daf..77cb4079 100755 --- a/common/src/main/java/common/inventory/ContainerMerchant.java +++ b/common/src/main/java/common/inventory/ContainerMerchant.java @@ -52,15 +52,6 @@ public class ContainerMerchant extends Container super.detectAndSendChanges(); } - /** - * Callback for when the crafting matrix is changed. - */ - public void onCraftMatrixChanged(IInventory inventoryIn) - { - this.merchantInventory.resetRecipeAndSlots(); - super.onCraftMatrixChanged(inventoryIn); - } - public void setCurrentRecipeIndex(int currentRecipeIndex) { this.merchantInventory.setCurrentRecipeIndex(currentRecipeIndex); diff --git a/common/src/main/java/common/inventory/ContainerPlayer.java b/common/src/main/java/common/inventory/ContainerPlayer.java index 7599f154..20432fe7 100755 --- a/common/src/main/java/common/inventory/ContainerPlayer.java +++ b/common/src/main/java/common/inventory/ContainerPlayer.java @@ -1,37 +1,16 @@ package common.inventory; import common.entity.npc.EntityNPC; -import common.init.CraftingRegistry; import common.item.ItemStack; import common.item.material.ItemArmor; import common.util.Equipment; public class ContainerPlayer extends Container { - private final InventoryCrafting baseCrafting = new InventoryCrafting(new Container() { - public boolean canInteractWith(EntityNPC playerIn) { - return false; - } - }, 1, 1); - private final InventoryCrafting craftMatrix = new InventoryCrafting(this, 2, 2); - private final IInventory craftResult = new InventoryCraftResult(); private final EntityNPC thePlayer; public ContainerPlayer(EntityNPC player) { this.thePlayer = player; - this.addSlotToContainer(new SlotCrafting(player, this.craftMatrix, this.craftResult, 0, 144, 36)); - - for (int i = 0; i < 2; ++i) - { - for (int j = 0; j < 2; ++j) - { - this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 2, 88 + j * 18, 26 + i * 18) { - public boolean canEditItem() { - return false; - } - }); - } - } for (Equipment slot : Equipment.ARMOR) { @@ -56,53 +35,24 @@ public class ContainerPlayer extends Container { { this.addSlotToContainer(new Slot(player, l, 8 + (l % 12) * 18, 84 + (l / 12) * 18)); } - - this.onCraftMatrixChanged(this.craftMatrix); - } - - /** - * Callback for when the crafting matrix is changed. - */ - public void onCraftMatrixChanged(IInventory inventoryIn) - { - this.craftResult.setInventorySlotContents(0, CraftingRegistry.getMatching(this.craftMatrix)); } public ItemStack getSingleRecipe(ItemStack stack) { - this.baseCrafting.setInventorySlotContents(0, stack); - stack = CraftingRegistry.getMatching(this.baseCrafting); - this.baseCrafting.setInventorySlotContents(0, null); - return stack; + return null; +// this.baseCrafting.setInventorySlotContents(0, stack); +// stack = CraftingRegistry.getMatching(this.baseCrafting); +// this.baseCrafting.setInventorySlotContents(0, null); +// return stack; } public ItemStack craftSingleRecipe(ItemStack stack) { - this.baseCrafting.setInventorySlotContents(0, stack); - SlotCrafting.handleRemaining(this.baseCrafting, this.thePlayer); - stack = this.baseCrafting.getStackInSlot(0); - this.baseCrafting.setInventorySlotContents(0, null); +// this.baseCrafting.setInventorySlotContents(0, stack); +// SlotCrafting.handleRemaining(this.baseCrafting, this.thePlayer); +// stack = this.baseCrafting.getStackInSlot(0); +// this.baseCrafting.setInventorySlotContents(0, null); return stack; } - /** - * Called when the container is closed. - */ - public void onContainerClosed(EntityNPC playerIn) - { - super.onContainerClosed(playerIn); - - for (int i = 0; i < 4; ++i) - { - ItemStack itemstack = this.craftMatrix.removeStackFromSlot(i); - - if (itemstack != null) - { - playerIn.dropItem(itemstack, false); - } - } - - this.craftResult.setInventorySlotContents(0, (ItemStack)null); - } - public boolean canInteractWith(EntityNPC playerIn) { return true; @@ -110,8 +60,8 @@ public class ContainerPlayer extends Container { private int getFreeSlotFor(Equipment type) { for(Equipment slot : type.getPossibleSlots(this.thePlayer)) { - if(!this.inventorySlots.get(5 + slot.getIndex()).getHasStack()) - return 5 + slot.getIndex(); + if(!this.inventorySlots.get(slot.getIndex()).getHasStack()) + return slot.getIndex(); } return -1; } @@ -127,25 +77,9 @@ public class ContainerPlayer extends Container { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); - if (index == 0) + if (index >= 0 && index < Equipment.ARMOR_SLOTS) { - if (!this.mergeItemStack(itemstack1, 5 + Equipment.ARMOR_SLOTS, 5 + Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity(), true)) - { - return null; - } - - slot.onSlotChange(itemstack1, itemstack); - } - else if (index >= 1 && index < 5) - { - if (!this.mergeItemStack(itemstack1, 5 + Equipment.ARMOR_SLOTS, 5 + Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity(), false)) - { - return null; - } - } - else if (index >= 5 && index < 5 + Equipment.ARMOR_SLOTS) - { - if (!this.mergeItemStack(itemstack1, 5 + Equipment.ARMOR_SLOTS, 5 + Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity(), false)) + if (!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity(), false)) { return null; } @@ -157,11 +91,11 @@ public class ContainerPlayer extends Container { return null; } } - else if (index >= 5 + Equipment.ARMOR_SLOTS && index < 5 + Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity()) + else if (index >= Equipment.ARMOR_SLOTS && index < Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity()) { return null; } - else if (!this.mergeItemStack(itemstack1, 5 + Equipment.ARMOR_SLOTS, 5 + Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity(), false)) + else if (!this.mergeItemStack(itemstack1, Equipment.ARMOR_SLOTS, Equipment.ARMOR_SLOTS + playerIn.getInventoryCapacity(), false)) { return null; } @@ -185,13 +119,4 @@ public class ContainerPlayer extends Container { return itemstack; } - - /** - * Called to determine if the current slot is valid for the stack merging (double-click) code. The stack passed in - * is null for the initial slot that was double-clicked. - */ - public boolean canMergeSlot(ItemStack stack, Slot slotIn) - { - return slotIn.inventory != this.craftResult && super.canMergeSlot(stack, slotIn); - } } diff --git a/common/src/main/java/common/inventory/ContainerRepair.java b/common/src/main/java/common/inventory/ContainerRepair.java index 2373bbaa..c6fae1cd 100755 --- a/common/src/main/java/common/inventory/ContainerRepair.java +++ b/common/src/main/java/common/inventory/ContainerRepair.java @@ -37,7 +37,7 @@ public class ContainerRepair extends Container public void markDirty() { super.markDirty(); - ContainerRepair.this.onCraftMatrixChanged(this); + ContainerRepair.this.onChanged(this); } }; this.selfPosition = blockPosIn; @@ -127,17 +127,10 @@ public class ContainerRepair extends Container } } - /** - * Callback for when the crafting matrix is changed. - */ - public void onCraftMatrixChanged(IInventory inventoryIn) + private void onChanged(IInventory inventoryIn) { - super.onCraftMatrixChanged(inventoryIn); - - if (inventoryIn == this.inputSlots) - { - this.updateRepairOutput(); - } + this.detectAndSendChanges(); + this.updateRepairOutput(); } /** diff --git a/common/src/main/java/common/inventory/ContainerWorkbench.java b/common/src/main/java/common/inventory/ContainerWorkbench.java index d6330646..9de48361 100755 --- a/common/src/main/java/common/inventory/ContainerWorkbench.java +++ b/common/src/main/java/common/inventory/ContainerWorkbench.java @@ -2,151 +2,34 @@ package common.inventory; import common.block.tech.BlockWorkbench; import common.entity.npc.EntityNPC; -import common.init.CraftingRegistry; import common.item.ItemStack; import common.util.LocalPos; import common.world.World; -public class ContainerWorkbench extends Container -{ - private final int craftSlots; - public final InventoryCrafting craftMatrix; - public final IInventory craftResult = new InventoryCraftResult(); - private final World worldObj; - private final LocalPos pos; - private final BlockWorkbench block; +public class ContainerWorkbench extends Container { + private final World worldObj; + private final LocalPos pos; + private final BlockWorkbench block; - public ContainerWorkbench(EntityNPC playerInventory, World worldIn, LocalPos posIn, BlockWorkbench block) - { - int size = block.getSize(); - this.block = block; - this.worldObj = worldIn; - this.pos = posIn; - this.craftSlots = size * size; - this.craftMatrix = new InventoryCrafting(this, size, size); - this.addSlotToContainer(new SlotCrafting(playerInventory, this.craftMatrix, this.craftResult, 0, 134, 17 + ((size - 1) * 18) / 2)); + public ContainerWorkbench(EntityNPC playerInventory, World worldIn, LocalPos posIn, BlockWorkbench block) { + this.block = block; + this.worldObj = worldIn; + this.pos = posIn; + for(int l = 0; l < playerInventory.getInventoryCapacity(); ++l) { + this.addSlotToContainer(new Slot(playerInventory, l, 8 + (l % 12) * 18, 30 + 3 * 18 + (l / 12) * 18)); + } + } + + public int getTier() { + return this.block.getTier(); + } - for (int i = 0; i < size; ++i) - { - for (int j = 0; j < size; ++j) - { - this.addSlotToContainer(new Slot(this.craftMatrix, j + i * size, 26 + j * 18, 17 + i * 18) { - public boolean canEditItem() { - return false; - } - }); - } - } + public boolean canInteractWith(EntityNPC playerIn) { + return this.worldObj.getState(this.pos).getBlock() != this.block ? false + : playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D; + } - for (int l = 0; l < playerInventory.getInventoryCapacity(); ++l) - { - this.addSlotToContainer(new Slot(playerInventory, l, 8 + (l % 12) * 18, 30 + size * 18 + (l / 12) * 18)); - } - - this.onCraftMatrixChanged(this.craftMatrix); - } - - /** - * Callback for when the crafting matrix is changed. - */ - public void onCraftMatrixChanged(IInventory inventoryIn) - { - this.craftResult.setInventorySlotContents(0, CraftingRegistry.getMatching(this.craftMatrix)); - } - - /** - * Called when the container is closed. - */ - public void onContainerClosed(EntityNPC playerIn) - { - super.onContainerClosed(playerIn); - - if (!this.worldObj.client) - { - for (int i = 0; i < this.craftSlots; ++i) - { - ItemStack itemstack = this.craftMatrix.removeStackFromSlot(i); - - if (itemstack != null) - { - playerIn.dropItem(itemstack, false); - } - } - } - } - - public boolean canInteractWith(EntityNPC playerIn) - { - return this.worldObj.getState(this.pos).getBlock() != this.block ? false : playerIn.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D; - } - - /** - * Take a stack from the specified inventory slot. - */ - public ItemStack transferStackInSlot(EntityNPC playerIn, int index) - { - ItemStack itemstack = null; - Slot slot = this.inventorySlots.get(index); - - if (slot != null && slot.getHasStack()) - { - ItemStack itemstack1 = slot.getStack(); - itemstack = itemstack1.copy(); - - if (index == 0) - { - if (!this.mergeItemStack(itemstack1, this.craftSlots + 1, this.craftSlots + 37, true)) - { - return null; - } - - slot.onSlotChange(itemstack1, itemstack); - } - else if (index >= this.craftSlots + 1 && index < this.craftSlots + 28) - { - if (!this.mergeItemStack(itemstack1, this.craftSlots + 28, this.craftSlots + 37, false)) - { - return null; - } - } - else if (index >= this.craftSlots + 28 && index < this.craftSlots + 37) - { - if (!this.mergeItemStack(itemstack1, this.craftSlots + 1, this.craftSlots + 28, false)) - { - return null; - } - } - else if (!this.mergeItemStack(itemstack1, this.craftSlots + 1, this.craftSlots + 37, false)) - { - return null; - } - - if (itemstack1.isEmpty()) - { - slot.putStack((ItemStack)null); - } - else - { - slot.onSlotChanged(); - } - - if (itemstack1.getSize() == itemstack.getSize()) - { - return null; - } - - slot.onPickupFromSlot(playerIn, itemstack1); - } - - return itemstack; - } - - /** - * Called to determine if the current slot is valid for the stack merging (double-click) code. The stack passed in - * is null for the initial slot that was double-clicked. - */ - public boolean canMergeSlot(ItemStack stack, Slot slotIn) - { - return slotIn.inventory != this.craftResult && super.canMergeSlot(stack, slotIn); - } + public ItemStack transferStackInSlot(EntityNPC playerIn, int index) { + return null; + } } diff --git a/common/src/main/java/common/inventory/InventoryCrafting.java b/common/src/main/java/common/inventory/InventoryCrafting.java deleted file mode 100755 index 109fa174..00000000 --- a/common/src/main/java/common/inventory/InventoryCrafting.java +++ /dev/null @@ -1,128 +0,0 @@ -package common.inventory; - -import common.item.ItemStack; - -public class InventoryCrafting implements IInventory -{ - /** List of the stacks in the crafting matrix. */ - private final ItemStack[] stackList; - - /** the width of the crafting inventory */ - private final int inventoryWidth; - private final int inventoryHeight; - - /** - * Class containing the callbacks for the events on_GUIClosed and on_CraftMaxtrixChanged. - */ - private final Container eventHandler; - - public InventoryCrafting(Container eventHandlerIn, int width, int height) - { - int i = width * height; - this.stackList = new ItemStack[i]; - this.eventHandler = eventHandlerIn; - this.inventoryWidth = width; - this.inventoryHeight = height; - } - - /** - * Returns the number of slots in the inventory. - */ - public int getSizeInventory() - { - return this.stackList.length; - } - - /** - * Returns the stack in the given slot. - */ - public ItemStack getStackInSlot(int index) - { - return index >= this.getSizeInventory() ? null : this.stackList[index]; - } - - /** - * Returns the itemstack in the slot specified (Top left is 0, 0). Args: row, column - */ - public ItemStack getStackInRowAndColumn(int row, int column) - { - return row >= 0 && row < this.inventoryWidth && column >= 0 && column <= this.inventoryHeight ? this.getStackInSlot(row + column * this.inventoryWidth) : null; - } - - /** - * Removes a stack from the given slot and returns it. - */ - public ItemStack removeStackFromSlot(int index) - { - if (this.stackList[index] != null) - { - ItemStack itemstack = this.stackList[index]; - this.stackList[index] = null; - return itemstack; - } - else - { - return null; - } - } - - /** - * Removes up to a specified number of items from an inventory slot and returns them in a new stack. - */ - public ItemStack decrStackSize(int index, int count) - { - if (this.stackList[index] != null) - { - if (this.stackList[index].getSize() <= count) - { - ItemStack itemstack1 = this.stackList[index]; - this.stackList[index] = null; - this.eventHandler.onCraftMatrixChanged(this); - return itemstack1; - } - else - { - ItemStack itemstack = this.stackList[index].split(count); - - if (this.stackList[index].isEmpty()) - { - this.stackList[index] = null; - } - - this.eventHandler.onCraftMatrixChanged(this); - return itemstack; - } - } - else - { - return null; - } - } - - /** - * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections). - */ - public void setInventorySlotContents(int index, ItemStack stack) - { - this.stackList[index] = stack; - this.eventHandler.onCraftMatrixChanged(this); - } - - public void clear() - { - for (int i = 0; i < this.stackList.length; ++i) - { - this.stackList[i] = null; - } - } - - public int getHeight() - { - return this.inventoryHeight; - } - - public int getWidth() - { - return this.inventoryWidth; - } -} diff --git a/common/src/main/java/common/inventory/SlotCrafting.java b/common/src/main/java/common/inventory/SlotCrafting.java deleted file mode 100755 index 76ce4621..00000000 --- a/common/src/main/java/common/inventory/SlotCrafting.java +++ /dev/null @@ -1,79 +0,0 @@ -package common.inventory; - -import common.entity.npc.EntityNPC; -import common.init.CraftingRegistry; -import common.item.ItemStack; - -public class SlotCrafting extends Slot -{ - private final InventoryCrafting craftMatrix; - private final EntityNPC thePlayer; - - public static void handleRemaining(InventoryCrafting craftMatrix, EntityNPC thePlayer) { - ItemStack[] aitemstack = CraftingRegistry.getRemaining(craftMatrix); - - for (int i = 0; i < aitemstack.length; ++i) - { - ItemStack itemstack = craftMatrix.getStackInSlot(i); - ItemStack itemstack1 = aitemstack[i]; - - if (itemstack != null) - { - craftMatrix.decrStackSize(i, 1); - } - - if (itemstack1 != null) - { - if (craftMatrix.getStackInSlot(i) == null) - { - craftMatrix.setInventorySlotContents(i, itemstack1); - } - else if (!thePlayer.addItemStackToInventory(itemstack1)) - { - thePlayer.dropItem(itemstack1, false); - } - } - } - } - - public SlotCrafting(EntityNPC player, InventoryCrafting craftingInventory, IInventory p_i45790_3_, int slotIndex, int xPosition, int yPosition) - { - super(p_i45790_3_, slotIndex, xPosition, yPosition); - this.thePlayer = player; - this.craftMatrix = craftingInventory; - } - - /** - * Check if the stack is a valid item for this slot. Always true beside for the armor slots. - */ - public boolean isItemValid(ItemStack stack) - { - return false; - } - - /** - * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. Typically increases an - * internal count then calls onCrafting(item). - */ - protected void onCrafting(ItemStack stack, int amount) - { - this.onCrafting(stack); - } - - /** - * the itemStack passed in is the output - ie, iron ingots, and pickaxes, not ore and wood. - */ - protected void onCrafting(ItemStack stack) - { - } - - public void onPickupFromSlot(EntityNPC playerIn, ItemStack stack) - { - this.onCrafting(stack); - handleRemaining(this.craftMatrix, this.thePlayer); - } - - public boolean canCheatItem() { - return false; - } -} diff --git a/common/src/main/java/common/packet/CPacketAction.java b/common/src/main/java/common/packet/CPacketAction.java index 7d7b17c5..0f51d82e 100755 --- a/common/src/main/java/common/packet/CPacketAction.java +++ b/common/src/main/java/common/packet/CPacketAction.java @@ -45,9 +45,46 @@ public class CPacketAction implements Packet { } public static enum Action { - OPEN_EDITOR, CLOSE_EDITOR, CANCEL_EDITOR, SELECT_CHARACTER, DELETE_CHARACTER, SWING_ARM, SET_ITEMSLOT, START_SNEAKING, STOP_SNEAKING, - START_SPRINTING, STOP_SPRINTING, START_HOVER, STOP_HOVER, RIDING_JUMP, OPEN_INVENTORY, START_FLYING, STOP_FLYING, PERFORM_RESPAWN, SET_HEIGHT, - SET_SPECIES, SET_CLASS, SELECT_TRADE, INTERACT, ATTACK, CLOSE_CONTAINER, CONFIRM_TRANSACTION, ENCHANT_ITEM, SET_ALIGN, ITEM_ACTION, GOD, - NOCLIP, SPEED, HEAL, REPAIR, PERF, MAGNET, WARP_MODE, START_PROFILING, STOP_PROFILING, CRAFT_ITEM; + OPEN_EDITOR, + CLOSE_EDITOR, + CANCEL_EDITOR, + SELECT_CHARACTER, + DELETE_CHARACTER, + SWING_ARM, + SET_ITEMSLOT, + START_SNEAKING, + STOP_SNEAKING, + START_SPRINTING, + STOP_SPRINTING, + START_HOVER, + STOP_HOVER, + RIDING_JUMP, + OPEN_INVENTORY, + START_FLYING, + STOP_FLYING, + PERFORM_RESPAWN, + SET_HEIGHT, + SET_SPECIES, + SET_CLASS, + SELECT_TRADE, + INTERACT, + ATTACK, + CLOSE_CONTAINER, + CONFIRM_TRANSACTION, + ENCHANT_ITEM, + SET_ALIGN, + ITEM_ACTION, + GOD, + NOCLIP, + SPEED, + HEAL, + REPAIR, + PERF, + MAGNET, + WARP_MODE, + START_PROFILING, + STOP_PROFILING, + CRAFT_SINGLE, + CRAFT_ITEM; } } diff --git a/common/src/main/java/common/util/Equipment.java b/common/src/main/java/common/util/Equipment.java index 691f255e..f3d36ee0 100644 --- a/common/src/main/java/common/util/Equipment.java +++ b/common/src/main/java/common/util/Equipment.java @@ -7,17 +7,17 @@ import common.entity.types.EntityLiving; import common.init.ToolMaterial; public enum Equipment implements Identifyable, Displayable { - PICKAXE("pickaxe", "Spitzhacke", ItemType.HARVEST_LEVELLED, 2, "XXX", " # ", " # "), - AXE("axe", "Axt", ItemType.HARVEST_BASIC, 3, "XX", "X#", " #"), - SHOVEL("shovel", "Schaufel", ItemType.HARVEST_BASIC, 1, "X", "#", "#"), - SHEARS("shears", "Schere", ItemType.HARVEST_OPTIONAL, " X", "X "), + PICKAXE("pickaxe", "Spitzhacke", ItemType.HARVEST_LEVELLED, 2, 3, 2), + AXE("axe", "Axt", ItemType.HARVEST_BASIC, 3, 3, 2), + SHOVEL("shovel", "Schaufel", ItemType.HARVEST_BASIC, 1, 1, 2), + SHEARS("shears", "Schere", ItemType.HARVEST_OPTIONAL, 2, 0), - SWORD("sword", "Schwert", ItemType.MELEE_WEAPON, 4, "X", "X", "#"), + SWORD("sword", "Schwert", ItemType.MELEE_WEAPON, 4, 2, 1), - HELMET("helmet", "Helm", "Kappe", 11, 0, EnchantmentType.ARMOR_HEAD, 1.0f, 1.0f, "XXX", "X X"), - CHESTPLATE("chestplate", "Brustpanzer", "Jacke", 16, 1, EnchantmentType.ARMOR_TORSO, 1.7f, 1.2f, "X X", "XXX", "XXX"), - LEGGINGS("leggings", "Beinschutz", "Hose", 15, 2, EnchantmentType.ARMOR_LEGS, 1.6f, 1.1f, "XXX", "X X", "X X"), - BOOTS("boots", "Stiefel", "Stiefel", 13, 3, EnchantmentType.ARMOR_FEET, 1.4f, 1.0f, "X X", "X X"), + HELMET("helmet", "Helm", "Kappe", 11, 0, EnchantmentType.ARMOR_HEAD, 1.0f, 1.0f, 5, 0), + CHESTPLATE("chestplate", "Brustpanzer", "Jacke", 16, 1, EnchantmentType.ARMOR_TORSO, 1.7f, 1.2f, 8, 0), + LEGGINGS("leggings", "Beinschutz", "Hose", 15, 2, EnchantmentType.ARMOR_LEGS, 1.6f, 1.1f, 7, 0), + BOOTS("boots", "Stiefel", "Stiefel", 13, 3, EnchantmentType.ARMOR_FEET, 1.4f, 1.0f, 4, 0), CROWN("crown", "Krone", 0, 4, null, 0.3f, 1.0f), RING_LEFT_A("ring_left_a", "Linker Ring 1", 0, 5, EnchantmentType.RING, 1.0f), @@ -28,7 +28,7 @@ public enum Equipment implements Identifyable, Displayable { RING_RIGHT_B("ring_right_b", "Rechter Ring 2", 0, 10, EnchantmentType.RING, 1.0f), BELT("belt", "Gürtel", 0, 11, null, 1.0f), - HORSE_ARMOR("horse_armor", "Pferderüstung", EntityHorse.class, "X X", "XXX", "XXX"); + HORSE_ARMOR("horse_armor", "Pferderüstung", EntityHorse.class, 8, 0); public static final int ARMOR_SLOTS; public static final Equipment[] ARMOR; @@ -36,7 +36,8 @@ public enum Equipment implements Identifyable, Displayable { private final String name; private final String display; private final String altDisplay; - private final String[] recipe; + private final int recipeItems; + private final int recipeSticks; private final ItemType type; private final int damage; private final int index; @@ -59,13 +60,14 @@ public enum Equipment implements Identifyable, Displayable { } } - private Equipment(String name, String display, String alt, ItemType type, int dmg, int index, EnchantmentType ench, float phy, float mag, Class clazz, String... recipe) { + private Equipment(String name, String display, String alt, ItemType type, int dmg, int index, EnchantmentType ench, float phy, float mag, Class clazz, int items, int sticks) { this.name = name; this.display = display; this.altDisplay = alt; this.type = type; this.damage = dmg; - this.recipe = recipe; + this.recipeItems = items; + this.recipeSticks = sticks; this.index = index; this.phyResist = phy; this.magicResist = mag; @@ -73,28 +75,28 @@ public enum Equipment implements Identifyable, Displayable { this.animalType = clazz; } - private Equipment(String name, String display, ItemType type, int damage, String... recipe) { - this(name, display, null, type, damage, -1, null, 0.0f, 0.0f, null, recipe); + private Equipment(String name, String display, ItemType type, int damage, int items, int sticks) { + this(name, display, null, type, damage, -1, null, 0.0f, 0.0f, null, items, sticks); } - private Equipment(String name, String display, ItemType type, String... recipe) { - this(name, display, type, -1, recipe); + private Equipment(String name, String display, ItemType type, int items, int sticks) { + this(name, display, type, -1, items, sticks); } - private Equipment(String name, String display, Class clazz, String... recipe) { - this(name, display, null, ItemType.ANIMAL_ARMOR, -1, -1, null, 0.0f, 0.0f, clazz, recipe); + private Equipment(String name, String display, Class clazz, int items, int sticks) { + this(name, display, null, ItemType.ANIMAL_ARMOR, -1, -1, null, 0.0f, 0.0f, clazz, items, sticks); } - private Equipment(String name, String display, String altDisplay, int damage, int index, EnchantmentType ench, float phy, float mag, String... recipe) { - this(name, display, altDisplay, ItemType.MAIN_ARMOR, damage, index, ench, phy, mag, null, recipe); + private Equipment(String name, String display, String altDisplay, int damage, int index, EnchantmentType ench, float phy, float mag, int items, int sticks) { + this(name, display, altDisplay, ItemType.MAIN_ARMOR, damage, index, ench, phy, mag, null, items, sticks); } private Equipment(String name, String display, int damage, int index, EnchantmentType ench, float mag) { - this(name, display, null, ItemType.ACCESSORY, damage, index, ench, 0.0f, mag, null); + this(name, display, null, ItemType.ACCESSORY, damage, index, ench, 0.0f, mag, null, 0, 0); } private Equipment(String name, String display, int damage, int index, EnchantmentType ench, float phy, float mag) { - this(name, display, null, ItemType.RENDERED_ACCESSORY, damage, index, ench, phy, mag, null); + this(name, display, null, ItemType.RENDERED_ACCESSORY, damage, index, ench, phy, mag, null, 0, 0); } public String toString() { @@ -162,8 +164,12 @@ public enum Equipment implements Identifyable, Displayable { return this.damage; } - public String[] getRecipe() { - return this.recipe; + public int getRecipeItems() { + return this.recipeItems; + } + + public int getRecipeSticks() { + return this.recipeSticks; } public int getIndex() { diff --git a/server/src/main/java/server/network/Player.java b/server/src/main/java/server/network/Player.java index 3e44b3cf..84e906b0 100755 --- a/server/src/main/java/server/network/Player.java +++ b/server/src/main/java/server/network/Player.java @@ -32,6 +32,7 @@ import common.entity.projectile.EntityArrow; import common.entity.types.EntityLiving; import common.init.BlockRegistry; import common.init.Blocks; +import common.init.CraftingRegistry; import common.init.EntityRegistry; import common.init.Items; import common.init.SoundEvent; @@ -41,10 +42,10 @@ import common.inventory.ContainerEnchantment; import common.inventory.ContainerEntityInventory; import common.inventory.ContainerMerchant; import common.inventory.ContainerTile; +import common.inventory.ContainerWorkbench; import common.inventory.IInventory; import common.inventory.InventoryBasic; import common.inventory.Slot; -import common.inventory.SlotCrafting; import common.item.Item; import common.item.ItemControl; import common.item.ItemStack; @@ -836,12 +837,9 @@ public class Player extends User implements Executor, IPlayer public void sendSlot(Container container, int index, ItemStack stack) { - if (!(container.getSlot(index) instanceof SlotCrafting)) + if (!this.isChangingQuantityOnly) { - if (!this.isChangingQuantityOnly) - { - this.sendPacket(new SPacketSetSlot(container.windowId, index, stack)); - } + this.sendPacket(new SPacketSetSlot(container.windowId, index, stack)); } } @@ -1948,7 +1946,7 @@ public class Player extends User implements Executor, IPlayer if(msg.length() > 30) throw new IllegalArgumentException("Ungültiger Name"); if(packetIn.getArg() == -1) - this.entity.inventoryContainer.renameItem(5 + Equipment.ARMOR_SLOTS + this.entity.getSelectedIndex(), msg); + this.entity.inventoryContainer.renameItem(Equipment.ARMOR_SLOTS + this.entity.getSelectedIndex(), msg); else this.entity.openContainer.renameItem(packetIn.getArg(), msg); this.entity.openContainer.detectAndSendChanges(); @@ -2803,7 +2801,7 @@ public class Player extends User implements Executor, IPlayer this.profiling = false; break; - case CRAFT_ITEM: { + case CRAFT_SINGLE: { if(this.entity.getMouseItem() == null) { Slot slot = this.entity.openContainer.getSlot(packetIn.getAuxData()); if(slot != null && slot.canCheatItem() && slot.getHasStack()) { @@ -2818,6 +2816,13 @@ public class Player extends User implements Executor, IPlayer } break; } + + case CRAFT_ITEM: { + int tier = this.entity.openContainer == this.entity.inventoryContainer ? 0 : (this.entity.openContainer instanceof ContainerWorkbench bench ? bench.getTier() : -1); + if(tier >= 0) + CraftingRegistry.doCrafting(this.entity, tier, packetIn.getAuxData()); + break; + } default: throw new IllegalArgumentException("Ungültige Aktion!"); @@ -2889,7 +2894,7 @@ public class Player extends User implements Executor, IPlayer Item item = packet.getItem(); if(item == null) return; - ItemStack stack = new ItemStack(item, packet.isStacked() ? item.getMaxAmount() : 1); + ItemStack stack = new ItemStack(item, packet.isStacked() ? Math.min(item.getMaxAmount(), 100) : 1); int amount = stack.getSize(); if(amount <= 0) return; @@ -2903,7 +2908,7 @@ public class Player extends User implements Executor, IPlayer this.entity.dropItem(stack, false, true); } else { - Slot slot = packet.getSlot() < 0 ? this.entity.inventoryContainer.getSlot(5 + Equipment.ARMOR_SLOTS + -2 - packet.getSlot()) : this.entity.openContainer.getSlot(packet.getSlot()); + Slot slot = packet.getSlot() < 0 ? this.entity.inventoryContainer.getSlot(Equipment.ARMOR_SLOTS + -2 - packet.getSlot()) : this.entity.openContainer.getSlot(packet.getSlot()); if(slot == null || !slot.canCheatItem()) return; stack.setSize(Math.min(slot.getItemStackLimit(stack), stack.getSize()));