Fixed OfflinePlayer Autocrafting

This commit is contained in:
James Peters 2022-01-12 19:57:07 +00:00
parent 332d6d3df1
commit 2dd3481c6a
26 changed files with 706 additions and 232 deletions

View File

@ -6,10 +6,17 @@ before_install:
- bash build-pre1.17.sh - bash build-pre1.17.sh
- wget https://github.com/sormuras/bach/raw/master/install-jdk.sh - wget https://github.com/sormuras/bach/raw/master/install-jdk.sh
- chmod +x $TRAVIS_BUILD_DIR/BuildTools/install-jdk.sh - chmod +x $TRAVIS_BUILD_DIR/BuildTools/install-jdk.sh
# Installs Java 16 and runs scripts needing Java 16.
- export JAVA_HOME=$HOME/openjdk16 - export JAVA_HOME=$HOME/openjdk16
- $TRAVIS_BUILD_DIR/BuildTools/install-jdk.sh -F 16 --target $JAVA_HOME - $TRAVIS_BUILD_DIR/BuildTools/install-jdk.sh -F 16 --target $JAVA_HOME
- export PATH=$JAVA_HOME/bin:$PATH - export PATH=$JAVA_HOME/bin:$PATH
#- bash build-1.17+.sh - bash build-1.17.sh
# Installs Java 17 and runs scripts needing Java 17.
- export JAVA_HOME=$HOME/openjdk17
- $TRAVIS_BUILD_DIR/BuildTools/install-jdk.sh -F 17 --target $JAVA_HOME
- export PATH=$JAVA_HOME/bin:$PATH
- bash build-1.18+.sh
##
- cd ../ - cd ../
install: install:

31
BuildTools/build-1.18+.sh Normal file
View File

@ -0,0 +1,31 @@
#!/bin/sh
echo "Checking BuildTools 1.18+ cache"
#Local Maven Repo
MAVEN_DIR="$HOME/.m2"
#CraftBukkit in local repo
SPIGOT="${MAVEN_DIR}/repository/org/spigotmc/spigot"
#Versions
array=("1.18.1")
#Download BuildTools jar
curl -s -o BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
for i in "${array[@]}"
do
VERSION_DIR="${SPIGOT}/${i}-R0.1-SNAPSHOT"
if [ -d "$VERSION_DIR" ]; then
echo "Spigot version ${i} is cached in ${VERSION_DIR}!"
echo "Checking for latest commit! "
java -jar BuildTools.jar --rev ${i} --compile-if-changed --remapped > /dev/null 2>&1
echo "Finished Check."
else
echo "Spigot version ${i} isn't cached!"
echo "Running BuildTools!"
java -jar BuildTools.jar --rev ${i} --remapped > /dev/null 2>&1
echo "Compiled Spigot ${i} in ${VERSION_DIR}"
fi
done

View File

@ -7,7 +7,7 @@ import org.bukkit.inventory.Recipe;
public interface CraftingProvider { public interface CraftingProvider {
CraftingResult craft(Player player, World world, ItemStack[] items); CraftingResult craft(World world, ItemStack[] items);
Recipe getRecipe(Player player, World world, ItemStack[] items); Recipe getRecipe(Player player, World world, ItemStack[] items);
} }

View File

@ -1,5 +1,14 @@
package com.jamesdpeters.minecraft.chests; package com.jamesdpeters.minecraft.chests;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
public record CraftingResult(ItemStack result, ItemStack[] matrixResult) {} import java.util.List;
import java.util.Objects;
public record CraftingResult(ItemStack result, ItemStack[] matrixResult, List<ItemStack> overflowItems) {
public void setResultMatrix(int i, ItemStack asBukkitCopy) {
matrixResult[i] = Objects.requireNonNullElseGet(asBukkitCopy, () -> new ItemStack(Material.AIR));
}
}

View File

@ -35,12 +35,6 @@
<version>1.16.1-R0.1-SNAPSHOT</version> <version>1.16.1-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_15</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>org.bukkit</groupId> <groupId>org.bukkit</groupId>

View File

