mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2024-11-25 12:06:09 +01:00
Bug fixes
This commit is contained in:
parent
d7e07c042b
commit
f9d60de527
@ -1,6 +1,7 @@
|
||||
package com.jamesdpeters.minecraft.chests;
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
@ -8,7 +9,7 @@ import java.util.List;
|
||||
|
||||
public interface CraftingProvider {
|
||||
|
||||
CraftingResult craft(World world, List<ItemStack> items);
|
||||
CraftingResult craft(Player player, World world, List<ItemStack> items);
|
||||
|
||||
Recipe getRecipe(World world, List<ItemStack> items);
|
||||
Recipe getRecipe(Player player, World world, List<ItemStack> items);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
@ -25,7 +26,7 @@ import java.util.stream.Collectors;
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(World world, List<ItemStack> items) {
|
||||
public CraftingResult craft(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
@ -70,7 +71,7 @@ public class Crafting implements CraftingProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(World world, List<ItemStack> items) {
|
||||
public Recipe getRecipe(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
@ -25,7 +26,7 @@ import java.util.stream.Collectors;
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(World world, List<ItemStack> items) {
|
||||
public CraftingResult craft(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
@ -70,7 +71,7 @@ public class Crafting implements CraftingProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(World world, List<ItemStack> items) {
|
||||
public Recipe getRecipe(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
@ -25,7 +26,7 @@ import java.util.stream.Collectors;
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(World world, List<ItemStack> items) {
|
||||
public CraftingResult craft(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
@ -70,7 +71,7 @@ public class Crafting implements CraftingProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(World world, List<ItemStack> items) {
|
||||
public Recipe getRecipe(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
@ -25,7 +26,7 @@ import java.util.stream.Collectors;
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(World world, List<ItemStack> items) {
|
||||
public CraftingResult craft(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
@ -70,7 +71,7 @@ public class Crafting implements CraftingProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(World world, List<ItemStack> items) {
|
||||
public Recipe getRecipe(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
|
@ -14,6 +14,7 @@ import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
@ -25,7 +26,7 @@ import java.util.stream.Collectors;
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(World world, List<ItemStack> items) {
|
||||
public CraftingResult craft(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
@ -70,7 +71,7 @@ public class Crafting implements CraftingProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(World world, List<ItemStack> items) {
|
||||
public Recipe getRecipe(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
|
@ -2,9 +2,8 @@ package com.jamesdpeters.minecraft.chests.v1_17_R1;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.CraftingProvider;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.CraftingContainer;
|
||||
import net.minecraft.world.inventory.CraftingMenu;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.crafting.CraftingRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
@ -12,8 +11,9 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
@ -24,20 +24,10 @@ import java.util.stream.Collectors;
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(World world, List<ItemStack> items) {
|
||||
AbstractContainerMenu container = new AbstractContainerMenu(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
CraftingContainer crafting = new CraftingContainer(container, 3, 3);
|
||||
public CraftingResult craft(Player player, World world, List<ItemStack> items) {
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
CraftingMenu menu = new CraftingMenu(-1, craftPlayer.getHandle().getInventory());
|
||||
CraftingContainer crafting = new CraftingContainer(menu.getBukkitView().getHandle(), 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
@ -69,21 +59,10 @@ public class Crafting implements CraftingProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(World world, List<ItemStack> items) {
|
||||
AbstractContainerMenu container = new AbstractContainerMenu(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CraftingContainer crafting = new CraftingContainer(container, 3, 3);
|
||||
public Recipe getRecipe(Player player, World world, List<ItemStack> items) {
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
CraftingMenu menu = new CraftingMenu(-1, craftPlayer.getHandle().getInventory());
|
||||
CraftingContainer crafting = new CraftingContainer(menu.getBukkitView().getHandle(), 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
if(i >= 9) break; // ItemList cant contain more than 9 items.
|
||||
@ -94,12 +73,6 @@ public class Crafting implements CraftingProvider {
|
||||
CraftWorld craftWorld = (CraftWorld) world;
|
||||
Optional<CraftingRecipe> optional = server.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, crafting, craftWorld.getHandle());
|
||||
|
||||
// var map = server.getServer().getRecipeManager().recipes.get(RecipeType.CRAFTING);
|
||||
//
|
||||
// Optional<CraftingRecipe> recipe = map.values().stream().flatMap(recipe1 -> {
|
||||
// recipe1.matches()
|
||||
// })
|
||||
|
||||
return optional.map(net.minecraft.world.item.crafting.Recipe::toBukkitRecipe).orElse(null);
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.jamesdpeters.minecraft.chests.CraftingResult;
|
||||
import com.jamesdpeters.minecraft.chests.api.ApiSpecific;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
@ -31,12 +32,12 @@ public class Crafting {
|
||||
});
|
||||
}
|
||||
|
||||
public static Recipe getRecipe(List<ItemStack> craftingTable) {
|
||||
return ApiSpecific.getNmsProvider().getCraftingProvider().getRecipe(Bukkit.getWorlds().get(0), craftingTable);
|
||||
public static Recipe getRecipe(Player player, List<ItemStack> craftingTable) {
|
||||
return ApiSpecific.getNmsProvider().getCraftingProvider().getRecipe(player, Bukkit.getWorlds().get(0), craftingTable);
|
||||
}
|
||||
|
||||
public static CraftingResult craft(List<ItemStack> recipe) {
|
||||
return ApiSpecific.getNmsProvider().getCraftingProvider().craft(Bukkit.getWorlds().get(0), recipe);
|
||||
public static CraftingResult craft(Player player, List<ItemStack> recipe) {
|
||||
return ApiSpecific.getNmsProvider().getCraftingProvider().craft(player, Bukkit.getWorlds().get(0), recipe);
|
||||
}
|
||||
|
||||
public static Recipe getRecipeByKey(NamespacedKey key) {
|
||||
|
@ -110,7 +110,7 @@ public class VirtualCraftingHolder implements InventoryHolder {
|
||||
else if (recipe instanceof ShapelessRecipe) setCrafting((ShapelessRecipe) recipe);
|
||||
else {
|
||||
// For ComplexRecipes or other implementations just use the result and original matrix for choices.
|
||||
result = ApiSpecific.getNmsProvider().getCraftingProvider().craft(Bukkit.getWorlds().get(0), matrix).getResult();
|
||||
result = ApiSpecific.getNmsProvider().getCraftingProvider().craft(storage.getOwner().getPlayer(), Bukkit.getWorlds().get(0), matrix).getResult();
|
||||
for (int i = 0; i < matrix.size(); i++) {
|
||||
ItemStack item = matrix.get(i);
|
||||
if (item != null) {
|
||||
@ -139,7 +139,7 @@ public class VirtualCraftingHolder implements InventoryHolder {
|
||||
List<ItemStack> crafting = new ArrayList<>(Arrays.asList(inventory.getContents()));
|
||||
crafting.remove(0);
|
||||
|
||||
Recipe recipe = Crafting.getRecipe(crafting);
|
||||
Recipe recipe = Crafting.getRecipe(storage.getOwner().getPlayer(), crafting);
|
||||
getStorage().setRecipe(recipe, crafting); // Only store the crafting matrix if the recipe is valid
|
||||
resetChoices();
|
||||
|
||||
@ -417,9 +417,9 @@ public class VirtualCraftingHolder implements InventoryHolder {
|
||||
if (recipe == null) return false;
|
||||
|
||||
// Use NMS to get the real result considering meta data etc.
|
||||
CraftingResult craftingResult = Crafting.craft(recipe);
|
||||
CraftingResult craftingResult = Crafting.craft(storage.getOwner().getPlayer(), recipe);
|
||||
|
||||
Recipe recipeActual = Crafting.getRecipe(recipe);
|
||||
Recipe recipeActual = Crafting.getRecipe(storage.getOwner().getPlayer(), recipe);
|
||||
CraftingInventoryImpl craftingInventoryImpl = new CraftingInventoryImpl(craftingInventory, craftingResult.getResult(), recipe, recipeActual);
|
||||
InventoryViewImpl inventoryView = new InventoryViewImpl(craftingInventory, output, ApiSpecific.getNmsProvider().getNPCProvider().createHumanEntity());
|
||||
PrepareItemCraftEvent itemCraftEvent = new PrepareItemCraftEvent(craftingInventoryImpl, inventoryView, false);
|
||||
|
@ -55,6 +55,9 @@ public class HopperListener implements Listener {
|
||||
while (true) {
|
||||
ItemStack item = event.getSource().getItem(index++);
|
||||
|
||||
if (item == null)
|
||||
continue;
|
||||
|
||||
if (index >= event.getSource().getSize())
|
||||
return;
|
||||
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.Keyed;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.configuration.serialization.SerializableAs;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
@ -43,9 +44,11 @@ public class RecipeSerializable implements ConfigurationSerializable {
|
||||
//noinspection deprecation
|
||||
namespacedKey = new NamespacedKey((String) map.get("namespace"), (String) map.get("key"));
|
||||
recipe = Crafting.getRecipeByKey(namespacedKey);
|
||||
}
|
||||
|
||||
public void updateRecipe(Player player) {
|
||||
if (recipe == null) {
|
||||
recipe = ApiSpecific.getNmsProvider().getCraftingProvider().getRecipe(Bukkit.getWorlds().get(0), items);
|
||||
recipe = ApiSpecific.getNmsProvider().getCraftingProvider().getRecipe(player, Bukkit.getWorlds().get(0), items);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,9 +69,6 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public AbstractStorage(Map<String, Object> map) {
|
||||
//Pass map through
|
||||
deserialize(map);
|
||||
|
||||
//This reformats the previous method of location storage to the newer version.
|
||||
List<Location> locations = (ArrayList<Location>) map.get("locations");
|
||||
if (locations != null) {
|
||||
@ -101,11 +98,15 @@ public abstract class AbstractStorage implements ConfigurationSerializable {
|
||||
}
|
||||
}
|
||||
|
||||
//Pass map through
|
||||
deserialize(map);
|
||||
|
||||
inventory = initInventory();
|
||||
if (storeInventory()) {
|
||||
ItemStack[] itemStacks = ((ArrayList<ItemStack>) map.get("inventory")).toArray(new ItemStack[0]);
|
||||
inventory.setContents(itemStacks);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -51,6 +51,7 @@ public class AutoCraftingStorage extends AbstractStorage implements Configuratio
|
||||
@Override
|
||||
protected void deserialize(Map<String, Object> map) {
|
||||
recipeSerializable = (RecipeSerializable) map.get("recipe");
|
||||
recipeSerializable.updateRecipe(getOwner().getPlayer());
|
||||
identifier = (String) map.get("identifier");
|
||||
initInventory();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user