diff --git a/ChestsPlusPlus_1_20_R2/pom.xml b/ChestsPlusPlus_1_20_R2/pom.xml new file mode 100644 index 0000000..5bb65c0 --- /dev/null +++ b/ChestsPlusPlus_1_20_R2/pom.xml @@ -0,0 +1,104 @@ + + + + ChestsPlusPlus-Parent + com.jamesdpeters.minecraft.chests + 1.0-SNAPSHOT + ../pom.xml + + + + 1.20.2 + + + 4.0.0 + jar + ChestsPlusPlus_1_20_R2 + 1.0-SNAPSHOT + + + + spigotmc-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + + + + com.jamesdpeters.minecraft.chests + ChestsPlusPlus-API + 1.0-SNAPSHOT + + + + org.spigotmc + spigot-api + ${minecraft.version}-R0.1-SNAPSHOT + provided + + + com.jamesdpeters.minecraft.chests + ChestsPlusPlus_1_17_R1 + 1.0-SNAPSHOT + compile + + + + org.spigotmc + spigot + ${minecraft.version}-R0.1-SNAPSHOT + remapped-mojang + provided + + + + + + + net.md-5 + specialsource-maven-plugin + 1.2.3 + + + package + + remap + + remap-obf + + org.spigotmc:minecraft-server:${minecraft.version}-R0.1-SNAPSHOT:txt:maps-mojang + true + org.spigotmc:spigot:${minecraft.version}-R0.1-SNAPSHOT:jar:remapped-mojang + true + remapped-obf + + + + package + + remap + + remap-spigot + + ${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar + org.spigotmc:minecraft-server:${minecraft.version}-R0.1-SNAPSHOT:csrg:maps-spigot + org.spigotmc:spigot:${minecraft.version}-R0.1-SNAPSHOT:jar:remapped-obf + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 16 + 16 + + + + + + + \ No newline at end of file diff --git a/ChestsPlusPlus_1_20_R2/src/main/java/com/jamesdpeters/minecraft/chests/v1_20_R2/Crafting.java b/ChestsPlusPlus_1_20_R2/src/main/java/com/jamesdpeters/minecraft/chests/v1_20_R2/Crafting.java new file mode 100644 index 0000000..cda943c --- /dev/null +++ b/ChestsPlusPlus_1_20_R2/src/main/java/com/jamesdpeters/minecraft/chests/v1_20_R2/Crafting.java @@ -0,0 +1,104 @@ +package com.jamesdpeters.minecraft.chests.v1_20_R2; + +import com.jamesdpeters.minecraft.chests.CraftingProvider; +import com.jamesdpeters.minecraft.chests.CraftingResult; +import net.minecraft.core.NonNullList; +import net.minecraft.core.RegistryAccess; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.CraftingContainer; +import net.minecraft.world.inventory.TransientCraftingContainer; +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_20_R2.CraftServer; +import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; +import org.bukkit.craftbukkit.v1_20_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; + +public class Crafting implements CraftingProvider { + + @Override + public CraftingResult craft(World world, ItemStack[] items) { + CraftWorld craftWorld = (CraftWorld) world; + + // Setup crafting inventories. + CraftingContainer inventoryCrafting = new TransientCraftingContainer(new AbstractContainerMenu(null, -1) { + @Override + public InventoryView getBukkitView() { + return null; + } + + @Override + public net.minecraft.world.item.ItemStack quickMoveStack(net.minecraft.world.entity.player.Player player, int i) { + 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().value().assemble(inventoryCrafting, RegistryAccess.EMPTY); + } + + 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 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.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; + } +} diff --git a/ChestsPlusPlus_1_20_R2/src/main/java/com/jamesdpeters/minecraft/chests/v1_20_R2/NMSProviderImpl.java b/ChestsPlusPlus_1_20_R2/src/main/java/com/jamesdpeters/minecraft/chests/v1_20_R2/NMSProviderImpl.java new file mode 100644 index 0000000..c5f5ae3 --- /dev/null +++ b/ChestsPlusPlus_1_20_R2/src/main/java/com/jamesdpeters/minecraft/chests/v1_20_R2/NMSProviderImpl.java @@ -0,0 +1,49 @@ +package com.jamesdpeters.minecraft.chests.v1_20_R2; + +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 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); + } + +} \ No newline at end of file diff --git a/ChestsPlusPlus_Main/pom.xml b/ChestsPlusPlus_Main/pom.xml index aaea41d..a1f9366 100644 --- a/ChestsPlusPlus_Main/pom.xml +++ b/ChestsPlusPlus_Main/pom.xml @@ -63,7 +63,7 @@ net.wesjd anvilgui - 1.6.6-SNAPSHOT + 1.9.0-SNAPSHOT @@ -149,7 +149,12 @@ 1.18.22 provided - + + com.jamesdpeters.minecraft.chests + ChestsPlusPlus_1_20_R2 + 1.0-SNAPSHOT + compile + diff --git a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api/NMSProviderDefault.java b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api/NMSProviderDefault.java index 0868702..6b7049a 100644 --- a/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api/NMSProviderDefault.java +++ b/ChestsPlusPlus_Main/src/main/java/com/jamesdpeters/minecraft/chests/api/NMSProviderDefault.java @@ -22,6 +22,8 @@ public class NMSProviderDefault implements NMSProvider { case "v1_18_R1" -> defaultProvider = new com.jamesdpeters.minecraft.chests.v1_18_R1.NMSProviderImpl(); case "v1_18_R2" -> defaultProvider = new com.jamesdpeters.minecraft.chests.v1_18_R2.NMSProviderImpl(); case "v1_19_R1" -> defaultProvider = new com.jamesdpeters.minecraft.chests.v1_19_R1.NMSProviderImpl(); + case "v1_20_R1" -> defaultProvider = new com.jamesdpeters.minecraft.chests.v1_20_R1.NMSProviderImpl(); + case "v1_20_R2" -> defaultProvider = new com.jamesdpeters.minecraft.chests.v1_20_R2.NMSProviderImpl(); default -> { ChestsPlusPlus.PLUGIN.getLogger().severe("§c======================================================="); ChestsPlusPlus.PLUGIN.getLogger().severe("§cThis version is not supported. Please update your server or the plugin!"); diff --git a/pom.xml b/pom.xml index 86a7461..96ad17f 100644 --- a/pom.xml +++ b/pom.xml @@ -16,6 +16,7 @@ ChestsPlusPlusAPI + ChestsPlusPlus_1_20_R2 ChestsPlusPlus_1_20_R1 ChestsPlusPlus_1_19_R3 ChestsPlusPlus_1_19_R2