@ -3,63 +3,59 @@ package com.jamesdpeters.minecraft.chests.v1_16_R1;
import com.jamesdpeters.minecraft.chests.CraftingProvider; import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.CraftingResult; import com.jamesdpeters.minecraft.chests.CraftingResult;
import net.minecraft.server.v1_16_R1.Container; import net.minecraft.server.v1_16_R1.Container;
import net.minecraft.server.v1_16_R1.ContainerWorkbench;
import net.minecraft.server.v1_16_R1.EntityHuman; import net.minecraft.server.v1_16_R1.EntityHuman;
import net.minecraft.server.v1_16_R1.IRecipe; import net.minecraft.server.v1_16_R1.IRecipe;
import net.minecraft.server.v1_16_R1.InventoryCraftResult;
import net.minecraft.server.v1_16_R1.InventoryCrafting; import net.minecraft.server.v1_16_R1.InventoryCrafting;
import net.minecraft.server.v1_16_R1.Item; import net.minecraft.server.v1_16_R1.NonNullList;
import net.minecraft.server.v1_16_R1.RecipeCrafting; import net.minecraft.server.v1_16_R1.RecipeCrafting;
import net.minecraft.server.v1_16_R1.RecipeRepair;
import net.minecraft.server.v1_16_R1.Recipes; import net.minecraft.server.v1_16_R1.Recipes;
import net.minecraft.server.v1_16_R1.WorldServer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_16_R1.CraftServer; import org.bukkit.craftbukkit.v1_16_R1.CraftServer;
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld; import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_16_R1.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryCrafting;
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe; import org.bukkit.inventory.Recipe;
import java.util.ArrayList;
import java.util.Optional; import java.util.Optional;
public class Crafting implements CraftingProvider { public class Crafting implements CraftingProvider {
@Override @Override
public CraftingResult craft(Player player, World world, ItemStack[] items) { public CraftingResult craft(World world, ItemStack[] items) {
CraftWorld craftWorld = (CraftWorld) world; CraftWorld craftWorld = (CraftWorld) world;
CraftPlayer craftPlayer = (CraftPlayer) player;
ContainerWorkbench workbench = new ContainerWorkbench(-1, craftPlayer.getHandle().inventory);
CraftInventoryView view = workbench.getBukkitView(); // Setup crafting inventories.
CraftInventoryCrafting craftInventoryCrafting = (CraftInventoryCrafting) view.getTopInventory(); InventoryCrafting inventoryCrafting = new InventoryCrafting(new Container(null, -1) {
InventoryCrafting inventoryCrafting = (InventoryCrafting) craftInventoryCrafting.getMatrixInventory(); @Override
InventoryCraftResult resultInventory = (InventoryCraftResult) craftInventoryCrafting.getResultInventory(); public InventoryView getBukkitView() {
return null;
}
Optional<RecipeCrafting> recipe = getNMSRecipe(items, inventoryCrafting, craftWorld); @Override
public boolean canUse(EntityHuman entityHuman) {
return false;
}
}, 3, 3);
net.minecraft.server.v1_16_R1.ItemStack itemstack = net.minecraft.server.v1_16_R1.ItemStack.b; for (int i = 0; i < items.length; i++) {
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
}
Optional<RecipeCrafting> recipe = ((CraftServer) Bukkit.getServer()).getServer().getCraftingManager().craft(Recipes.CRAFTING, inventoryCrafting, craftWorld.getHandle());
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.server.v1_16_R1.ItemStack itemStack = net.minecraft.server.v1_16_R1.ItemStack.b;
if (recipe.isPresent()) { if (recipe.isPresent()) {
RecipeCrafting recipeCrafting = recipe.get(); itemStack = recipe.get().a(inventoryCrafting);
if (resultInventory.a(craftWorld.getHandle(), craftPlayer.getHandle(), recipeCrafting)) {
itemstack = recipeCrafting.a(inventoryCrafting);
}
} }
net.minecraft.server.v1_16_R1.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, resultInventory, itemstack, view, recipe.orElse(null) instanceof RecipeRepair); return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
for(int i = 0; i < items.length; ++i) {
Item remaining = inventoryCrafting.getContents().get(i).getItem().getCraftingRemainingItem();
items[i] = remaining != null ? CraftItemStack.asBukkitCopy(remaining.r()) : null;
}
return new CraftingResult(CraftItemStack.asBukkitCopy(result), items);
} }
@Override @Override
@ -90,12 +86,38 @@ public class Crafting implements CraftingProvider {
return optional.map(IRecipe::toBukkitRecipe).orElse(null); return optional.map(IRecipe::toBukkitRecipe).orElse(null);
} }
private Optional<RecipeCrafting> getNMSRecipe(ItemStack[] craftingMatrix, InventoryCrafting inventoryCrafting, CraftWorld world) { private CraftingResult createItemCraftResult(ItemStack itemStack, InventoryCrafting inventoryCrafting, WorldServer worldServer) {
for(int i = 0; i < craftingMatrix.length; ++i) { CraftServer server = (CraftServer) Bukkit.getServer();
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(craftingMatrix[i])); NonNullList<net.minecraft.server.v1_16_R1.ItemStack> remainingItems = server.getServer().getCraftingManager().c(Recipes.CRAFTING, inventoryCrafting, worldServer);
CraftingResult craftItemResult = new CraftingResult(itemStack, new ItemStack[9], new ArrayList<>());
// Create resulting matrix and overflow items
for (int i = 0; i < remainingItems.size(); ++i) {
net.minecraft.server.v1_16_R1.ItemStack itemstack1 = inventoryCrafting.getItem(i);
net.minecraft.server.v1_16_R1.ItemStack itemstack2 = remainingItems.get(i);
if (!itemstack1.isEmpty()) {
inventoryCrafting.splitStack(i, 1);
itemstack1 = inventoryCrafting.getItem(i);
} }
CraftServer server = (CraftServer) Bukkit.getServer(); if (!itemstack2.isEmpty()) {
return server.getServer().getCraftingManager().craft(Recipes.CRAFTING, inventoryCrafting, world.getHandle()); if (itemstack1.isEmpty()) {
inventoryCrafting.setItem(i, itemstack2);
} else if (net.minecraft.server.v1_16_R1.ItemStack.equals(itemstack1, itemstack2) && net.minecraft.server.v1_16_R1.ItemStack.matches(itemstack1, itemstack2)) {
itemstack2.add(itemstack1.getCount());
inventoryCrafting.setItem(i, itemstack2);
} else {
craftItemResult.overflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
}
}
}
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
}
return craftItemResult;
} }
} }

