mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-19 15:09:18 +00:00
fix NexoDataProvider
This commit is contained in:
@@ -62,7 +62,7 @@ dependencies {
|
|||||||
|
|
||||||
// Third Party Integrations
|
// Third Party Integrations
|
||||||
compileOnly 'com.ticxo.playeranimator:PlayerAnimator:R1.2.7'
|
compileOnly 'com.ticxo.playeranimator:PlayerAnimator:R1.2.7'
|
||||||
compileOnly 'com.nexomc:nexo:0.1.0-dev.0'
|
compileOnly 'com.nexomc:nexo:0.6.0-dev.0'
|
||||||
compileOnly 'com.github.LoneDev6:api-itemsadder:3.4.1-r4'
|
compileOnly 'com.github.LoneDev6:api-itemsadder:3.4.1-r4'
|
||||||
compileOnly 'com.github.PlaceholderAPI:placeholderapi:2.11.3'
|
compileOnly 'com.github.PlaceholderAPI:placeholderapi:2.11.3'
|
||||||
compileOnly 'com.github.Ssomar-Developement:SCore:4.23.10.8'
|
compileOnly 'com.github.Ssomar-Developement:SCore:4.23.10.8'
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
package com.volmit.iris.core.link;
|
package com.volmit.iris.core.link;
|
||||||
|
|
||||||
|
import com.nexomc.nexo.api.NexoBlocks;
|
||||||
|
import com.nexomc.nexo.api.NexoFurniture;
|
||||||
|
import com.nexomc.nexo.api.NexoItems;
|
||||||
|
import com.nexomc.nexo.items.ItemBuilder;
|
||||||
import com.volmit.iris.Iris;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.core.nms.INMS;
|
import com.volmit.iris.core.nms.INMS;
|
||||||
import com.volmit.iris.core.nms.container.BiomeColor;
|
import com.volmit.iris.core.nms.container.BiomeColor;
|
||||||
|
import com.volmit.iris.core.nms.container.Pair;
|
||||||
import com.volmit.iris.core.service.ExternalDataSVC;
|
import com.volmit.iris.core.service.ExternalDataSVC;
|
||||||
import com.volmit.iris.engine.data.cache.Cache;
|
import com.volmit.iris.engine.data.cache.Cache;
|
||||||
import com.volmit.iris.engine.framework.Engine;
|
import com.volmit.iris.engine.framework.Engine;
|
||||||
@@ -25,19 +30,12 @@ import java.lang.reflect.Proxy;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.MissingResourceException;
|
import java.util.MissingResourceException;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collector;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class NexoDataProvider extends ExternalDataProvider {
|
public class NexoDataProvider extends ExternalDataProvider {
|
||||||
private final AtomicBoolean failed = new AtomicBoolean(false);
|
private final AtomicBoolean failed = new AtomicBoolean(false);
|
||||||
private WrappedReturningMethod<?, String[]> itemNames;
|
|
||||||
private WrappedReturningMethod<?, Object> itemFromId;
|
|
||||||
private WrappedReturningMethod<?, Boolean> exists;
|
|
||||||
|
|
||||||
private WrappedReturningMethod<?, Boolean> isCustomBlock;
|
|
||||||
private WrappedReturningMethod<?, Boolean> isFurniture;
|
|
||||||
|
|
||||||
private WrappedReturningMethod<?, BlockData> getBlockData;
|
|
||||||
private WrappedReturningMethod<?, ItemDisplay> placeFurniture;
|
|
||||||
private WrappedReturningMethod<?, ?> placeBlock;
|
|
||||||
|
|
||||||
public NexoDataProvider() {
|
public NexoDataProvider() {
|
||||||
super("Nexo");
|
super("Nexo");
|
||||||
@@ -45,38 +43,21 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
try {
|
|
||||||
Class<?> nexoItems = Class.forName("com.nexomc.nexo.api.NexoItems");
|
|
||||||
Class<?> nexoBlocks = Class.forName("com.nexomc.nexo.api.NexoBlocks");
|
|
||||||
Class<?> nexoFurniture = Class.forName("com.nexomc.nexo.api.NexoFurniture");
|
|
||||||
|
|
||||||
itemNames = new WrappedReturningMethod<>(nexoItems, "itemNames");
|
|
||||||
exists = new WrappedReturningMethod<>(nexoItems, "exists", String.class);
|
|
||||||
itemFromId = new WrappedReturningMethod<>(nexoItems, "itemFromId", String.class);
|
|
||||||
|
|
||||||
isCustomBlock = new WrappedReturningMethod<>(nexoBlocks, "isCustomBlock", String.class);
|
|
||||||
isFurniture = new WrappedReturningMethod<>(nexoFurniture, "isFurniture", String.class);
|
|
||||||
|
|
||||||
getBlockData = new WrappedReturningMethod<>(nexoBlocks, "blockData", String.class);
|
|
||||||
placeFurniture = new WrappedReturningMethod<>(nexoFurniture, "place", String.class, Location.class, float.class, BlockFace.class);
|
|
||||||
placeBlock = new WrappedReturningMethod<>(nexoBlocks, "place", String.class, Location.class);
|
|
||||||
} catch (Throwable e) {
|
|
||||||
failed.set(true);
|
|
||||||
Iris.error("Failed to initialize NexoDataProvider");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockData getBlockData(Identifier blockId, KMap<String, String> state) throws MissingResourceException {
|
public BlockData getBlockData(Identifier blockId, KMap<String, String> state) throws MissingResourceException {
|
||||||
if (!exists.invoke(blockId.key())) {
|
if (!NexoItems.exists(blockId.key())) {
|
||||||
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||||
}
|
}
|
||||||
|
|
||||||
Identifier blockState = ExternalDataSVC.buildState(blockId, state);
|
Identifier blockState = ExternalDataSVC.buildState(blockId, state);
|
||||||
if (isCustomBlock.invoke(blockId.key())) {
|
if (NexoBlocks.isCustomBlock(blockId.key())) {
|
||||||
return new IrisBlockData(getBlockData.invoke(blockId.key()), blockState);
|
BlockData data = NexoBlocks.blockData(blockId.key());
|
||||||
} else if (isFurniture.invoke(blockId.key())) {
|
if (data == null)
|
||||||
|
throw new MissingResourceException("Failed to find BlockData!", blockId.namespace(), blockId.key());
|
||||||
|
return new IrisBlockData(data, blockState);
|
||||||
|
} else if (NexoFurniture.isFurniture(blockId.key())) {
|
||||||
return new IrisBlockData(B.getAir(), blockState);
|
return new IrisBlockData(B.getAir(), blockState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,16 +66,11 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItemStack(Identifier itemId, KMap<String, Object> customNbt) throws MissingResourceException {
|
public ItemStack getItemStack(Identifier itemId, KMap<String, Object> customNbt) throws MissingResourceException {
|
||||||
Object o = itemFromId.invoke(itemId.key());
|
ItemBuilder builder = NexoItems.itemFromId(itemId.key());
|
||||||
if (o == null) {
|
if (builder == null) {
|
||||||
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
||||||
}
|
}
|
||||||
ItemBuilder builder = newProxy(o);
|
return builder.build();
|
||||||
ItemStack itemStack = builder.build();
|
|
||||||
if (itemStack == null) {
|
|
||||||
throw new MissingResourceException("Failed to find ItemData!", itemId.namespace(), itemId.key());
|
|
||||||
}
|
|
||||||
return itemStack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -103,12 +79,12 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
var state = pair.getB();
|
var state = pair.getB();
|
||||||
blockId = pair.getA();
|
blockId = pair.getA();
|
||||||
|
|
||||||
if (isCustomBlock.invoke(blockId.key())) {
|
if (NexoBlocks.isCustomBlock(blockId.key())) {
|
||||||
placeBlock.invoke(blockId.key(), block.getLocation());
|
NexoBlocks.place(blockId.key(), block.getLocation());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isFurniture.invoke(blockId.key()))
|
if (!NexoFurniture.isFurniture(blockId.key()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float yaw = 0;
|
float yaw = 0;
|
||||||
@@ -130,7 +106,7 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
if (face == BlockFace.SELF) {
|
if (face == BlockFace.SELF) {
|
||||||
face = BlockFace.NORTH;
|
face = BlockFace.NORTH;
|
||||||
}
|
}
|
||||||
ItemDisplay display = placeFurniture.invoke(blockId.key(), block.getLocation(), yaw, face);
|
ItemDisplay display = NexoFurniture.place(blockId.key(), block.getLocation(), yaw, face);
|
||||||
if (display == null) return;
|
if (display == null) return;
|
||||||
ItemStack itemStack = display.getItemStack();
|
ItemStack itemStack = display.getItemStack();
|
||||||
if (itemStack == null) return;
|
if (itemStack == null) return;
|
||||||
@@ -154,8 +130,7 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getBlockTypes() {
|
public Identifier[] getBlockTypes() {
|
||||||
return Arrays.stream(itemNames.invoke())
|
return Arrays.stream(NexoItems.itemNames())
|
||||||
.filter(i -> isCustomBlock.invoke(i) || isFurniture.invoke(i))
|
|
||||||
.map(i -> new Identifier("nexo", i))
|
.map(i -> new Identifier("nexo", i))
|
||||||
.filter(i -> {
|
.filter(i -> {
|
||||||
try {
|
try {
|
||||||
@@ -169,7 +144,7 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Identifier[] getItemTypes() {
|
public Identifier[] getItemTypes() {
|
||||||
return Arrays.stream(itemNames.invoke())
|
return Arrays.stream(NexoItems.itemNames())
|
||||||
.map(i -> new Identifier("nexo", i))
|
.map(i -> new Identifier("nexo", i))
|
||||||
.filter(i -> {
|
.filter(i -> {
|
||||||
try {
|
try {
|
||||||
@@ -190,15 +165,4 @@ public class NexoDataProvider extends ExternalDataProvider {
|
|||||||
public boolean isReady() {
|
public boolean isReady() {
|
||||||
return super.isReady() && !failed.get();
|
return super.isReady() && !failed.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ItemBuilder newProxy(Object instance) {
|
|
||||||
return (ItemBuilder) Proxy.newProxyInstance(
|
|
||||||
NexoDataProvider.class.getClassLoader(),
|
|
||||||
new Class[]{ItemBuilder.class},
|
|
||||||
(proxy, method, args) -> method.invoke(instance, args));
|
|
||||||
}
|
|
||||||
|
|
||||||
private interface ItemBuilder {
|
|
||||||
@Nullable ItemStack build();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user