mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 10:12:53 +00:00
Reflective api additions
This commit is contained in:
parent
6e1c4f682e
commit
74172e3123
@ -0,0 +1,40 @@
|
|||||||
|
package com.volmit.iris.core.tools;
|
||||||
|
|
||||||
|
import com.volmit.iris.util.data.B;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.block.data.BlockData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class is used by an external IrisLib for other plugins to interact with Iris. Do not change
|
||||||
|
* existing methods or their parameters as it will break the library that uses these methods
|
||||||
|
* feel free to add more methods so long as you also add the reflective methods to the library
|
||||||
|
*/
|
||||||
|
public class IrisReflectiveAPI {
|
||||||
|
public static boolean isIrisWorld(World world) {
|
||||||
|
return IrisToolbelt.isIrisWorld(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isIrisStudioWorld(World world) {
|
||||||
|
return IrisToolbelt.isIrisStudioWorld(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerCustomBlockData(String namespace, String key, BlockData blockData) {
|
||||||
|
B.registerCustomBlockData(namespace, key, blockData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void retainMantleData(String classname) {
|
||||||
|
IrisToolbelt.retainMantleDataForSlice(classname);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setMantleData(World world, int x, int y, int z, Object data) {
|
||||||
|
IrisToolbelt.access(world).getEngine().getMantle().getMantle().set(x, y, z, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteMantleData(World world, int x, int y, int z, Class c) {
|
||||||
|
IrisToolbelt.access(world).getEngine().getMantle().getMantle().remove(x, y, z, c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getMantleData(World world, int x, int y, int z, Class c) {
|
||||||
|
return IrisToolbelt.access(world).getEngine().getMantle().getMantle().get(x, y, z, c);
|
||||||
|
}
|
||||||
|
}
|
@ -235,45 +235,4 @@ public class IrisToolbelt {
|
|||||||
if(e == null) {return;}
|
if(e == null) {return;}
|
||||||
e.getEngine().getMantle().getMantle().remove(x, y - world.getMinHeight(), z, of);
|
e.getEngine().getMantle().getMantle().remove(x, y - world.getMinHeight(), z, of);
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////// REFLECTIVE METHODS //////////////////////////
|
|
||||||
// Copy this stuff to your project, it's safe to use with a
|
|
||||||
// bukkit api only.
|
|
||||||
/////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
public static void setup() throws Throwable {
|
|
||||||
Method m = Class.forName("com.volmit.iris.core.tools.IrisToolbelt").getDeclaredMethod("retainMantleDataForSlice", String.class);
|
|
||||||
m.invoke(null, String.class.getCanonicalName());
|
|
||||||
m.invoke(null, BlockData.class.getCanonicalName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasMantleObject(World world, int x, int y, int z) {
|
|
||||||
return getMantleIdentity(world, x, y, z) != -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void deleteMantleBlock(World world, int x, int y, int z) {
|
|
||||||
try {
|
|
||||||
Method m = Class.forName("com.volmit.iris.core.tools.IrisToolbelt").getDeclaredMethod("deleteMantleData", World.class, int.class, int.class, int.class, Class.class);
|
|
||||||
m.invoke(null, world, x, y, z, BlockData.class);
|
|
||||||
m.invoke(null, world, x, y, z, String.class);
|
|
||||||
} catch(Throwable ignored) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BlockData getMantleBlock(World world, int x, int y, int z) {
|
|
||||||
try {
|
|
||||||
Method m = Class.forName("com.volmit.iris.core.tools.IrisToolbelt").getDeclaredMethod("getMantleData", World.class, int.class, int.class, int.class, Class.class);
|
|
||||||
BlockData s = (BlockData) m.invoke(null, world, x, y, z, BlockData.class);
|
|
||||||
if(s != null) {return s;}
|
|
||||||
} catch(Throwable ignored) {}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static int getMantleIdentity(World world, int x, int y, int z) {
|
|
||||||
try {
|
|
||||||
Method m = Class.forName("com.volmit.iris.core.tools.IrisToolbelt").getDeclaredMethod("getMantleData", World.class, int.class, int.class, int.class, Class.class);
|
|
||||||
String s = (String) m.invoke(null, world, x, y, z, String.class);
|
|
||||||
if(s != null) {return Integer.parseInt(s.split("\\Q@\\E")[1]);}
|
|
||||||
} catch(Throwable ignored) {}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import com.volmit.iris.Iris;
|
|||||||
import com.volmit.iris.core.IrisSettings;
|
import com.volmit.iris.core.IrisSettings;
|
||||||
import com.volmit.iris.core.service.RegistrySVC;
|
import com.volmit.iris.core.service.RegistrySVC;
|
||||||
import com.volmit.iris.util.collection.KList;
|
import com.volmit.iris.util.collection.KList;
|
||||||
|
import com.volmit.iris.util.collection.KMap;
|
||||||
import com.volmit.iris.util.scheduling.ChronoLatch;
|
import com.volmit.iris.util.scheduling.ChronoLatch;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
import it.unimi.dsi.fastutil.ints.Int2IntMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap;
|
||||||
@ -34,6 +35,7 @@ import org.bukkit.block.data.BlockData;
|
|||||||
import org.bukkit.block.data.Waterlogged;
|
import org.bukkit.block.data.Waterlogged;
|
||||||
import org.bukkit.block.data.type.Leaves;
|
import org.bukkit.block.data.type.Leaves;
|
||||||
import org.bukkit.block.data.type.PointedDripstone;
|
import org.bukkit.block.data.type.PointedDripstone;
|
||||||
|
import org.checkerframework.checker.units.qual.K;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -44,6 +46,8 @@ import java.util.stream.Collectors;
|
|||||||
import static org.bukkit.Material.*;
|
import static org.bukkit.Material.*;
|
||||||
|
|
||||||
public class B {
|
public class B {
|
||||||
|
private static final KMap<String, BlockData> custom = new KMap<>();
|
||||||
|
|
||||||
private static final Material AIR_MATERIAL = Material.AIR;
|
private static final Material AIR_MATERIAL = Material.AIR;
|
||||||
private static final BlockData AIR = AIR_MATERIAL.createBlockData();
|
private static final BlockData AIR = AIR_MATERIAL.createBlockData();
|
||||||
private static final IntSet foliageCache = buildFoliageCache();
|
private static final IntSet foliageCache = buildFoliageCache();
|
||||||
@ -405,6 +409,11 @@ public class B {
|
|||||||
try {
|
try {
|
||||||
String bd = bdxf.trim();
|
String bd = bdxf.trim();
|
||||||
|
|
||||||
|
if(!custom.isEmpty() && custom.containsKey(bd))
|
||||||
|
{
|
||||||
|
return custom.get(bd);
|
||||||
|
}
|
||||||
|
|
||||||
if(bd.startsWith("minecraft:cauldron[level=")) {
|
if(bd.startsWith("minecraft:cauldron[level=")) {
|
||||||
bd = bd.replaceAll("\\Q:cauldron[\\E", ":water_cauldron[");
|
bd = bd.replaceAll("\\Q:cauldron[\\E", ":water_cauldron[");
|
||||||
}
|
}
|
||||||
@ -660,6 +669,8 @@ public class B {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bt.addAll(custom.k());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
bt.addAll(Iris.service(RegistrySVC.class).getCustomBlockRegistry().compile());
|
bt.addAll(Iris.service(RegistrySVC.class).getCustomBlockRegistry().compile());
|
||||||
} catch(Throwable e) {
|
} catch(Throwable e) {
|
||||||
@ -683,4 +694,8 @@ public class B {
|
|||||||
public static boolean isWaterLogged(BlockData b) {
|
public static boolean isWaterLogged(BlockData b) {
|
||||||
return (b instanceof Waterlogged) && ((Waterlogged) b).isWaterlogged();
|
return (b instanceof Waterlogged) && ((Waterlogged) b).isWaterlogged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void registerCustomBlockData(String namespace, String key, BlockData blockData) {
|
||||||
|
custom.put(namespace + ":" + key, blockData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user