View File

@ -3,63 +3,59 @@ package com.jamesdpeters.minecraft.chests.v1_16_R2;
import com.jamesdpeters.minecraft.chests.CraftingProvider; import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.CraftingResult; import com.jamesdpeters.minecraft.chests.CraftingResult;
import net.minecraft.server.v1_16_R2.Container; import net.minecraft.server.v1_16_R2.Container;
import net.minecraft.server.v1_16_R2.ContainerWorkbench;
import net.minecraft.server.v1_16_R2.EntityHuman; import net.minecraft.server.v1_16_R2.EntityHuman;
import net.minecraft.server.v1_16_R2.IRecipe; import net.minecraft.server.v1_16_R2.IRecipe;
import net.minecraft.server.v1_16_R2.InventoryCraftResult;
import net.minecraft.server.v1_16_R2.InventoryCrafting; import net.minecraft.server.v1_16_R2.InventoryCrafting;
import net.minecraft.server.v1_16_R2.Item; import net.minecraft.server.v1_16_R2.NonNullList;
import net.minecraft.server.v1_16_R2.RecipeCrafting; import net.minecraft.server.v1_16_R2.RecipeCrafting;
import net.minecraft.server.v1_16_R2.RecipeRepair;
import net.minecraft.server.v1_16_R2.Recipes; import net.minecraft.server.v1_16_R2.Recipes;
import net.minecraft.server.v1_16_R2.WorldServer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_16_R2.CraftServer; import org.bukkit.craftbukkit.v1_16_R2.CraftServer;
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld; import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_16_R2.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventoryCrafting;
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe; import org.bukkit.inventory.Recipe;
import java.util.ArrayList;
import java.util.Optional; import java.util.Optional;
public class Crafting implements CraftingProvider { public class Crafting implements CraftingProvider {
@Override @Override
public CraftingResult craft(Player player, World world, ItemStack[] items) { public CraftingResult craft(World world, ItemStack[] items) {
CraftWorld craftWorld = (CraftWorld) world; CraftWorld craftWorld = (CraftWorld) world;
CraftPlayer craftPlayer = (CraftPlayer) player;
ContainerWorkbench workbench = new ContainerWorkbench(-1, craftPlayer.getHandle().inventory);
CraftInventoryView view = workbench.getBukkitView(); // Setup crafting inventories.
CraftInventoryCrafting craftInventoryCrafting = (CraftInventoryCrafting) view.getTopInventory(); InventoryCrafting inventoryCrafting = new InventoryCrafting(new Container(null, -1) {
InventoryCrafting inventoryCrafting = (InventoryCrafting) craftInventoryCrafting.getMatrixInventory(); @Override
InventoryCraftResult resultInventory = (InventoryCraftResult) craftInventoryCrafting.getResultInventory(); public InventoryView getBukkitView() {
return null;
}
Optional<RecipeCrafting> recipe = getNMSRecipe(items, inventoryCrafting, craftWorld); @Override
public boolean canUse(EntityHuman entityHuman) {
return false;
}
}, 3, 3);
net.minecraft.server.v1_16_R2.ItemStack itemstack = net.minecraft.server.v1_16_R2.ItemStack.b; for (int i = 0; i < items.length; i++) {
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
}
Optional<RecipeCrafting> recipe = ((CraftServer) Bukkit.getServer()).getServer().getCraftingManager().craft(Recipes.CRAFTING, inventoryCrafting, craftWorld.getHandle());
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.server.v1_16_R2.ItemStack itemStack = net.minecraft.server.v1_16_R2.ItemStack.b;
if (recipe.isPresent()) { if (recipe.isPresent()) {
RecipeCrafting recipeCrafting = recipe.get(); itemStack = recipe.get().a(inventoryCrafting);
if (resultInventory.a(craftWorld.getHandle(), craftPlayer.getHandle(), recipeCrafting)) {
itemstack = recipeCrafting.a(inventoryCrafting);
}
} }
net.minecraft.server.v1_16_R2.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, resultInventory, itemstack, view, recipe.orElse(null) instanceof RecipeRepair); return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
for(int i = 0; i < items.length; ++i) {
Item remaining = inventoryCrafting.getContents().get(i).getItem().getCraftingRemainingItem();
items[i] = remaining != null ? CraftItemStack.asBukkitCopy(remaining.createItemStack()) : null;
}
return new CraftingResult(CraftItemStack.asBukkitCopy(result), items);
} }
@Override @Override
@ -90,12 +86,38 @@ public class Crafting implements CraftingProvider {
return optional.map(IRecipe::toBukkitRecipe).orElse(null); return optional.map(IRecipe::toBukkitRecipe).orElse(null);
} }
private Optional<RecipeCrafting> getNMSRecipe(ItemStack[] craftingMatrix, InventoryCrafting inventoryCrafting, CraftWorld world) { private CraftingResult createItemCraftResult(ItemStack itemStack, InventoryCrafting inventoryCrafting, WorldServer worldServer) {
for(int i = 0; i < craftingMatrix.length; ++i) { CraftServer server = (CraftServer) Bukkit.getServer();
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(craftingMatrix[i])); NonNullList<net.minecraft.server.v1_16_R2.ItemStack> remainingItems = server.getServer().getCraftingManager().c(Recipes.CRAFTING, inventoryCrafting, worldServer);
CraftingResult craftItemResult = new CraftingResult(itemStack, new ItemStack[9], new ArrayList<>());
// Create resulting matrix and overflow items
for (int i = 0; i < remainingItems.size(); ++i) {
net.minecraft.server.v1_16_R2.ItemStack itemstack1 = inventoryCrafting.getItem(i);
net.minecraft.server.v1_16_R2.ItemStack itemstack2 = remainingItems.get(i);
if (!itemstack1.isEmpty()) {
inventoryCrafting.splitStack(i, 1);
itemstack1 = inventoryCrafting.getItem(i);
} }
CraftServer server = (CraftServer) Bukkit.getServer(); if (!itemstack2.isEmpty()) {
return server.getServer().getCraftingManager().craft(Recipes.CRAFTING, inventoryCrafting, world.getHandle()); if (itemstack1.isEmpty()) {
inventoryCrafting.setItem(i, itemstack2);
} else if (net.minecraft.server.v1_16_R2.ItemStack.equals(itemstack1, itemstack2) && net.minecraft.server.v1_16_R2.ItemStack.matches(itemstack1, itemstack2)) {
itemstack2.add(itemstack1.getCount());
inventoryCrafting.setItem(i, itemstack2);
} else {
craftItemResult.overflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
}
}
}
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
}
return craftItemResult;
} }
} }

