|
@@ -3,11 +3,14 @@ package me.km.utils;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.Field;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.InvocationTargetException;
|
|
import java.lang.reflect.Method;
|
|
import java.lang.reflect.Method;
|
|
|
|
+import java.lang.reflect.Modifier;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.Random;
|
|
import java.util.Random;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.material.Material;
|
|
import net.minecraft.block.material.Material;
|
|
|
|
+import net.minecraft.client.resources.FoliageColorReloadListener;
|
|
|
|
+import net.minecraft.client.resources.GrassColorReloadListener;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.Entity;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
import net.minecraft.entity.item.EntityItem;
|
|
import net.minecraft.entity.item.EntityItem;
|
|
@@ -18,8 +21,11 @@ import net.minecraft.entity.projectile.EntityArrow;
|
|
import net.minecraft.server.management.PlayerList;
|
|
import net.minecraft.server.management.PlayerList;
|
|
import net.minecraft.util.DamageSource;
|
|
import net.minecraft.util.DamageSource;
|
|
import net.minecraft.util.FoodStats;
|
|
import net.minecraft.util.FoodStats;
|
|
|
|
+import net.minecraft.util.ResourceLocation;
|
|
import net.minecraft.world.Explosion;
|
|
import net.minecraft.world.Explosion;
|
|
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
|
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
|
|
|
+import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
+import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
|
|
public class ReflectionUtils
|
|
public class ReflectionUtils
|
|
{
|
|
{
|
|
@@ -53,6 +59,28 @@ public class ReflectionUtils
|
|
return null;
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private static Field getFinalStaticField(Class c, String... field)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ Field f = ReflectionHelper.findField(c, field);
|
|
|
|
+
|
|
|
|
+ Field modifiersField = Field.class.getDeclaredField("modifiers");
|
|
|
|
+ modifiersField.setAccessible(true);
|
|
|
|
+ modifiersField.setInt(f, f.getModifiers() & ~Modifier.FINAL);
|
|
|
|
+
|
|
|
|
+ return f;
|
|
|
|
+ }
|
|
|
|
+ catch(SecurityException | ReflectionHelper.UnableToFindFieldException |
|
|
|
|
+ IllegalArgumentException | IllegalAccessException | NoSuchFieldException ex)
|
|
|
|
+ {
|
|
|
|
+ System.out.println(String.join(", ", field) + " - " + ex);
|
|
|
|
+ }
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
private static <T> void setInt(T t, Field f, int i)
|
|
private static <T> void setInt(T t, Field f, int i)
|
|
{
|
|
{
|
|
try
|
|
try
|
|
@@ -129,6 +157,18 @@ public class ReflectionUtils
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private static void setFieldValue(Object o, Field f, Object value)
|
|
|
|
+ {
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ f.set(o, value);
|
|
|
|
+ }
|
|
|
|
+ catch(SecurityException | IllegalAccessException | IllegalArgumentException ex)
|
|
|
|
+ {
|
|
|
|
+ System.out.println(f + " - " + ex);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// -----------------------------------------------------------------------------------
|
|
// -----------------------------------------------------------------------------------
|
|
// villager stuff
|
|
// villager stuff
|
|
// -----------------------------------------------------------------------------------
|
|
// -----------------------------------------------------------------------------------
|
|
@@ -299,4 +339,26 @@ public class ReflectionUtils
|
|
{
|
|
{
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // -------------------------------------------------------------------------
|
|
|
|
+ // rendering stuff
|
|
|
|
+ // -------------------------------------------------------------------------
|
|
|
|
+
|
|
|
|
+ @SideOnly(Side.CLIENT)
|
|
|
|
+ private final static Field LOC_FOLIAGE_PNG = getFinalStaticField(FoliageColorReloadListener.class, "field_130079_a", "LOC_FOLIAGE_PNG");
|
|
|
|
+
|
|
|
|
+ @SideOnly(Side.CLIENT)
|
|
|
|
+ public static void setFoliage(ResourceLocation loc)
|
|
|
|
+ {
|
|
|
|
+ setFieldValue(null, LOC_FOLIAGE_PNG, loc);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @SideOnly(Side.CLIENT)
|
|
|
|
+ private final static Field LOC_GRASS_PNG = getFinalStaticField(GrassColorReloadListener.class, "field_130078_a", "LOC_GRASS_PNG");
|
|
|
|
+
|
|
|
|
+ @SideOnly(Side.CLIENT)
|
|
|
|
+ public static void setGrass(ResourceLocation loc)
|
|
|
|
+ {
|
|
|
|
+ setFieldValue(null, LOC_GRASS_PNG, loc);
|
|
|
|
+ }
|
|
}
|
|
}
|