Fix some methodhandles

This commit is contained in:
Vincent Lee committed 2016-03-24 13:01:07 -05:00
1 parent 674ba5c19d
commit ab618923df
4 files changed
+55 -38

No files matched your search

@@ -814,19 +814,19 @@ public final class ModelHandler {
ModelLoader.setCustomModelResourceLocation(item, color.getMetadata(), new ModelResourceLocation(name, "inventory_" + color.getName()));
}
// item = Item.getItemFromBlock(ModBlocks.doubleFlower1);
// for (EnumDyeColor color : BotaniaStateProps.DOUBLEFLOWER_VARIANT_1.getAllowedValues()) {
// String name = GameData.getBlockRegistry().getNameForObject(ModBlocks.doubleFlower1).toString();
// String variant = "inventory_" + color.getName();
// ModelLoader.setCustomModelResourceLocation(item, color.getMetadata(), new ModelResourceLocation(name, variant));
// }
//
// item = Item.getItemFromBlock(ModBlocks.doubleFlower2);
// for (EnumDyeColor color : BotaniaStateProps.DOUBLEFLOWER_VARIANT_2.getAllowedValues()) {
// String name = GameData.getBlockRegistry().getNameForObject(ModBlocks.doubleFlower2).toString();
// String variant = "inventory_" + color.getName();
// ModelLoader.setCustomModelResourceLocation(item, color.getMetadata() - 8, new ModelResourceLocation(name, variant));
// }
item = Item.getItemFromBlock(ModBlocks.doubleFlower1);
for (EnumDyeColor color : BotaniaStateProps.DOUBLEFLOWER_VARIANT_1.getAllowedValues()) {
String name = GameData.getBlockRegistry().getNameForObject(ModBlocks.doubleFlower1).toString();
String variant = "inventory_" + color.getName();
ModelLoader.setCustomModelResourceLocation(item, color.getMetadata(), new ModelResourceLocation(name, variant));
}
item = Item.getItemFromBlock(ModBlocks.doubleFlower2);
for (EnumDyeColor color : BotaniaStateProps.DOUBLEFLOWER_VARIANT_2.getAllowedValues()) {
String name = GameData.getBlockRegistry().getNameForObject(ModBlocks.doubleFlower2).toString();
String variant = "inventory_" + color.getName();
ModelLoader.setCustomModelResourceLocation(item, color.getMetadata() - 8, new ModelResourceLocation(name, variant));
}
}
private static void registerPavement() {
@@ -16,12 +16,16 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLiving;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.MobSpawnerBaseLogic;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityMobSpawner;
import net.minecraft.util.WeightedSpawnerEntity;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.WeightedRandom;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.storage.AnvilChunkLoader;
import vazkii.botania.api.mana.IManaReceiver;
import vazkii.botania.common.Botania;
import vazkii.botania.common.core.handler.MethodHandles;
@@ -72,32 +76,47 @@ public class TileSpawnerClaw extends TileMod implements IManaReceiver {
int spawnCount = ((int) MethodHandles.spawnCount_getter.invokeExact(logic));
int spawnRange = ((int) MethodHandles.spawnRange_getter.invokeExact(logic));
int maxNearbyEntities = ((int) MethodHandles.maxNearbyEntities_getter.invokeExact(logic));
WeightedSpawnerEntity randomEntity = ((WeightedSpawnerEntity) MethodHandles.randomEntity_getter.invokeExact(logic));
BlockPos blockpos = logic.getSpawnerPosition();
for(int i = 0; i < spawnCount; ++i) {
Entity entity = EntityList.createEntityByName(((String) MethodHandles.getEntityNameToSpawn.invokeExact(logic)), logic.getSpawnerWorld());
NBTTagCompound nbttagcompound = randomEntity.getNbt();
NBTTagList nbttaglist = nbttagcompound.getTagList("Pos", 6);
World world = logic.getSpawnerWorld();
int j = nbttaglist.tagCount();
double d0 = j >= 1 ? nbttaglist.getDoubleAt(0) : (double)blockpos.getX() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double)spawnRange + 0.5D;
double d1 = j >= 2 ? nbttaglist.getDoubleAt(1) : (double)(blockpos.getY() + world.rand.nextInt(3) - 1);
double d2 = j >= 3 ? nbttaglist.getDoubleAt(2) : (double)blockpos.getZ() + (world.rand.nextDouble() - world.rand.nextDouble()) * (double)spawnRange + 0.5D;
Entity entity = AnvilChunkLoader.readWorldEntityPos(nbttagcompound, world, d0, d1, d2, false);
if (entity == null)
return;
int j = logic.getSpawnerWorld().getEntitiesWithinAABB(entity.getClass(), new AxisAlignedBB(logic.getSpawnerPosition(), logic.getSpawnerPosition().add(1, 1, 1)).expand(spawnRange * 2, 4.0D, spawnRange * 2)).size();
if (j >= maxNearbyEntities) {
resetTimer(logic);
{
return;
}
int k = world.getEntitiesWithinAABB(entity.getClass(), (new AxisAlignedBB((double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ(), (double)(blockpos.getX() + 1), (double)(blockpos.getY() + 1), (double)(blockpos.getZ() + 1))).expandXyz((double)spawnRange)).size();
if (k >= maxNearbyEntities)
{
this.resetTimer(logic);
return;
}
double d2 = logic.getSpawnerPosition().getX() + (logic.getSpawnerWorld().rand.nextDouble() - logic.getSpawnerWorld().rand.nextDouble()) * spawnRange;
double d3 = logic.getSpawnerPosition().getY() + logic.getSpawnerWorld().rand.nextInt(3) - 1;
double d4 = logic.getSpawnerPosition().getZ() + (logic.getSpawnerWorld().rand.nextDouble() - logic.getSpawnerWorld().rand.nextDouble()) * spawnRange;
EntityLiving entityliving = entity instanceof EntityLiving ? (EntityLiving)entity : null;
entity.setLocationAndAngles(d2, d3, d4, logic.getSpawnerWorld().rand.nextFloat() * 360.0F, 0.0F);
entity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, world.rand.nextFloat() * 360.0F, 0.0F);
if(entityliving == null || entityliving.getCanSpawnHere()) {
// Must accept return value so methodhandle dynamically binds correctly
Entity e = ((Entity) MethodHandles.spawnNewEntity.invokeExact(logic, entity, true));
this.getWorld().playAuxSFX(2004, logic.getSpawnerPosition(), 0);
if (entityliving == null || entityliving.getCanSpawnHere())
{
if (randomEntity.getNbt().getSize() == 1 && randomEntity.getNbt().hasKey("id", 8) && entity instanceof EntityLiving)
{
((EntityLiving)entity).onInitialSpawn(world.getDifficultyForLocation(new BlockPos(entity)), null);
}
if(entityliving != null) {
AnvilChunkLoader.spawnEntity(entity, world);
world.playAuxSFX(2004, blockpos, 0);
if (entityliving != null)
{
entityliving.spawnExplosionParticle();
}
@@ -23,7 +23,7 @@ public final class MethodHandles {
spawnRange_getter, spawnCount_getter, maxNearbyEntities_getter,
maxSpawnDelay_getter, minSpawnDelay_getter,
spawnDelay_getter, spawnDelay_setter, prevMobRotation_setter, mobRotation_setter, potentialSpawns_getter,
getEntityNameToSpawn, isActivated, spawnNewEntity; // MobSpawnerBaseLogic
randomEntity_getter, isActivated; // MobSpawnerBaseLogic
static {
try {
@@ -76,19 +76,16 @@ public final class MethodHandles {
f.setAccessible(true);
potentialSpawns_getter = publicLookup().unreflectGetter(f);
f = ReflectionHelper.findField(MobSpawnerBaseLogic.class, LibObfuscation.RANDOM_ENTITY);
f.setAccessible(true);
randomEntity_getter = publicLookup().unreflectGetter(f);
Method m = ReflectionHelper.findMethod(MobSpawnerBaseLogic.class, null, LibObfuscation.IS_ACTIVATED);
m.setAccessible(true);
isActivated = publicLookup().unreflect(m);
m = ReflectionHelper.findMethod(MobSpawnerBaseLogic.class, null, LibObfuscation.SPAWN_NEW_ENTITY, Entity.class, boolean.class);
m.setAccessible(true);
spawnNewEntity = publicLookup().unreflect(m);
m = ReflectionHelper.findMethod(MobSpawnerBaseLogic.class, null, LibObfuscation.GET_ENTITY_TO_SPAWN);
m.setAccessible(true);
getEntityNameToSpawn = publicLookup().unreflect(m);
} catch (Throwable t) {
FMLLog.severe("[Botania]: Couldn't initialize methodhandles! Things will be broken!");
t.printStackTrace();
throw Throwables.propagate(t);
}
}
@@ -70,6 +70,7 @@ public final class LibObfuscation {
public static final String[] PREV_MOB_ROTATION = new String[] { "prevMobRotation", "field_98284_d", "e" };
public static final String[] MOB_ROTATION = new String[] { "mobRotation", "field_98287_c", "d" };
public static final String[] GET_ENTITY_TO_SPAWN = new String[] { "getEntityNameToSpawn", "func_98276_e", "g" };
public static final String[] RANDOM_ENTITY = new String[] { "randomEntity", "field_98282_f", "c" };
public static final String[] SPAWN_NEW_ENTITY = new String[] { "spawnNewEntity", "func_180613_a", "a" }; // todo 1.9
// GuiIngame