View File

@ -3,63 +3,59 @@ package com.jamesdpeters.minecraft.chests.v1_16_R3;
import com.jamesdpeters.minecraft.chests.CraftingProvider; import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.CraftingResult; import com.jamesdpeters.minecraft.chests.CraftingResult;
import net.minecraft.server.v1_16_R3.Container; import net.minecraft.server.v1_16_R3.Container;
import net.minecraft.server.v1_16_R3.ContainerWorkbench;
import net.minecraft.server.v1_16_R3.EntityHuman; import net.minecraft.server.v1_16_R3.EntityHuman;
import net.minecraft.server.v1_16_R3.IRecipe; import net.minecraft.server.v1_16_R3.IRecipe;
import net.minecraft.server.v1_16_R3.InventoryCraftResult;
import net.minecraft.server.v1_16_R3.InventoryCrafting; import net.minecraft.server.v1_16_R3.InventoryCrafting;
import net.minecraft.server.v1_16_R3.Item; import net.minecraft.server.v1_16_R3.NonNullList;
import net.minecraft.server.v1_16_R3.RecipeCrafting; import net.minecraft.server.v1_16_R3.RecipeCrafting;
import net.minecraft.server.v1_16_R3.RecipeRepair;
import net.minecraft.server.v1_16_R3.Recipes; import net.minecraft.server.v1_16_R3.Recipes;
import net.minecraft.server.v1_16_R3.WorldServer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.v1_16_R3.CraftServer; import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld; import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_16_R3.event.CraftEventFactory;
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryCrafting;
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView;
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe; import org.bukkit.inventory.Recipe;
import java.util.ArrayList;
import java.util.Optional; import java.util.Optional;
public class Crafting implements CraftingProvider { public class Crafting implements CraftingProvider {
@Override @Override
public CraftingResult craft(Player player, World world, ItemStack[] items) { public CraftingResult craft(World world, ItemStack[] items) {
CraftWorld craftWorld = (CraftWorld) world; CraftWorld craftWorld = (CraftWorld) world;
CraftPlayer craftPlayer = (CraftPlayer) player;
ContainerWorkbench workbench = new ContainerWorkbench(-1, craftPlayer.getHandle().inventory);
CraftInventoryView view = workbench.getBukkitView(); // Setup crafting inventories.
CraftInventoryCrafting craftInventoryCrafting = (CraftInventoryCrafting) view.getTopInventory(); InventoryCrafting inventoryCrafting = new InventoryCrafting(new Container(null, -1) {
InventoryCrafting inventoryCrafting = (InventoryCrafting) craftInventoryCrafting.getMatrixInventory(); @Override
InventoryCraftResult resultInventory = (InventoryCraftResult) craftInventoryCrafting.getResultInventory(); public InventoryView getBukkitView() {
return null;
}
Optional<RecipeCrafting> recipe = getNMSRecipe(items, inventoryCrafting, craftWorld); @Override
public boolean canUse(EntityHuman entityHuman) {
return false;
}
}, 3, 3);
net.minecraft.server.v1_16_R3.ItemStack itemstack = net.minecraft.server.v1_16_R3.ItemStack.b; for (int i = 0; i < items.length; i++) {
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
}
Optional<RecipeCrafting> recipe = ((CraftServer) Bukkit.getServer()).getServer().getCraftingManager().craft(Recipes.CRAFTING, inventoryCrafting, craftWorld.getHandle());
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.server.v1_16_R3.ItemStack itemStack = net.minecraft.server.v1_16_R3.ItemStack.b;
if (recipe.isPresent()) { if (recipe.isPresent()) {
RecipeCrafting recipeCrafting = recipe.get(); itemStack = recipe.get().a(inventoryCrafting);
if (resultInventory.a(craftWorld.getHandle(), craftPlayer.getHandle(), recipeCrafting)) {
itemstack = recipeCrafting.a(inventoryCrafting);
}
} }
net.minecraft.server.v1_16_R3.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, resultInventory, itemstack, view, recipe.orElse(null) instanceof RecipeRepair); return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
for(int i = 0; i < items.length; ++i) {
Item remaining = inventoryCrafting.getContents().get(i).getItem().getCraftingRemainingItem();
items[i] = remaining != null ? CraftItemStack.asBukkitCopy(remaining.createItemStack()) : null;
}
return new CraftingResult(CraftItemStack.asBukkitCopy(result), items);
} }
@Override @Override
@ -98,4 +94,39 @@ public class Crafting implements CraftingProvider {
CraftServer server = (CraftServer) Bukkit.getServer(); CraftServer server = (CraftServer) Bukkit.getServer();
return server.getServer().getCraftingManager().craft(Recipes.CRAFTING, inventoryCrafting, world.getHandle()); return server.getServer().getCraftingManager().craft(Recipes.CRAFTING, inventoryCrafting, world.getHandle());
} }
private CraftingResult createItemCraftResult(ItemStack itemStack, InventoryCrafting inventoryCrafting, WorldServer worldServer) {
CraftServer server = (CraftServer) Bukkit.getServer();
NonNullList<net.minecraft.server.v1_16_R3.ItemStack> remainingItems = server.getServer().getCraftingManager().c(Recipes.CRAFTING, inventoryCrafting, worldServer);
CraftingResult craftItemResult = new CraftingResult(itemStack, new ItemStack[9], new ArrayList<>());
// Create resulting matrix and overflow items
for (int i = 0; i < remainingItems.size(); ++i) {
net.minecraft.server.v1_16_R3.ItemStack itemstack1 = inventoryCrafting.getItem(i);
net.minecraft.server.v1_16_R3.ItemStack itemstack2 = remainingItems.get(i);
if (!itemstack1.isEmpty()) {
inventoryCrafting.splitStack(i, 1);
itemstack1 = inventoryCrafting.getItem(i);
}
if (!itemstack2.isEmpty()) {
if (itemstack1.isEmpty()) {
inventoryCrafting.setItem(i, itemstack2);
} else if (net.minecraft.server.v1_16_R3.ItemStack.equals(itemstack1, itemstack2) && net.minecraft.server.v1_16_R3.ItemStack.matches(itemstack1, itemstack2)) {
itemstack2.add(itemstack1.getCount());
inventoryCrafting.setItem(i, itemstack2);
} else {
craftItemResult.overflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
}
}
}
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
}
return craftItemResult;
}
} }

