mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2025-01-09 18:07:34 +01:00
1.16.4 support
This commit is contained in:
parent
6159e7bc35
commit
c58096bae6
54
ChestsPlusPlus_1_16_R3/pom.xml
Normal file
54
ChestsPlusPlus_1_16_R3/pom.xml
Normal file
@ -0,0 +1,54 @@
|
||||
<?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>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>ChestsPlusPlus_1_16_R3</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>1.16.4-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.bukkit</groupId>
|
||||
<artifactId>craftbukkit</artifactId>
|
||||
<version>1.16.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
@ -0,0 +1,86 @@
|
||||
package com.jamesdpeters.minecraft.chests.v1_16_R3;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.CraftingProvider;
|
||||
import net.minecraft.server.v1_16_R3.Container;
|
||||
import net.minecraft.server.v1_16_R3.EntityHuman;
|
||||
import net.minecraft.server.v1_16_R3.IRecipe;
|
||||
import net.minecraft.server.v1_16_R3.InventoryCrafting;
|
||||
import net.minecraft.server.v1_16_R3.RecipeCrafting;
|
||||
import net.minecraft.server.v1_16_R3.Recipes;
|
||||
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.inventory.CraftItemStack;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public ItemStack craft(World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityHuman) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
InventoryCrafting crafting = new InventoryCrafting(container, 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
CraftWorld craftWorld = (CraftWorld) world;
|
||||
Optional<RecipeCrafting> optional = server.getServer().getCraftingManager().craft(Recipes.CRAFTING, crafting, craftWorld.getHandle());
|
||||
|
||||
net.minecraft.server.v1_16_R3.ItemStack itemstack = net.minecraft.server.v1_16_R3.ItemStack.b;
|
||||
|
||||
if (optional.isPresent()) {
|
||||
RecipeCrafting recipeCrafting = optional.get();
|
||||
itemstack = recipeCrafting.a(crafting);
|
||||
}
|
||||
|
||||
return CraftItemStack.asBukkitCopy(itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityHuman) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
InventoryCrafting crafting = new InventoryCrafting(container, 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
if(i >= 9) break; // ItemList cant contain more than 9 items.
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
CraftWorld craftWorld = (CraftWorld) world;
|
||||
Optional<RecipeCrafting> optional = server.getServer().getCraftingManager().craft(Recipes.CRAFTING, crafting, craftWorld.getHandle());
|
||||
|
||||
return optional.map(IRecipe::toBukkitRecipe).orElse(null);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.jamesdpeters.minecraft.chests.v1_16_R3;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.MaterialChecker;
|
||||
import com.jamesdpeters.minecraft.chests.v1_16_R1.MaterialChecker_1_16;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Only a protocol change from 1.16.2 to 1.16.3 so no new materials were added.
|
||||
*/
|
||||
public class MaterialChecker_1_16_R3 extends MaterialChecker {
|
||||
|
||||
private MaterialChecker_1_16 version1_16;
|
||||
|
||||
public MaterialChecker_1_16_R3(){
|
||||
version1_16 = new MaterialChecker_1_16();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Material> graphically2DList() {
|
||||
return version1_16.graphically2DList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Material> ignoredMaterials() {
|
||||
return version1_16.ignoredMaterials();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTool(ItemStack itemStack) {
|
||||
return version1_16.isTool(itemStack);
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package com.jamesdpeters.minecraft.chests.v1_16_R3;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.ChestOpener;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingProvider;
|
||||
import com.jamesdpeters.minecraft.chests.MaterialChecker;
|
||||
import com.jamesdpeters.minecraft.chests.NMSProvider;
|
||||
import org.bukkit.block.Lidded;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
|
||||
public class NMSProviderImpl implements NMSProvider {
|
||||
|
||||
@Override
|
||||
public ChestOpener getChestOpener() {
|
||||
return (inventory, container, tileEntityOpener) -> {
|
||||
if(hasLiddedAPI()){
|
||||
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_16_R3();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftingProvider getCraftingProvider() {
|
||||
return new Crafting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
|
||||
itemFrame.setVisible(visible);
|
||||
}
|
||||
|
||||
private boolean hasLiddedAPI(){
|
||||
try {
|
||||
Class.forName("org.bukkit.block.Lidded");
|
||||
return true;
|
||||
} catch (ClassNotFoundException e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -92,6 +92,14 @@
|
||||
<version>1.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
||||
<artifactId>ChestsPlusPlus_1_16_R3</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
||||
<artifactId>ChestsPlusPlus_1_16_R2</artifactId>
|
||||
|
Loading…
Reference in New Issue
Block a user