mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-24 19:46:21 +01:00
Implemented addRecipe method in CraftServer and associated recipe classes.
This commit is contained in:
parent
017b15c3a6
commit
5a5ce79035
77
src/main/java/net/minecraft/server/ContainerPlayer.java
Normal file
77
src/main/java/net/minecraft/server/ContainerPlayer.java
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package net.minecraft.server;
|
||||||
|
|
||||||
|
// CraftBukkit
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ContainerPlayer extends Container {
|
||||||
|
|
||||||
|
public InventoryCrafting a;
|
||||||
|
public IInventory b;
|
||||||
|
public boolean c;
|
||||||
|
|
||||||
|
public ContainerPlayer(InventoryPlayer inventoryplayer) {
|
||||||
|
this(inventoryplayer, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ContainerPlayer(InventoryPlayer inventoryplayer, boolean flag) {
|
||||||
|
this.a = new InventoryCrafting(this, 2, 2);
|
||||||
|
this.b = new InventoryCraftResult();
|
||||||
|
this.c = false;
|
||||||
|
this.c = flag;
|
||||||
|
this.a((Slot) (new SlotResult(inventoryplayer.d, this.a, this.b, 0, 144, 36)));
|
||||||
|
|
||||||
|
int i;
|
||||||
|
int j;
|
||||||
|
|
||||||
|
for (i = 0; i < 2; ++i) {
|
||||||
|
for (j = 0; j < 2; ++j) {
|
||||||
|
this.a(new Slot(this.a, j + i * 2, 88 + j * 18, 26 + i * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 4; ++i) {
|
||||||
|
this.a((Slot) (new SlotArmor(this, inventoryplayer, inventoryplayer.getSize() - 1 - i, 8, 8 + i * 18, i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 3; ++i) {
|
||||||
|
for (j = 0; j < 9; ++j) {
|
||||||
|
this.a(new Slot(inventoryplayer, j + (i + 1) * 9, 8 + j * 18, 84 + i * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 9; ++i) {
|
||||||
|
this.a(new Slot(inventoryplayer, i, 8 + i * 18, 142));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.a((IInventory) this.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void a(IInventory iinventory) {
|
||||||
|
// CraftBukkit start
|
||||||
|
ItemStack craftResult = CraftingManager.a().a(this.a);
|
||||||
|
this.b.setItem(0, craftResult);
|
||||||
|
if (super.g.size() < 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EntityPlayer player = (EntityPlayer) super.g.get(0); // TODO: Is this _always_ correct? Seems like it.
|
||||||
|
player.netServerHandler.sendPacket((Packet) (new Packet103SetSlot(player.activeContainer.f, 0, craftResult)));
|
||||||
|
// CraftBukkit end
|
||||||
|
}
|
||||||
|
|
||||||
|
public void a(EntityHuman entityhuman) {
|
||||||
|
super.a(entityhuman);
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
ItemStack itemstack = this.a.getItem(i);
|
||||||
|
|
||||||
|
if (itemstack != null) {
|
||||||
|
entityhuman.b(itemstack);
|
||||||
|
this.a.setItem(i, (ItemStack) null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean b(EntityHuman entityhuman) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
71
src/main/java/net/minecraft/server/ContainerWorkbench.java
Normal file
71
src/main/java/net/minecraft/server/ContainerWorkbench.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package net.minecraft.server;
|
||||||
|
|
||||||
|
// CraftBukkit
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ContainerWorkbench extends Container {
|
||||||
|
|
||||||
|
public InventoryCrafting a = new InventoryCrafting(this, 3, 3);
|
||||||
|
public IInventory b = new InventoryCraftResult();
|
||||||
|
private World c;
|
||||||
|
private int h;
|
||||||
|
private int i;
|
||||||
|
private int j;
|
||||||
|
|
||||||
|
public ContainerWorkbench(InventoryPlayer inventoryplayer, World world, int i, int j, int k) {
|
||||||
|
this.c = world;
|
||||||
|
this.h = i;
|
||||||
|
this.i = j;
|
||||||
|
this.j = k;
|
||||||
|
this.a((Slot) (new SlotResult(inventoryplayer.d, this.a, this.b, 0, 124, 35)));
|
||||||
|
|
||||||
|
int l;
|
||||||
|
int i1;
|
||||||
|
|
||||||
|
for (l = 0; l < 3; ++l) {
|
||||||
|
for (i1 = 0; i1 < 3; ++i1) {
|
||||||
|
this.a(new Slot(this.a, i1 + l * 3, 30 + i1 * 18, 17 + l * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (l = 0; l < 3; ++l) {
|
||||||
|
for (i1 = 0; i1 < 9; ++i1) {
|
||||||
|
this.a(new Slot(inventoryplayer, i1 + l * 9 + 9, 8 + i1 * 18, 84 + l * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (l = 0; l < 9; ++l) {
|
||||||
|
this.a(new Slot(inventoryplayer, l, 8 + l * 18, 142));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.a((IInventory) this.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void a(IInventory iinventory) {
|
||||||
|
// CraftBukkit start
|
||||||
|
ItemStack craftResult = CraftingManager.a().a(this.a);
|
||||||
|
this.b.setItem(0, craftResult);
|
||||||
|
if (super.g.size() < 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EntityPlayer player = (EntityPlayer) super.g.get(0); // TODO: Is this _always_ correct? Seems like it.
|
||||||
|
player.netServerHandler.sendPacket((Packet) (new Packet103SetSlot(player.activeContainer.f, 0, craftResult)));
|
||||||
|
// CraftBukkit end
|
||||||
|
}
|
||||||
|
|
||||||
|
public void a(EntityHuman entityhuman) {
|
||||||
|
super.a(entityhuman);
|
||||||
|
|
||||||
|
for (int i = 0; i < 9; ++i) {
|
||||||
|
ItemStack itemstack = this.a.getItem(i);
|
||||||
|
|
||||||
|
if (itemstack != null) {
|
||||||
|
entityhuman.b(itemstack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean b(EntityHuman entityhuman) {
|
||||||
|
return this.c.getTypeId(this.h, this.i, this.j) != Block.WORKBENCH.id ? false : entityhuman.d((double) this.h + 0.5D, (double) this.i + 0.5D, (double) this.j + 0.5D) <= 64.0D;
|
||||||
|
}
|
||||||
|
}
|
179
src/main/java/net/minecraft/server/CraftingManager.java
Normal file
179
src/main/java/net/minecraft/server/CraftingManager.java
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
package net.minecraft.server;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CraftingManager {
|
||||||
|
|
||||||
|
private static final CraftingManager a = new CraftingManager();
|
||||||
|
private List b = new ArrayList();
|
||||||
|
|
||||||
|
public static final CraftingManager a() {
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
private CraftingManager() {
|
||||||
|
(new RecipesTools()).a(this);
|
||||||
|
(new RecipesWeapons()).a(this);
|
||||||
|
(new RecipeIngots()).a(this);
|
||||||
|
(new RecipesFood()).a(this);
|
||||||
|
(new RecipesCrafting()).a(this);
|
||||||
|
(new RecipesArmor()).a(this);
|
||||||
|
(new RecipesDyes()).a(this);
|
||||||
|
this.a(new ItemStack(Item.PAPER, 3), new Object[] { "###", Character.valueOf('#'), Item.SUGAR_CANE});
|
||||||
|
this.a(new ItemStack(Item.BOOK, 1), new Object[] { "#", "#", "#", Character.valueOf('#'), Item.PAPER});
|
||||||
|
this.a(new ItemStack(Block.FENCE, 2), new Object[] { "###", "###", Character.valueOf('#'), Item.STICK});
|
||||||
|
this.a(new ItemStack(Block.JUKEBOX, 1), new Object[] { "###", "#X#", "###", Character.valueOf('#'), Block.WOOD, Character.valueOf('X'), Item.DIAMOND});
|
||||||
|
this.a(new ItemStack(Block.NOTE_BLOCK, 1), new Object[] { "###", "#X#", "###", Character.valueOf('#'), Block.WOOD, Character.valueOf('X'), Item.REDSTONE});
|
||||||
|
this.a(new ItemStack(Block.BOOKSHELF, 1), new Object[] { "###", "XXX", "###", Character.valueOf('#'), Block.WOOD, Character.valueOf('X'), Item.BOOK});
|
||||||
|
this.a(new ItemStack(Block.SNOW_BLOCK, 1), new Object[] { "##", "##", Character.valueOf('#'), Item.SNOW_BALL});
|
||||||
|
this.a(new ItemStack(Block.CLAY, 1), new Object[] { "##", "##", Character.valueOf('#'), Item.CLAY_BALL});
|
||||||
|
this.a(new ItemStack(Block.BRICK, 1), new Object[] { "##", "##", Character.valueOf('#'), Item.CLAY_BRICK});
|
||||||
|
this.a(new ItemStack(Block.GLOWSTONE, 1), new Object[] { "###", "###", "###", Character.valueOf('#'), Item.GLOWSTONE_DUST});
|
||||||
|
this.a(new ItemStack(Block.WOOL, 1), new Object[] { "###", "###", "###", Character.valueOf('#'), Item.STRING});
|
||||||
|
this.a(new ItemStack(Block.TNT, 1), new Object[] { "X#X", "#X#", "X#X", Character.valueOf('X'), Item.SULPHUR, Character.valueOf('#'), Block.SAND});
|
||||||
|
this.a(new ItemStack(Block.STEP, 3, 3), new Object[] { "###", Character.valueOf('#'), Block.COBBLESTONE});
|
||||||
|
this.a(new ItemStack(Block.STEP, 3, 0), new Object[] { "###", Character.valueOf('#'), Block.STONE});
|
||||||
|
this.a(new ItemStack(Block.STEP, 3, 1), new Object[] { "###", Character.valueOf('#'), Block.SANDSTONE});
|
||||||
|
this.a(new ItemStack(Block.STEP, 3, 2), new Object[] { "###", Character.valueOf('#'), Block.WOOD});
|
||||||
|
this.a(new ItemStack(Block.LADDER, 2), new Object[] { "# #", "###", "# #", Character.valueOf('#'), Item.STICK});
|
||||||
|
this.a(new ItemStack(Item.WOOD_DOOR, 1), new Object[] { "##", "##", "##", Character.valueOf('#'), Block.WOOD});
|
||||||
|
this.a(new ItemStack(Item.IRON_DOOR, 1), new Object[] { "##", "##", "##", Character.valueOf('#'), Item.IRON_INGOT});
|
||||||
|
this.a(new ItemStack(Item.SIGN, 1), new Object[] { "###", "###", " X ", Character.valueOf('#'), Block.WOOD, Character.valueOf('X'), Item.STICK});
|
||||||
|
this.a(new ItemStack(Item.CAKE, 1), new Object[] { "AAA", "BEB", "CCC", Character.valueOf('A'), Item.MILK_BUCKET, Character.valueOf('B'), Item.SUGAR, Character.valueOf('C'), Item.WHEAT, Character.valueOf('E'), Item.EGG});
|
||||||
|
this.a(new ItemStack(Item.SUGAR, 1), new Object[] { "#", Character.valueOf('#'), Item.SUGAR_CANE});
|
||||||
|
this.a(new ItemStack(Block.WOOD, 4), new Object[] { "#", Character.valueOf('#'), Block.LOG});
|
||||||
|
this.a(new ItemStack(Item.STICK, 4), new Object[] { "#", "#", Character.valueOf('#'), Block.WOOD});
|
||||||
|
this.a(new ItemStack(Block.TORCH, 4), new Object[] { "X", "#", Character.valueOf('X'), Item.COAL, Character.valueOf('#'), Item.STICK});
|
||||||
|
this.a(new ItemStack(Block.TORCH, 4), new Object[] { "X", "#", Character.valueOf('X'), new ItemStack(Item.COAL, 1, 1), Character.valueOf('#'), Item.STICK});
|
||||||
|
this.a(new ItemStack(Item.BOWL, 4), new Object[] { "# #", " # ", Character.valueOf('#'), Block.WOOD});
|
||||||
|
this.a(new ItemStack(Block.RAILS, 16), new Object[] { "X X", "X#X", "X X", Character.valueOf('X'), Item.IRON_INGOT, Character.valueOf('#'), Item.STICK});
|
||||||
|
this.a(new ItemStack(Block.GOLDEN_RAIL, 6), new Object[] { "X X", "X#X", "XRX", Character.valueOf('X'), Item.GOLD_INGOT, Character.valueOf('R'), Item.REDSTONE, Character.valueOf('#'), Item.STICK});
|
||||||
|
this.a(new ItemStack(Block.DETECTOR_RAIL, 6), new Object[] { "X X", "X#X", "XRX", Character.valueOf('X'), Item.IRON_INGOT, Character.valueOf('R'), Item.REDSTONE, Character.valueOf('#'), Block.STONE_PLATE});
|
||||||
|
this.a(new ItemStack(Item.MINECART, 1), new Object[] { "# #", "###", Character.valueOf('#'), Item.IRON_INGOT});
|
||||||
|
this.a(new ItemStack(Block.JACK_O_LANTERN, 1), new Object[] { "A", "B", Character.valueOf('A'), Block.PUMPKIN, Character.valueOf('B'), Block.TORCH});
|
||||||
|
this.a(new ItemStack(Item.STORAGE_MINECART, 1), new Object[] { "A", "B", Character.valueOf('A'), Block.CHEST, Character.valueOf('B'), Item.MINECART});
|
||||||
|
this.a(new ItemStack(Item.POWERED_MINECART, 1), new Object[] { "A", "B", Character.valueOf('A'), Block.FURNACE, Character.valueOf('B'), Item.MINECART});
|
||||||
|
this.a(new ItemStack(Item.BOAT, 1), new Object[] { "# #", "###", Character.valueOf('#'), Block.WOOD});
|
||||||
|
this.a(new ItemStack(Item.BUCKET, 1), new Object[] { "# #", " # ", Character.valueOf('#'), Item.IRON_INGOT});
|
||||||
|
this.a(new ItemStack(Item.FLINT_AND_STEEL, 1), new Object[] { "A ", " B", Character.valueOf('A'), Item.IRON_INGOT, Character.valueOf('B'), Item.FLINT});
|
||||||
|
this.a(new ItemStack(Item.BREAD, 1), new Object[] { "###", Character.valueOf('#'), Item.WHEAT});
|
||||||
|
this.a(new ItemStack(Block.WOOD_STAIRS, 4), new Object[] { "# ", "## ", "###", Character.valueOf('#'), Block.WOOD});
|
||||||
|
this.a(new ItemStack(Item.FISHING_ROD, 1), new Object[] { " #", " #X", "# X", Character.valueOf('#'), Item.STICK, Character.valueOf('X'), Item.STRING});
|
||||||
|
this.a(new ItemStack(Block.COBBLESTONE_STAIRS, 4), new Object[] { "# ", "## ", "###", Character.valueOf('#'), Block.COBBLESTONE});
|
||||||
|
this.a(new ItemStack(Item.PAINTING, 1), new Object[] { "###", "#X#", "###", Character.valueOf('#'), Item.STICK, Character.valueOf('X'), Block.WOOL});
|
||||||
|
this.a(new ItemStack(Item.GOLDEN_APPLE, 1), new Object[] { "###", "#X#", "###", Character.valueOf('#'), Block.GOLD_BLOCK, Character.valueOf('X'), Item.APPLE});
|
||||||
|
this.a(new ItemStack(Block.LEVER, 1), new Object[] { "X", "#", Character.valueOf('#'), Block.COBBLESTONE, Character.valueOf('X'), Item.STICK});
|
||||||
|
this.a(new ItemStack(Block.REDSTONE_TORCH_ON, 1), new Object[] { "X", "#", Character.valueOf('#'), Item.STICK, Character.valueOf('X'), Item.REDSTONE});
|
||||||
|
this.a(new ItemStack(Item.DIODE, 1), new Object[] { "#X#", "III", Character.valueOf('#'), Block.REDSTONE_TORCH_ON, Character.valueOf('X'), Item.REDSTONE, Character.valueOf('I'), Block.STONE});
|
||||||
|
this.a(new ItemStack(Item.WATCH, 1), new Object[] { " # ", "#X#", " # ", Character.valueOf('#'), Item.GOLD_INGOT, Character.valueOf('X'), Item.REDSTONE});
|
||||||
|
this.a(new ItemStack(Item.COMPASS, 1), new Object[] { " # ", "#X#", " # ", Character.valueOf('#'), Item.IRON_INGOT, Character.valueOf('X'), Item.REDSTONE});
|
||||||
|
this.a(new ItemStack(Block.STONE_BUTTON, 1), new Object[] { "#", "#", Character.valueOf('#'), Block.STONE});
|
||||||
|
this.a(new ItemStack(Block.STONE_PLATE, 1), new Object[] { "##", Character.valueOf('#'), Block.STONE});
|
||||||
|
this.a(new ItemStack(Block.WOOD_PLATE, 1), new Object[] { "##", Character.valueOf('#'), Block.WOOD});
|
||||||
|
this.a(new ItemStack(Block.DISPENSER, 1), new Object[] { "###", "#X#", "#R#", Character.valueOf('#'), Block.COBBLESTONE, Character.valueOf('X'), Item.BOW, Character.valueOf('R'), Item.REDSTONE});
|
||||||
|
this.a(new ItemStack(Item.BED, 1), new Object[] { "###", "XXX", Character.valueOf('#'), Block.WOOL, Character.valueOf('X'), Block.WOOD});
|
||||||
|
Collections.sort(this.b, new RecipeSorter(this));
|
||||||
|
System.out.println(this.b.size() + " recipes");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void a(ItemStack itemstack, Object[] aobject) { // CraftBukkit - default -> public and Object... -> Object[]
|
||||||
|
String s = "";
|
||||||
|
int i = 0;
|
||||||
|
int j = 0;
|
||||||
|
int k = 0;
|
||||||
|
|
||||||
|
if (aobject[i] instanceof String[]) {
|
||||||
|
String[] astring = (String[]) ((String[]) aobject[i++]);
|
||||||
|
|
||||||
|
for (int l = 0; l < astring.length; ++l) {
|
||||||
|
String s1 = astring[l];
|
||||||
|
|
||||||
|
++k;
|
||||||
|
j = s1.length();
|
||||||
|
s = s + s1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while (aobject[i] instanceof String) {
|
||||||
|
String s2 = (String) aobject[i++];
|
||||||
|
|
||||||
|
++k;
|
||||||
|
j = s2.length();
|
||||||
|
s = s + s2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap hashmap;
|
||||||
|
|
||||||
|
for (hashmap = new HashMap(); i < aobject.length; i += 2) {
|
||||||
|
Character character = (Character) aobject[i];
|
||||||
|
ItemStack itemstack1 = null;
|
||||||
|
|
||||||
|
if (aobject[i + 1] instanceof Item) {
|
||||||
|
itemstack1 = new ItemStack((Item) aobject[i + 1]);
|
||||||
|
} else if (aobject[i + 1] instanceof Block) {
|
||||||
|
itemstack1 = new ItemStack((Block) aobject[i + 1], 1, -1);
|
||||||
|
} else if (aobject[i + 1] instanceof ItemStack) {
|
||||||
|
itemstack1 = (ItemStack) aobject[i + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
hashmap.put(character, itemstack1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack[] aitemstack = new ItemStack[j * k];
|
||||||
|
|
||||||
|
for (int i1 = 0; i1 < j * k; ++i1) {
|
||||||
|
char c0 = s.charAt(i1);
|
||||||
|
|
||||||
|
if (hashmap.containsKey(Character.valueOf(c0))) {
|
||||||
|
aitemstack[i1] = ((ItemStack) hashmap.get(Character.valueOf(c0))).j();
|
||||||
|
} else {
|
||||||
|
aitemstack[i1] = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.b.add(new ShapedRecipes(j, k, aitemstack, itemstack));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void b(ItemStack itemstack, Object[] aobject) { // CraftBukkit - default -> public and Object... -> Object[]
|
||||||
|
ArrayList arraylist = new ArrayList();
|
||||||
|
Object[] aobject1 = aobject;
|
||||||
|
int i = aobject.length;
|
||||||
|
|
||||||
|
for (int j = 0; j < i; ++j) {
|
||||||
|
Object object = aobject1[j];
|
||||||
|
|
||||||
|
if (object instanceof ItemStack) {
|
||||||
|
arraylist.add(((ItemStack) object).j());
|
||||||
|
} else if (object instanceof Item) {
|
||||||
|
arraylist.add(new ItemStack((Item) object));
|
||||||
|
} else {
|
||||||
|
if (!(object instanceof Block)) {
|
||||||
|
throw new RuntimeException("Invalid shapeless recipy!");
|
||||||
|
}
|
||||||
|
|
||||||
|
arraylist.add(new ItemStack((Block) object));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.b.add(new ShapelessRecipes(itemstack, arraylist));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack a(InventoryCrafting inventorycrafting) {
|
||||||
|
for (int i = 0; i < this.b.size(); ++i) {
|
||||||
|
CraftingRecipe craftingrecipe = (CraftingRecipe) this.b.get(i);
|
||||||
|
|
||||||
|
if (craftingrecipe.a(inventorycrafting)) {
|
||||||
|
return craftingrecipe.b(inventorycrafting);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List b() {
|
||||||
|
return this.b;
|
||||||
|
}
|
||||||
|
}
|
@ -823,8 +823,13 @@ public class NetServerHandler extends NetHandler implements ICommandListener {
|
|||||||
public void a(Packet102WindowClick packet102windowclick) {
|
public void a(Packet102WindowClick packet102windowclick) {
|
||||||
if (this.player.activeContainer.f == packet102windowclick.a && this.player.activeContainer.c(this.player)) {
|
if (this.player.activeContainer.f == packet102windowclick.a && this.player.activeContainer.c(this.player)) {
|
||||||
ItemStack itemstack = this.player.activeContainer.a(packet102windowclick.b, packet102windowclick.c, packet102windowclick.f, this.player);
|
ItemStack itemstack = this.player.activeContainer.a(packet102windowclick.b, packet102windowclick.c, packet102windowclick.f, this.player);
|
||||||
|
// CraftBukkit start
|
||||||
if (ItemStack.equals(packet102windowclick.e, itemstack)) {
|
boolean clickSuccessful = ItemStack.equals(packet102windowclick.e, itemstack);
|
||||||
|
if ((this.player.activeContainer instanceof ContainerWorkbench || this.player.activeContainer instanceof ContainerPlayer) && packet102windowclick.b == 0) {
|
||||||
|
clickSuccessful = false;
|
||||||
|
}
|
||||||
|
// CraftBukkit end
|
||||||
|
if (clickSuccessful) { // CraftBukkit - extracted to local variable
|
||||||
this.player.netServerHandler.sendPacket(new Packet106Transaction(packet102windowclick.a, packet102windowclick.d, true));
|
this.player.netServerHandler.sendPacket(new Packet106Transaction(packet102windowclick.a, packet102windowclick.d, true));
|
||||||
this.player.h = true;
|
this.player.h = true;
|
||||||
this.player.activeContainer.a();
|
this.player.activeContainer.a();
|
||||||
|
@ -152,7 +152,8 @@ public class TileEntityFurnace extends TileEntity implements IInventory {
|
|||||||
} else {
|
} else {
|
||||||
ItemStack itemstack = FurnaceRecipes.a().a(this.items[0].getItem().id);
|
ItemStack itemstack = FurnaceRecipes.a().a(this.items[0].getItem().id);
|
||||||
|
|
||||||
return itemstack == null ? false : (this.items[2] == null ? true : (!this.items[2].a(itemstack) ? false : (this.items[2].count < this.getMaxStackSize() && this.items[2].count < this.items[2].b() ? true : this.items[2].count < itemstack.b())));
|
// CraftBukkit - consider resultant count instead of current count
|
||||||
|
return itemstack == null ? false : (this.items[2] == null ? true : (!this.items[2].a(itemstack) ? false : (this.items[2].count+itemstack.count <= this.getMaxStackSize() && this.items[2].count < this.items[2].b() ? true : this.items[2].count+itemstack.count <= itemstack.b())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,8 +163,8 @@ public class TileEntityFurnace extends TileEntity implements IInventory {
|
|||||||
|
|
||||||
if (this.items[2] == null) {
|
if (this.items[2] == null) {
|
||||||
this.items[2] = itemstack.j();
|
this.items[2] = itemstack.j();
|
||||||
} else if (this.items[2].id == itemstack.id) {
|
} else if (this.items[2].id == itemstack.id && this.items[2].damage == itemstack.damage) { // CraftBukkit - compare damage too
|
||||||
++this.items[2].count;
|
this.items[2].count += itemstack.count; // CraftBukkit - increment by count instead of 1
|
||||||
}
|
}
|
||||||
|
|
||||||
--this.items[0].count;
|
--this.items[0].count;
|
||||||
|
@ -8,6 +8,10 @@ import net.minecraft.server.IWorldAccess;
|
|||||||
import org.bukkit.command.*;
|
import org.bukkit.command.*;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.world.WorldLoadEvent;
|
import org.bukkit.event.world.WorldLoadEvent;
|
||||||
|
import org.bukkit.inventory.FurnaceRecipe;
|
||||||
|
import org.bukkit.inventory.Recipe;
|
||||||
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
|
import org.bukkit.inventory.ShapelessRecipe;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -37,6 +41,10 @@ import org.bukkit.plugin.PluginManager;
|
|||||||
import org.bukkit.plugin.SimplePluginManager;
|
import org.bukkit.plugin.SimplePluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||||
import org.bukkit.scheduler.BukkitScheduler;
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
import org.bukkit.craftbukkit.inventory.CraftFurnaceRecipe;
|
||||||
|
import org.bukkit.craftbukkit.inventory.CraftRecipe;
|
||||||
|
import org.bukkit.craftbukkit.inventory.CraftShapedRecipe;
|
||||||
|
import org.bukkit.craftbukkit.inventory.CraftShapelessRecipe;
|
||||||
import org.bukkit.craftbukkit.scheduler.CraftScheduler;
|
import org.bukkit.craftbukkit.scheduler.CraftScheduler;
|
||||||
import org.bukkit.util.config.Configuration;
|
import org.bukkit.util.config.Configuration;
|
||||||
|
|
||||||
@ -420,4 +428,24 @@ public final class CraftServer implements Server {
|
|||||||
return this.prefix;
|
return this.prefix;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addRecipe(Recipe recipe) {
|
||||||
|
CraftRecipe toAdd;
|
||||||
|
if(recipe instanceof CraftRecipe) {
|
||||||
|
toAdd = (CraftRecipe) recipe;
|
||||||
|
} else {
|
||||||
|
if (recipe instanceof ShapedRecipe) {
|
||||||
|
toAdd = CraftShapedRecipe.fromBukkitRecipe((ShapedRecipe) recipe);
|
||||||
|
} else if (recipe instanceof ShapelessRecipe) {
|
||||||
|
toAdd = CraftShapelessRecipe.fromBukkitRecipe((ShapelessRecipe) recipe);
|
||||||
|
} else if (recipe instanceof FurnaceRecipe) {
|
||||||
|
toAdd = CraftFurnaceRecipe.fromBukkitRecipe((FurnaceRecipe) recipe);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toAdd.addToCraftingManager();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
package org.bukkit.craftbukkit.inventory;
|
||||||
|
|
||||||
|
import net.minecraft.server.FurnaceRecipes;
|
||||||
|
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.inventory.FurnaceRecipe;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.material.MaterialData;
|
||||||
|
|
||||||
|
public class CraftFurnaceRecipe extends FurnaceRecipe implements CraftRecipe {
|
||||||
|
public CraftFurnaceRecipe(ItemStack result, Material source) {
|
||||||
|
super(result, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CraftFurnaceRecipe(ItemStack result, MaterialData source) {
|
||||||
|
super(result, source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CraftFurnaceRecipe fromBukkitRecipe(FurnaceRecipe recipe) {
|
||||||
|
if (recipe instanceof CraftFurnaceRecipe) {
|
||||||
|
return (CraftFurnaceRecipe) recipe;
|
||||||
|
}
|
||||||
|
return new CraftFurnaceRecipe(recipe.getResult(), recipe.getInput());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addToCraftingManager() {
|
||||||
|
ItemStack result = this.getResult();
|
||||||
|
MaterialData input = this.getInput();
|
||||||
|
int id = result.getTypeId();
|
||||||
|
int amount = result.getAmount();
|
||||||
|
int dmg = result.getDurability();
|
||||||
|
FurnaceRecipes.a().a(input.getItemTypeId(), new net.minecraft.server.ItemStack(id, amount, dmg));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package org.bukkit.craftbukkit.inventory;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.Recipe;
|
||||||
|
|
||||||
|
public interface CraftRecipe extends Recipe {
|
||||||
|
void addToCraftingManager();
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package org.bukkit.craftbukkit.inventory;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import net.minecraft.server.CraftingManager;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.ShapedRecipe;
|
||||||
|
import org.bukkit.material.MaterialData;
|
||||||
|
|
||||||
|
public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
|
||||||
|
public CraftShapedRecipe(ItemStack result) {
|
||||||
|
super(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CraftShapedRecipe fromBukkitRecipe(ShapedRecipe recipe) {
|
||||||
|
if (recipe instanceof CraftShapedRecipe) {
|
||||||
|
return (CraftShapedRecipe) recipe;
|
||||||
|
}
|
||||||
|
CraftShapedRecipe ret = new CraftShapedRecipe(recipe.getResult());
|
||||||
|
String[] shape = recipe.getShape();
|
||||||
|
ret.shape(shape);
|
||||||
|
for (char c : recipe.getIngredientMap().keySet()) {
|
||||||
|
ret.setIngredient(c, recipe.getIngredientMap().get(c));
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addToCraftingManager() {
|
||||||
|
Object[] data;
|
||||||
|
String[] shape = this.getShape();
|
||||||
|
HashMap<Character, MaterialData> ingred = this.getIngredientMap();
|
||||||
|
int datalen = shape.length;
|
||||||
|
datalen += ingred.size() * 2;
|
||||||
|
int i = 0;
|
||||||
|
data = new Object[datalen];
|
||||||
|
for (; i < shape.length; i++) {
|
||||||
|
data[i] = shape[i];
|
||||||
|
}
|
||||||
|
for (char c : ingred.keySet()) {
|
||||||
|
data[i] = c;
|
||||||
|
i++;
|
||||||
|
MaterialData mdata = ingred.get(c);
|
||||||
|
int id = mdata.getItemTypeId();
|
||||||
|
byte dmg = mdata.getData();
|
||||||
|
data[i] = new net.minecraft.server.ItemStack(id, 1, dmg);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
int id = this.getResult().getTypeId();
|
||||||
|
int amount = this.getResult().getAmount();
|
||||||
|
short durability = this.getResult().getDurability();
|
||||||
|
CraftingManager.a().a(new net.minecraft.server.ItemStack(id, amount, durability), data);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package org.bukkit.craftbukkit.inventory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import net.minecraft.server.CraftingManager;
|
||||||
|
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.ShapelessRecipe;
|
||||||
|
import org.bukkit.material.MaterialData;
|
||||||
|
|
||||||
|
public class CraftShapelessRecipe extends ShapelessRecipe implements CraftRecipe {
|
||||||
|
public CraftShapelessRecipe(ItemStack result) {
|
||||||
|
super(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CraftShapelessRecipe fromBukkitRecipe(ShapelessRecipe recipe) {
|
||||||
|
if (recipe instanceof CraftShapelessRecipe) {
|
||||||
|
return (CraftShapelessRecipe) recipe;
|
||||||
|
}
|
||||||
|
CraftShapelessRecipe ret = new CraftShapelessRecipe(recipe.getResult());
|
||||||
|
for (MaterialData ingred : recipe.getIngredientList()) {
|
||||||
|
ret.addIngredient(ingred);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addToCraftingManager() {
|
||||||
|
ArrayList<MaterialData> ingred = this.getIngredientList();
|
||||||
|
Object[] data = new Object[ingred.size()];
|
||||||
|
int i = 0;
|
||||||
|
for (MaterialData mdata : ingred) {
|
||||||
|
int id = mdata.getItemTypeId();
|
||||||
|
byte dmg = mdata.getData();
|
||||||
|
data[i] = new net.minecraft.server.ItemStack(id, 1, dmg);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
int id = this.getResult().getTypeId();
|
||||||
|
int amount = this.getResult().getAmount();
|
||||||
|
short durability = this.getResult().getDurability();
|
||||||
|
CraftingManager.a().b(new net.minecraft.server.ItemStack(id, amount, durability), data);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user