View File

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ChestsPlusPlus-Parent</artifactId>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<properties>
<minecraft.version>1.17.1</minecraft.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>ChestsPlusPlus_1_17_R1</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus-API</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${minecraft.version}-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_16</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>${minecraft.version}-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
<version>1.2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-obf</id>
<configuration>
<srgIn>org.spigotmc:minecraft-server:${minecraft.version}-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:${minecraft.version}-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-spigot</id>
<configuration>
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:${minecraft.version}-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:${minecraft.version}-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,97 @@
package com.jamesdpeters.minecraft.chests.v1_17_R1;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.CraftingResult;
import net.minecraft.core.NonNullList;
import net.minecraft.server.level.WorldServer;
import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.world.inventory.Container;
import net.minecraft.world.inventory.InventoryCrafting;
import net.minecraft.world.item.crafting.Recipes;
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.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import java.util.ArrayList;
public class Crafting implements CraftingProvider {
@Override
public CraftingResult craft(World world, ItemStack[] items) {
CraftWorld craftWorld = (CraftWorld) world;
// Setup crafting inventories.
InventoryCrafting inventoryCrafting = new InventoryCrafting(new Container(null, -1) {
@Override
public InventoryView getBukkitView() {
return null;
}
@Override
public boolean canUse(EntityHuman entityHuman) {
return false;
}
}, 3, 3);
for (int i = 0; i < items.length; i++) {
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
}
var recipe = ((CraftServer) Bukkit.getServer()).getServer().getCraftingManager().craft(Recipes.a, inventoryCrafting, craftWorld.getHandle());
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.world.item.ItemStack itemStack = net.minecraft.world.item.ItemStack.b;
if (recipe.isPresent()) {
itemStack = recipe.get().a(inventoryCrafting);
}
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
}
@Override
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
return Bukkit.getCraftingRecipe(items, world);
}
private CraftingResult createItemCraftResult(ItemStack itemStack, InventoryCrafting inventoryCrafting, WorldServer worldServer) {
CraftServer server = (CraftServer) Bukkit.getServer();
NonNullList<net.minecraft.world.item.ItemStack> remainingItems = server.getServer().getCraftingManager().c(Recipes.a, inventoryCrafting, worldServer);
CraftingResult craftItemResult = new CraftingResult(itemStack, new ItemStack[9], new ArrayList<>());
// Create resulting matrix and overflow items
for (int i = 0; i < remainingItems.size(); ++i) {
net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i);
net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i);
if (!itemstack1.isEmpty()) {
inventoryCrafting.splitStack(i, 1);
itemstack1 = inventoryCrafting.getItem(i);
}
if (!itemstack2.isEmpty()) {
if (itemstack1.isEmpty()) {
inventoryCrafting.setItem(i, itemstack2);
} else if (net.minecraft.world.item.ItemStack.equals(itemstack1, itemstack2) && net.minecraft.world.item.ItemStack.matches(itemstack1, itemstack2)) {
itemstack2.add(itemstack1.getCount());
inventoryCrafting.setItem(i, itemstack2);
} else {
craftItemResult.overflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
}
}
}
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
}
return craftItemResult;
}
}

