mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2024-11-21 18:16:09 +01:00
Fixed OfflinePlayer Autocrafting
This commit is contained in:
parent
332d6d3df1
commit
2dd3481c6a
@ -6,10 +6,17 @@ before_install:
|
||||
- bash build-pre1.17.sh
|
||||
- wget https://github.com/sormuras/bach/raw/master/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
|
||||
- $TRAVIS_BUILD_DIR/BuildTools/install-jdk.sh -F 16 --target $JAVA_HOME
|
||||
- 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 ../
|
||||
|
||||
install:
|
||||
|
31
BuildTools/build-1.18+.sh
Normal file
31
BuildTools/build-1.18+.sh
Normal 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
|
@ -7,7 +7,7 @@ import org.bukkit.inventory.Recipe;
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -1,5 +1,14 @@
|
||||
package com.jamesdpeters.minecraft.chests;
|
||||
|
||||
import org.bukkit.Material;
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -35,12 +35,6 @@
|
||||
<version>1.16.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
||||
<artifactId>ChestsPlusPlus_1_15</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
|
@ -3,63 +3,59 @@ package com.jamesdpeters.minecraft.chests.v1_16_R1;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingProvider;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingResult;
|
||||
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.IRecipe;
|
||||
import net.minecraft.server.v1_16_R1.InventoryCraftResult;
|
||||
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.RecipeRepair;
|
||||
import net.minecraft.server.v1_16_R1.Recipes;
|
||||
import net.minecraft.server.v1_16_R1.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
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.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.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(Player player, World world, ItemStack[] items) {
|
||||
public CraftingResult craft(World world, ItemStack[] items) {
|
||||
CraftWorld craftWorld = (CraftWorld) world;
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
ContainerWorkbench workbench = new ContainerWorkbench(-1, craftPlayer.getHandle().inventory);
|
||||
|
||||
CraftInventoryView view = workbench.getBukkitView();
|
||||
CraftInventoryCrafting craftInventoryCrafting = (CraftInventoryCrafting) view.getTopInventory();
|
||||
InventoryCrafting inventoryCrafting = (InventoryCrafting) craftInventoryCrafting.getMatrixInventory();
|
||||
InventoryCraftResult resultInventory = (InventoryCraftResult) craftInventoryCrafting.getResultInventory();
|
||||
// Setup crafting inventories.
|
||||
InventoryCrafting inventoryCrafting = new InventoryCrafting(new Container(null, -1) {
|
||||
@Override
|
||||
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()) {
|
||||
RecipeCrafting recipeCrafting = recipe.get();
|
||||
if (resultInventory.a(craftWorld.getHandle(), craftPlayer.getHandle(), recipeCrafting)) {
|
||||
itemstack = recipeCrafting.a(inventoryCrafting);
|
||||
}
|
||||
itemStack = recipe.get().a(inventoryCrafting);
|
||||
}
|
||||
|
||||
net.minecraft.server.v1_16_R1.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, resultInventory, itemstack, view, recipe.orElse(null) instanceof RecipeRepair);
|
||||
|
||||
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);
|
||||
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -90,12 +86,38 @@ public class Crafting implements CraftingProvider {
|
||||
return optional.map(IRecipe::toBukkitRecipe).orElse(null);
|
||||
}
|
||||
|
||||
private Optional<RecipeCrafting> getNMSRecipe(ItemStack[] craftingMatrix, InventoryCrafting inventoryCrafting, CraftWorld world) {
|
||||
for(int i = 0; i < craftingMatrix.length; ++i) {
|
||||
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(craftingMatrix[i]));
|
||||
private CraftingResult createItemCraftResult(ItemStack itemStack, InventoryCrafting inventoryCrafting, WorldServer worldServer) {
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
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);
|
||||
}
|
||||
|
||||
if (!itemstack2.isEmpty()) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
return server.getServer().getCraftingManager().craft(Recipes.CRAFTING, inventoryCrafting, world.getHandle());
|
||||
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
|
||||
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
|
||||
}
|
||||
|
||||
return craftItemResult;
|
||||
}
|
||||
}
|
||||
|
@ -3,63 +3,59 @@ package com.jamesdpeters.minecraft.chests.v1_16_R2;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingProvider;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingResult;
|
||||
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.IRecipe;
|
||||
import net.minecraft.server.v1_16_R2.InventoryCraftResult;
|
||||
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.RecipeRepair;
|
||||
import net.minecraft.server.v1_16_R2.Recipes;
|
||||
import net.minecraft.server.v1_16_R2.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
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.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.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(Player player, World world, ItemStack[] items) {
|
||||
public CraftingResult craft(World world, ItemStack[] items) {
|
||||
CraftWorld craftWorld = (CraftWorld) world;
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
ContainerWorkbench workbench = new ContainerWorkbench(-1, craftPlayer.getHandle().inventory);
|
||||
|
||||
CraftInventoryView view = workbench.getBukkitView();
|
||||
CraftInventoryCrafting craftInventoryCrafting = (CraftInventoryCrafting) view.getTopInventory();
|
||||
InventoryCrafting inventoryCrafting = (InventoryCrafting) craftInventoryCrafting.getMatrixInventory();
|
||||
InventoryCraftResult resultInventory = (InventoryCraftResult) craftInventoryCrafting.getResultInventory();
|
||||
// Setup crafting inventories.
|
||||
InventoryCrafting inventoryCrafting = new InventoryCrafting(new Container(null, -1) {
|
||||
@Override
|
||||
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()) {
|
||||
RecipeCrafting recipeCrafting = recipe.get();
|
||||
if (resultInventory.a(craftWorld.getHandle(), craftPlayer.getHandle(), recipeCrafting)) {
|
||||
itemstack = recipeCrafting.a(inventoryCrafting);
|
||||
}
|
||||
itemStack = recipe.get().a(inventoryCrafting);
|
||||
}
|
||||
|
||||
net.minecraft.server.v1_16_R2.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, resultInventory, itemstack, view, recipe.orElse(null) instanceof RecipeRepair);
|
||||
|
||||
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);
|
||||
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -90,12 +86,38 @@ public class Crafting implements CraftingProvider {
|
||||
return optional.map(IRecipe::toBukkitRecipe).orElse(null);
|
||||
}
|
||||
|
||||
private Optional<RecipeCrafting> getNMSRecipe(ItemStack[] craftingMatrix, InventoryCrafting inventoryCrafting, CraftWorld world) {
|
||||
for(int i = 0; i < craftingMatrix.length; ++i) {
|
||||
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(craftingMatrix[i]));
|
||||
private CraftingResult createItemCraftResult(ItemStack itemStack, InventoryCrafting inventoryCrafting, WorldServer worldServer) {
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
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);
|
||||
}
|
||||
|
||||
if (!itemstack2.isEmpty()) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
return server.getServer().getCraftingManager().craft(Recipes.CRAFTING, inventoryCrafting, world.getHandle());
|
||||
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
|
||||
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
|
||||
}
|
||||
|
||||
return craftItemResult;
|
||||
}
|
||||
}
|
||||
|
@ -3,63 +3,59 @@ package com.jamesdpeters.minecraft.chests.v1_16_R3;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingProvider;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingResult;
|
||||
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.IRecipe;
|
||||
import net.minecraft.server.v1_16_R3.InventoryCraftResult;
|
||||
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.RecipeRepair;
|
||||
import net.minecraft.server.v1_16_R3.Recipes;
|
||||
import net.minecraft.server.v1_16_R3.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
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.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.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(Player player, World world, ItemStack[] items) {
|
||||
public CraftingResult craft(World world, ItemStack[] items) {
|
||||
CraftWorld craftWorld = (CraftWorld) world;
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
ContainerWorkbench workbench = new ContainerWorkbench(-1, craftPlayer.getHandle().inventory);
|
||||
|
||||
CraftInventoryView view = workbench.getBukkitView();
|
||||
CraftInventoryCrafting craftInventoryCrafting = (CraftInventoryCrafting) view.getTopInventory();
|
||||
InventoryCrafting inventoryCrafting = (InventoryCrafting) craftInventoryCrafting.getMatrixInventory();
|
||||
InventoryCraftResult resultInventory = (InventoryCraftResult) craftInventoryCrafting.getResultInventory();
|
||||
// Setup crafting inventories.
|
||||
InventoryCrafting inventoryCrafting = new InventoryCrafting(new Container(null, -1) {
|
||||
@Override
|
||||
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()) {
|
||||
RecipeCrafting recipeCrafting = recipe.get();
|
||||
if (resultInventory.a(craftWorld.getHandle(), craftPlayer.getHandle(), recipeCrafting)) {
|
||||
itemstack = recipeCrafting.a(inventoryCrafting);
|
||||
}
|
||||
itemStack = recipe.get().a(inventoryCrafting);
|
||||
}
|
||||
|
||||
net.minecraft.server.v1_16_R3.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, resultInventory, itemstack, view, recipe.orElse(null) instanceof RecipeRepair);
|
||||
|
||||
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);
|
||||
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -98,4 +94,39 @@ public class Crafting implements CraftingProvider {
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
104
ChestsPlusPlus_1_17_R1/pom.xml
Normal file
104
ChestsPlusPlus_1_17_R1/pom.xml
Normal 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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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 org.bukkit.event.EventHandler;
|
@ -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.MaterialChecker;
|
@ -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.CraftingProvider;
|
105
ChestsPlusPlus_1_18_R1/pom.xml
Normal file
105
ChestsPlusPlus_1_18_R1/pom.xml
Normal 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>
|
@ -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;
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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>
|
@ -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);
|
||||
}
|
||||
}
|
@ -22,13 +22,13 @@
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>dmulloy2-repo</id>
|
||||
<url>http://repo.dmulloy2.net/nexus/repository/public/</url>
|
||||
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
@ -36,10 +36,10 @@
|
||||
<url>https://repo.codemc.org/repository/maven-public</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>sytm-nexus</id>
|
||||
<url>https://repo.sytm.de/repository/maven-hosted/</url>
|
||||
</repository>
|
||||
<!-- <repository>-->
|
||||
<!-- <id>sytm-nexus</id>-->
|
||||
<!-- <url>https://repo.sytm.de/repository/maven-hosted/</url>-->
|
||||
<!-- </repository>-->
|
||||
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
@ -101,7 +101,15 @@
|
||||
|
||||
<dependency>
|
||||
<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>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
@ -131,22 +139,6 @@
|
||||
<scope>compile</scope>
|
||||
</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>
|
||||
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
||||
<artifactId>ChestsPlusPlus-API</artifactId>
|
||||
|
@ -1,7 +1,11 @@
|
||||
package com.jamesdpeters.minecraft.chests.api;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.*;
|
||||
import com.jamesdpeters.minecraft.chests.latest.NMSProviderImpl;
|
||||
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.NMSProviderImpl;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
|
||||
public class NMSProviderDefault implements NMSProvider {
|
||||
|
@ -37,7 +37,7 @@ public class Crafting {
|
||||
}
|
||||
|
||||
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) {
|
||||
|
@ -106,7 +106,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(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++) {
|
||||
ItemStack item = matrix[i];
|
||||
if (item != null) {
|
||||
|
@ -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!
|
||||
# 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
|
||||
|
@ -41,7 +41,7 @@
|
||||
<dependency>
|
||||
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
||||
<artifactId>ChestsPlusPlus-Master</artifactId>
|
||||
<version>2.3.1-Release</version>
|
||||
<version>2.5.2-BETA-3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
5
pom.xml
5
pom.xml
@ -16,7 +16,8 @@
|
||||
|
||||
<modules>
|
||||
<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_R2</module>
|
||||
<module>ChestsPlusPlus_1_16</module>
|
||||
@ -25,7 +26,7 @@
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
Loading…
Reference in New Issue
Block a user