[Bleeding] Implementation of inventory framework. Addresses BUKKIT-856
See the corresponding Bukkit commit for details. Implementation details: - Any packets that include an itemstack will send air stacks as null; maybe this will even eliminate the client crash that occurs if the client receives an air stack - Better handling of null itemstacks in general (ie less converting them to air stacks) - Inventory.setContents() can now take an array smaller than the inventory without error - Player.updateInventory() should now correctly update the result slot in a crafting inventory Some small credit goes to Afforess (initial implementation of openInventory() methods) and Drakia (initial implementation of InventoryOpenEvent and InventoryCloseEvent).
This commit is contained in:
committed by
EvilSeph
parent
10e593649c
commit
0842bab48b
@@ -4,11 +4,19 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
// CraftBukkit start
|
||||
import org.bukkit.craftbukkit.event.CraftEventFactory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
// CraftBukkit end
|
||||
|
||||
public class CraftingManager {
|
||||
|
||||
private static final CraftingManager a = new CraftingManager();
|
||||
public List b = new ArrayList(); // CraftBukkit - private -> public
|
||||
// CraftBukkit start
|
||||
public CraftingRecipe lastRecipe;
|
||||
public InventoryView lastCraftView;
|
||||
// CraftBukkit end
|
||||
|
||||
public static final CraftingManager getInstance() {
|
||||
return a;
|
||||
@@ -218,13 +226,27 @@ public class CraftingManager {
|
||||
j1 = 0;
|
||||
}
|
||||
|
||||
return new ItemStack(itemstack.id, 1, j1);
|
||||
// CraftBukkit start - construct a dummy repair recipe
|
||||
ItemStack result = new ItemStack(itemstack.id, 1, j1);
|
||||
List<ItemStack> ingredients = new ArrayList<ItemStack>();
|
||||
ingredients.add(itemstack.cloneItemStack());
|
||||
ingredients.add(itemstack1.cloneItemStack());
|
||||
ShapelessRecipes recipe = new ShapelessRecipes(result.cloneItemStack(), ingredients);
|
||||
inventorycrafting.currentRecipe = recipe;
|
||||
result = CraftEventFactory.callPreCraftEvent(inventorycrafting, result, lastCraftView, true);
|
||||
return result;
|
||||
// CraftBukkit end
|
||||
} else {
|
||||
for (j = 0; j < this.b.size(); ++j) {
|
||||
CraftingRecipe craftingrecipe = (CraftingRecipe) this.b.get(j);
|
||||
|
||||
if (craftingrecipe.a(inventorycrafting)) {
|
||||
return craftingrecipe.b(inventorycrafting);
|
||||
// CraftBukkit start - INVENTORY_PRE_CRAFT event
|
||||
inventorycrafting.currentRecipe = craftingrecipe;
|
||||
ItemStack result = craftingrecipe.b(inventorycrafting);
|
||||
result = CraftEventFactory.callPreCraftEvent(inventorycrafting, result, lastCraftView, false);
|
||||
return result;
|
||||
// CraftBukkit end
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user