View File

@ -1,4 +1,4 @@
package com.jamesdpeters.minecraft.chests.latest; package com.jamesdpeters.minecraft.chests.v1_17_R1;
import com.jamesdpeters.minecraft.chests.EntityEventListener; import com.jamesdpeters.minecraft.chests.EntityEventListener;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;

View File

@ -1,4 +1,4 @@
package com.jamesdpeters.minecraft.chests.latest; package com.jamesdpeters.minecraft.chests.v1_17_R1;
import com.jamesdpeters.minecraft.chests.BaseMaterialChecker; import com.jamesdpeters.minecraft.chests.BaseMaterialChecker;
import com.jamesdpeters.minecraft.chests.MaterialChecker; import com.jamesdpeters.minecraft.chests.MaterialChecker;

View File

@ -1,4 +1,4 @@
package com.jamesdpeters.minecraft.chests.latest; package com.jamesdpeters.minecraft.chests.v1_17_R1;
import com.jamesdpeters.minecraft.chests.ChestOpener; import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.CraftingProvider; import com.jamesdpeters.minecraft.chests.CraftingProvider;

View File

@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ChestsPlusPlus-Parent</artifactId>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<properties>
<minecraft.version>1.18.1</minecraft.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>ChestsPlusPlus_1_18_R1</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus-API</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${minecraft.version}-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_17_R1</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>${minecraft.version}-R0.1-SNAPSHOT</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
<version>1.2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-obf</id>
<configuration>
<srgIn>org.spigotmc:minecraft-server:${minecraft.version}-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:${minecraft.version}-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
<remappedArtifactAttached>true</remappedArtifactAttached>
<remappedClassifierName>remapped-obf</remappedClassifierName>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-spigot</id>
<configuration>
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:${minecraft.version}-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:${minecraft.version}-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,97 @@
package com.jamesdpeters.minecraft.chests.v1_18_R1;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.CraftingResult;
import net.minecraft.core.NonNullList;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_18_R1.CraftServer;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.inventory.InventoryView;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import java.util.ArrayList;
public class Crafting implements CraftingProvider {
@Override
public CraftingResult craft(World world, ItemStack[] items) {
CraftWorld craftWorld = (CraftWorld) world;
// Setup crafting inventories.
CraftingContainer inventoryCrafting = new CraftingContainer(new AbstractContainerMenu(null, -1) {
@Override
public InventoryView getBukkitView() {
return null;
}
@Override
public boolean stillValid(net.minecraft.world.entity.player.Player player) {
return false;
}
}, 3, 3);
for (int i = 0; i < items.length; i++) {
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
}
var recipe = ((CraftServer) Bukkit.getServer()).getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventoryCrafting, craftWorld.getHandle());
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.world.item.ItemStack itemStack = net.minecraft.world.item.ItemStack.EMPTY;
if (recipe.isPresent()) {
itemStack = recipe.get().assemble(inventoryCrafting);
}
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
}
@Override
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
return Bukkit.getCraftingRecipe(items, world);
}
private CraftingResult createItemCraftResult(ItemStack itemStack, CraftingContainer inventoryCrafting, Level worldServer) {
CraftServer server = (CraftServer) Bukkit.getServer();
NonNullList<net.minecraft.world.item.ItemStack> remainingItems = server.getServer().getRecipeManager().getRemainingItemsFor(RecipeType.CRAFTING, inventoryCrafting, worldServer);
CraftingResult craftItemResult = new CraftingResult(itemStack, new ItemStack[9], new ArrayList<>());
// Create resulting matrix and overflow items
for (int i = 0; i < remainingItems.size(); ++i) {
net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i);
net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i);
if (!itemstack1.isEmpty()) {
inventoryCrafting.removeItem(i, 1);
itemstack1 = inventoryCrafting.getItem(i);
}
if (!itemstack2.isEmpty()) {
if (itemstack1.isEmpty()) {
inventoryCrafting.setItem(i, itemstack2);
} else if (net.minecraft.world.item.ItemStack.tagMatches(itemstack1, itemstack2) && net.minecraft.world.item.ItemStack.matches(itemstack1, itemstack2)) {
itemstack2.grow(itemstack1.getCount());
inventoryCrafting.setItem(i, itemstack2);
} else {
craftItemResult.overflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
}
}
}
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
}
return craftItemResult;
}
}

