mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-29 20:19:06 +00:00
f
This commit is contained in:
@@ -64,6 +64,29 @@ public abstract class IrisPostBlockFilter implements IPostBlockAccess
|
||||
return d.getMaterial().equals(Material.AIR) || d.getMaterial().equals(Material.CAVE_AIR);
|
||||
}
|
||||
|
||||
public boolean hasGravity(int x, int y, int z)
|
||||
{
|
||||
BlockData d = getPostBlock(x, y, z);
|
||||
return d.getMaterial().equals(Material.SAND)
|
||||
|| d.getMaterial().equals(Material.RED_SAND)
|
||||
|| d.getMaterial().equals(Material.BLACK_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.BLUE_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.BROWN_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.CYAN_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.GRAY_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.GREEN_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.LIGHT_BLUE_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.LIGHT_GRAY_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.LIME_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.MAGENTA_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.ORANGE_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.PINK_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.PURPLE_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.RED_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.WHITE_CONCRETE_POWDER)
|
||||
|| d.getMaterial().equals(Material.YELLOW_CONCRETE_POWDER);
|
||||
}
|
||||
|
||||
public boolean isSolid(int x, int y, int z)
|
||||
{
|
||||
BlockData d = getPostBlock(x, y, z);
|
||||
@@ -82,6 +105,12 @@ public abstract class IrisPostBlockFilter implements IPostBlockAccess
|
||||
return d instanceof Slab;
|
||||
}
|
||||
|
||||
public boolean isSnowLayer(int x, int y, int z)
|
||||
{
|
||||
BlockData d = getPostBlock(x, y, z);
|
||||
return d.getMaterial().equals(Material.SNOW);
|
||||
}
|
||||
|
||||
public boolean isWater(int x, int y, int z)
|
||||
{
|
||||
BlockData d = getPostBlock(x, y, z);
|
||||
|
||||
@@ -91,6 +91,7 @@ public class KList<T> extends ArrayList<T> implements List<T>
|
||||
* the function
|
||||
* @return the new map
|
||||
*/
|
||||
@SuppressWarnings("hiding")
|
||||
public <V> KMap<T, V> asKeys(Function<T, V> f)
|
||||
{
|
||||
KMap<T, V> m = new KMap<T, V>();
|
||||
@@ -274,6 +275,7 @@ public class KList<T> extends ArrayList<T> implements List<T>
|
||||
* the converter that converts the forign type into this list type
|
||||
* @return this list (builder)
|
||||
*/
|
||||
@SuppressWarnings("hiding")
|
||||
public <V> KList<T> addFrom(List<V> v, Function<V, T> converter)
|
||||
{
|
||||
v.forEach((g) -> add(converter.apply(g)));
|
||||
@@ -288,6 +290,7 @@ public class KList<T> extends ArrayList<T> implements List<T>
|
||||
* @param converter
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("hiding")
|
||||
public <V> KList<V> convert(Function<T, V> converter)
|
||||
{
|
||||
KList<V> v = new KList<V>();
|
||||
@@ -663,4 +666,13 @@ public class KList<T> extends ArrayList<T> implements List<T>
|
||||
add(t);
|
||||
return this;
|
||||
}
|
||||
|
||||
public KList<T> removeDuplicates()
|
||||
{
|
||||
KSet<T> v = new KSet<>();
|
||||
v.addAll(this);
|
||||
KList<T> m = new KList<>();
|
||||
m.addAll(v);
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.Enumeration;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@SuppressWarnings("hiding")
|
||||
public class KMap<K, V> extends ConcurrentHashMap<K, V>
|
||||
{
|
||||
private static final long serialVersionUID = 7288942695300448163L;
|
||||
|
||||
@@ -7,6 +7,7 @@ package com.volmit.iris.util;
|
||||
* @param <K> the key type
|
||||
* @param <V> the value type
|
||||
*/
|
||||
@SuppressWarnings("hiding")
|
||||
public class KeyPair<K, V>
|
||||
{
|
||||
private K k;
|
||||
|
||||
@@ -16,6 +16,7 @@ public class M
|
||||
private static final int precision = 128;
|
||||
private static final int modulus = 360 * precision;
|
||||
private static final float[] sin = new float[modulus];
|
||||
public static int tick = 0;
|
||||
|
||||
/**
|
||||
* Scales B by an external range change so that <br/>
|
||||
@@ -440,4 +441,9 @@ public class M
|
||||
return a >= 0 ? sin[a % (modulus)] : -sin[-a % (modulus)];
|
||||
}
|
||||
|
||||
public static boolean interval(int tickInterval)
|
||||
{
|
||||
return tick % (tickInterval <= 0 ? 1 : tickInterval) == 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public class ResourceLoader<T extends IrisRegistrant>
|
||||
Iris.hotloader.track(j);
|
||||
Iris.info("Loading " + resourceTypeName + ": " + j.getPath());
|
||||
t.setLoadKey(name);
|
||||
t.setLoadFile(j);
|
||||
lock.unlock();
|
||||
return t;
|
||||
}
|
||||
|
||||
150
src/main/java/com/volmit/iris/util/V.java
Normal file
150
src/main/java/com/volmit/iris/util/V.java
Normal file
@@ -0,0 +1,150 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
public class V
|
||||
{
|
||||
private Object o;
|
||||
private boolean local;
|
||||
private boolean suppress = false;
|
||||
|
||||
public V(Class<?> c, Object... parameters)
|
||||
{
|
||||
this.o = Violator.construct(c, parameters);
|
||||
this.local = true;
|
||||
}
|
||||
|
||||
public V(Object o)
|
||||
{
|
||||
this.o = o;
|
||||
this.local = true;
|
||||
}
|
||||
|
||||
public V(Object o, boolean local, boolean suppress)
|
||||
{
|
||||
this(o);
|
||||
this.local = local;
|
||||
this.suppress = suppress;
|
||||
}
|
||||
|
||||
public V(Object o, boolean local)
|
||||
{
|
||||
this(o);
|
||||
this.local = local;
|
||||
}
|
||||
|
||||
public <T extends Annotation> T get(Class<? extends T> t)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (T) (local ? Violator.getDeclaredAnnotation(o.getClass(), t) : Violator.getAnnotation(o.getClass(), t));
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
if(!suppress)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T extends Annotation> T get(Class<? extends T> t, String mn, Class<?>... pars)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (T) (local ? Violator.getDeclaredAnnotation(Violator.getDeclaredMethod(o.getClass(), mn, pars), t) : Violator.getAnnotation(Violator.getMethod(o.getClass(), mn, pars), t));
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
if(!suppress)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public <T extends Annotation> T get(Class<? extends T> t, String mn)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (T) (local ? Violator.getDeclaredAnnotation(Violator.getDeclaredField(o.getClass(), mn), t) : Violator.getAnnotation(Violator.getField(o.getClass(), mn), t));
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
if(!suppress)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T get(String field)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (T) (local ? Violator.getDeclaredField(o.getClass(), field) : Violator.getField(o.getClass(), field)).get(o);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
if(!suppress)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object invoke(String method, Object... parameters)
|
||||
{
|
||||
KList<Class<?>> par = new KList<Class<?>>();
|
||||
|
||||
for(Object i : parameters)
|
||||
{
|
||||
par.add(i.getClass());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return (local ? Violator.getDeclaredMethod(o.getClass(), method, par.toArray(new Class<?>[par.size()])) : Violator.getMethod(o.getClass(), method, par.toArray(new Class<?>[par.size()]))).invoke(o, parameters);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
if(!suppress)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void set(String field, Object value)
|
||||
{
|
||||
try
|
||||
{
|
||||
// https://github.com/VolmitSoftware/Mortar/issues/5
|
||||
(local ? Violator.getDeclaredField(o.getClass(), field) : Violator.getField(o.getClass(), field)).set(o, value);
|
||||
}
|
||||
|
||||
catch(Throwable e)
|
||||
{
|
||||
if(!suppress)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
302
src/main/java/com/volmit/iris/util/Violator.java
Normal file
302
src/main/java/com/volmit/iris/util/Violator.java
Normal file
@@ -0,0 +1,302 @@
|
||||
package com.volmit.iris.util;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
|
||||
public class Violator
|
||||
{
|
||||
protected static ConcurrentSkipListMap<String, Object> nodes = new ConcurrentSkipListMap<String, Object>();
|
||||
|
||||
private static String id(Object o, Object h)
|
||||
{
|
||||
if(o instanceof Field)
|
||||
{
|
||||
return id(((Field) o).getDeclaringClass(), null) + "." + ((Field) o).getName();
|
||||
}
|
||||
|
||||
if(o instanceof String)
|
||||
{
|
||||
return (String) o;
|
||||
}
|
||||
|
||||
if(o instanceof Class<?>)
|
||||
{
|
||||
return ((Class<?>) o).getCanonicalName();
|
||||
}
|
||||
|
||||
if(o instanceof Constructor<?>)
|
||||
{
|
||||
Constructor<?> co = (Constructor<?>) o;
|
||||
|
||||
String mx = "";
|
||||
|
||||
for(Class<?> i : co.getParameterTypes())
|
||||
{
|
||||
mx += "," + i.getCanonicalName();
|
||||
}
|
||||
|
||||
mx = mx.length() >= 1 ? mx.substring(1) : mx;
|
||||
|
||||
return id(co.getDeclaringClass(), null) + "(" + mx + ")";
|
||||
}
|
||||
|
||||
if(o instanceof Method)
|
||||
{
|
||||
String mx = "";
|
||||
|
||||
for(Class<?> i : ((Method) o).getParameterTypes())
|
||||
{
|
||||
mx += "," + i.getCanonicalName();
|
||||
}
|
||||
|
||||
mx = mx.length() >= 1 ? mx.substring(1) : mx;
|
||||
|
||||
return id(((Method) o).getDeclaringClass(), null) + "." + ((Method) o).getName() + "(" + mx + ")";
|
||||
}
|
||||
|
||||
if(o instanceof Annotation)
|
||||
{
|
||||
Annotation a = (Annotation) o;
|
||||
return "@" + a.annotationType().getCanonicalName() + "[" + id(h, null) + "]";
|
||||
}
|
||||
|
||||
return o.hashCode() + o.toString();
|
||||
}
|
||||
|
||||
private static void p(String n, Object o)
|
||||
{
|
||||
nodes.put(n, o);
|
||||
}
|
||||
|
||||
private static boolean h(String n)
|
||||
{
|
||||
return nodes.containsKey(n);
|
||||
}
|
||||
|
||||
private static Object g(String n)
|
||||
{
|
||||
return nodes.get(n);
|
||||
}
|
||||
|
||||
public static Constructor<?> getConstructor(Class<?> c, Class<?>... params) throws NoSuchMethodException, SecurityException
|
||||
{
|
||||
String mx = "";
|
||||
|
||||
for(Class<?> i : params)
|
||||
{
|
||||
mx += "," + i.getCanonicalName();
|
||||
}
|
||||
|
||||
mx = mx.length() >= 1 ? mx.substring(1) : mx;
|
||||
|
||||
if(!h(id(c, null) + "(" + mx + ")"))
|
||||
{
|
||||
Constructor<?> co = c.getConstructor(params);
|
||||
co.setAccessible(true);
|
||||
p(id(co, null), co);
|
||||
}
|
||||
|
||||
return (Constructor<?>) g(id(c, null) + "(" + mx + ")");
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Field getField(Class<?> c, String name) throws Throwable
|
||||
{
|
||||
if(!h(id(c, null) + "." + name))
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = c.getField(name);
|
||||
f.setAccessible(true);
|
||||
p(id(c, null) + "." + name, f);
|
||||
}
|
||||
catch(NoSuchFieldException e)
|
||||
{
|
||||
Class s = c.getSuperclass();
|
||||
if(null == s)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
Field f = s.getField(name);
|
||||
f.setAccessible(true);
|
||||
p(id(c, null) + "." + name, f);
|
||||
}
|
||||
}
|
||||
|
||||
return (Field) g(id(c, null) + "." + name);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static Field getDeclaredField(Class<?> c, String name) throws Throwable
|
||||
{
|
||||
if(!h(id(c, null) + "." + name))
|
||||
{
|
||||
try
|
||||
{
|
||||
Field f = c.getDeclaredField(name);
|
||||
f.setAccessible(true);
|
||||
p(id(c, null) + "." + name, f);
|
||||
}
|
||||
catch(NoSuchFieldException e)
|
||||
{
|
||||
Class s = c.getSuperclass();
|
||||
if(null == s)
|
||||
{
|
||||
throw e;
|
||||
}
|
||||
Field f = s.getDeclaredField(name);
|
||||
f.setAccessible(true);
|
||||
p(id(c, null) + "." + name, f);
|
||||
}
|
||||
}
|
||||
|
||||
return (Field) g(id(c, null) + "." + name);
|
||||
}
|
||||
|
||||
public static Method getMethod(Class<?> c, String name, Class<?>... pars) throws Throwable
|
||||
{
|
||||
String iv = "";
|
||||
String mx = "";
|
||||
|
||||
for(Class<?> i : pars)
|
||||
{
|
||||
mx += "," + i.getCanonicalName();
|
||||
}
|
||||
|
||||
mx = mx.length() >= 1 ? mx.substring(1) : mx;
|
||||
iv = id(c, null) + "." + name + "(" + mx + ")";
|
||||
|
||||
if(!h(iv))
|
||||
{
|
||||
Method f = c.getMethod(name, pars);
|
||||
f.setAccessible(true);
|
||||
p(iv, f);
|
||||
}
|
||||
|
||||
return (Method) g(iv);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T construct(Class<?> c, Object... parameters)
|
||||
{
|
||||
KList<Class<?>> cv = new KList<Class<?>>();
|
||||
|
||||
for(Object i : parameters)
|
||||
{
|
||||
cv.add(i.getClass());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Constructor<?> co = getConstructor(c, cv.toArray(new Class<?>[cv.size()]));
|
||||
return (T) co.newInstance(parameters);
|
||||
}
|
||||
|
||||
catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Method getDeclaredMethod(Class<?> c, String name, Class<?>... pars) throws Throwable
|
||||
{
|
||||
String iv = "";
|
||||
String mx = "";
|
||||
|
||||
for(Class<?> i : pars)
|
||||
{
|
||||
mx += "," + i.getCanonicalName();
|
||||
}
|
||||
|
||||
mx = mx.length() >= 1 ? mx.substring(1) : mx;
|
||||
iv = id(c, null) + "." + name + "(" + mx + ")";
|
||||
|
||||
if(!h(iv))
|
||||
{
|
||||
Method f = c.getDeclaredMethod(name, pars);
|
||||
f.setAccessible(true);
|
||||
p(iv, f);
|
||||
}
|
||||
|
||||
return (Method) g(iv);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Annotation> T getAnnotation(Class<?> c, Class<? extends T> a) throws Throwable
|
||||
{
|
||||
if(!h("@" + a.getCanonicalName() + "[" + c.getCanonicalName() + "]"))
|
||||
{
|
||||
T f = c.getAnnotation(a);
|
||||
p(id(f, c), f);
|
||||
}
|
||||
|
||||
return (T) g("@" + a.getCanonicalName() + "[" + c.getCanonicalName() + "]");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Annotation> T getDeclaredAnnotation(Class<?> c, Class<? extends T> a) throws Throwable
|
||||
{
|
||||
if(!h("@" + a.getCanonicalName() + "[" + c.getCanonicalName() + "]"))
|
||||
{
|
||||
T f = c.getDeclaredAnnotation(a);
|
||||
p(id(f, c), f);
|
||||
}
|
||||
|
||||
return (T) g("@" + a.getCanonicalName() + "[" + c.getCanonicalName() + "]");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Annotation> T getAnnotation(Field c, Class<? extends T> a) throws Throwable
|
||||
{
|
||||
if(!h("@" + a.getCanonicalName() + "[" + id(c, null) + "]"))
|
||||
{
|
||||
T f = c.getAnnotation(a);
|
||||
p(id(f, c), f);
|
||||
}
|
||||
|
||||
return (T) g("@" + a.getCanonicalName() + "[" + id(c, null) + "]");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Annotation> T getDeclaredAnnotation(Field c, Class<? extends T> a) throws Throwable
|
||||
{
|
||||
if(!h("@" + a.getCanonicalName() + "[" + id(c, null) + "]"))
|
||||
{
|
||||
T f = c.getDeclaredAnnotation(a);
|
||||
p(id(f, c), f);
|
||||
}
|
||||
|
||||
return (T) g("@" + a.getCanonicalName() + "[" + id(c, null) + "]");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Annotation> T getAnnotation(Method c, Class<? extends T> a) throws Throwable
|
||||
{
|
||||
if(!h("@" + a.getCanonicalName() + "[" + id(c, null) + "]"))
|
||||
{
|
||||
T f = c.getAnnotation(a);
|
||||
p(id(f, c), f);
|
||||
}
|
||||
|
||||
return (T) g("@" + a.getCanonicalName() + "[" + id(c, null) + "]");
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T extends Annotation> T getDeclaredAnnotation(Method c, Class<? extends T> a) throws Throwable
|
||||
{
|
||||
if(!h("@" + a.getCanonicalName() + "[" + id(c, null) + "]"))
|
||||
{
|
||||
T f = c.getDeclaredAnnotation(a);
|
||||
p(id(f, c), f);
|
||||
|
||||
System.out.println("Set as " + id(f, c) + " as " + ("@" + a.getCanonicalName() + "[" + id(c, null) + "]"));
|
||||
}
|
||||
|
||||
return (T) g("@" + a.getCanonicalName() + "[" + id(c, null) + "]");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user