View File

@ -0,0 +1,50 @@
package com.jamesdpeters.minecraft.chests.v1_18_R1;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.EntityEventListener;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.NMSProvider;
import com.jamesdpeters.minecraft.chests.v1_17_R1.EntityEventListener_1_17;
import com.jamesdpeters.minecraft.chests.v1_17_R1.MaterialChecker_1_17_R1;
import com.jamesdpeters.minecraft.chests.v1_18_R1.Crafting;
import org.bukkit.block.Lidded;
import org.bukkit.entity.ItemFrame;
public class NMSProviderImpl implements NMSProvider {
@Override
public ChestOpener getChestOpener() {
return (inventory, container, tileEntityOpener) -> {
if(container instanceof Lidded){
if(inventory.getViewers().size() > 0){
((Lidded) container).open();
} else {
((Lidded) container).close();
}
}
return null;
};
}
@Override
public MaterialChecker getMaterialChecker() {
return new MaterialChecker_1_17_R1();
}
@Override
public CraftingProvider getCraftingProvider() {
return new Crafting();
}
@Override
public EntityEventListener getEntityEventListener() {
return new EntityEventListener_1_17();
}
@Override
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
itemFrame.setVisible(visible);
}
}

View File

@ -1,64 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ChestsPlusPlus-Parent</artifactId>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<properties>
<minecraft.version>1.17.1</minecraft.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>ChestsPlusPlus_LatestMC</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>spigotmc-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus-API</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${minecraft.version}-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_16</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>16</source>
<target>16</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,28 +0,0 @@
package com.jamesdpeters.minecraft.chests.latest;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.CraftingResult;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import java.util.Arrays;
public class Crafting implements CraftingProvider {
@Override
public CraftingResult craft(Player player, World world, ItemStack[] items) {
// Create copy of array since Bukkit#craftItem modifies the input array.
ItemStack[] itemsCopy = Arrays.copyOf(items, items.length);
var item = Bukkit.craftItem(itemsCopy, world, player);
return new CraftingResult(item, itemsCopy);
}
@Override
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
return Bukkit.getCraftingRecipe(items, world);
}
}

View File

@ -22,13 +22,13 @@
<repositories> <repositories>
<repository> <repository>
<id>spigotmc-repo</id> <id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository> </repository>
<repository> <repository>
<id>dmulloy2-repo</id> <id>dmulloy2-repo</id>
<url>http://repo.dmulloy2.net/nexus/repository/public/</url> <url>https://repo.dmulloy2.net/nexus/repository/public/</url>
</repository> </repository>
<repository> <repository>
@ -36,10 +36,10 @@
<url>https://repo.codemc.org/repository/maven-public</url> <url>https://repo.codemc.org/repository/maven-public</url>
</repository> </repository>
<repository> <!-- <repository>-->
<id>sytm-nexus</id> <!-- <id>sytm-nexus</id>-->
<url>https://repo.sytm.de/repository/maven-hosted/</url> <!-- <url>https://repo.sytm.de/repository/maven-hosted/</url>-->
</repository> <!-- </repository>-->
<repository> <repository>
<id>jitpack.io</id> <id>jitpack.io</id>
@ -101,7 +101,15 @@
<dependency> <dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId> <groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_LatestMC</artifactId> <artifactId>ChestsPlusPlus_1_18_R1</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_17_R1</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<type>jar</type> <type>jar</type>
<scope>compile</scope> <scope>compile</scope>
@ -131,22 +139,6 @@
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_15</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_14</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId> <groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus-API</artifactId> <artifactId>ChestsPlusPlus-API</artifactId>

View File

@ -1,7 +1,11 @@
package com.jamesdpeters.minecraft.chests.api; package com.jamesdpeters.minecraft.chests.api;
import com.jamesdpeters.minecraft.chests.*; import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.latest.NMSProviderImpl; import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.EntityEventListener;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.NMSProvider;
import com.jamesdpeters.minecraft.chests.v1_17_R1.NMSProviderImpl;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
public class NMSProviderDefault implements NMSProvider { public class NMSProviderDefault implements NMSProvider {

View File

@ -37,7 +37,7 @@ public class Crafting {
} }
public static CraftingResult craft(Player player, ItemStack[] recipe) { public static CraftingResult craft(Player player, ItemStack[] recipe) {
return ApiSpecific.getNmsProvider().getCraftingProvider().craft(player, Bukkit.getWorlds().get(0), recipe); return ApiSpecific.getNmsProvider().getCraftingProvider().craft(Bukkit.getWorlds().get(0), recipe);
} }
public static Recipe getRecipeByKey(NamespacedKey key) { public static Recipe getRecipeByKey(NamespacedKey key) {

View File

@ -106,7 +106,7 @@ public class VirtualCraftingHolder implements InventoryHolder {
else if (recipe instanceof ShapelessRecipe) setCrafting((ShapelessRecipe) recipe); else if (recipe instanceof ShapelessRecipe) setCrafting((ShapelessRecipe) recipe);
else { else {
// For ComplexRecipes or other implementations just use the result and original matrix for choices. // For ComplexRecipes or other implementations just use the result and original matrix for choices.
result = ApiSpecific.getNmsProvider().getCraftingProvider().craft(storage.getOwner().getPlayer(), Bukkit.getWorlds().get(0), matrix).result(); result = ApiSpecific.getNmsProvider().getCraftingProvider().craft(Bukkit.getWorlds().get(0), matrix).result();
for (int i = 0; i < matrix.length; i++) { for (int i = 0; i < matrix.length; i++) {
ItemStack item = matrix[i]; ItemStack item = matrix[i];
if (item != null) { if (item != null) {

View File

@ -1,4 +1,4 @@
# Chests++ Language File (Version 2.5.2-BETA-2) # Chests++ Language File (Version 2.5.2-BETA-3)
# NOTE: This file gets replaced when the plugin launches! If you want to make modifications create a copy first! # NOTE: This file gets replaced when the plugin launches! If you want to make modifications create a copy first!
# To create a new language file simply create a copy of this file and rename it to your desired choice for example 'en_US.properties' # To create a new language file simply create a copy of this file and rename it to your desired choice for example 'en_US.properties'
# It should be located in the 'lang' folder # It should be located in the 'lang' folder

View File

@ -41,7 +41,7 @@
<dependency> <dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId> <groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus-Master</artifactId> <artifactId>ChestsPlusPlus-Master</artifactId>
<version>2.3.1-Release</version> <version>2.5.2-BETA-3</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View File

@ -16,7 +16,8 @@
<modules> <modules>
<module>ChestsPlusPlusAPI</module> <module>ChestsPlusPlusAPI</module>
<module>ChestsPlusPlus_LatestMC</module> <module>ChestsPlusPlus_1_18_R1</module>
<module>ChestsPlusPlus_1_17_R1</module>
<module>ChestsPlusPlus_1_16_R3</module> <module>ChestsPlusPlus_1_16_R3</module>
<module>ChestsPlusPlus_1_16_R2</module> <module>ChestsPlusPlus_1_16_R2</module>
<module>ChestsPlusPlus_1_16</module> <module>ChestsPlusPlus_1_16</module>
@ -25,7 +26,7 @@
<repositories> <repositories>
<repository> <repository>
<id>spigotmc-repo</id> <id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url> <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository> </repository>
</repositories> </repositories>