混淆的 Minecraft 构建中的奇怪床错误,不存在于开发环境中

Odd Bed Error in obfuscated Minecraft build, not present in Development Environment

所以,我有一个 class 我正在使用它来改进床的功能(如果暴民看不到它们或无法到达它们,玩家可以睡在上面),并且在开发环境中,它可以工作完美,完全符合预期。然而,当我编译它并将其放入一个混淆的游戏中时,我 运行 陷入了一个重大错误。玩家上床睡觉,然后就无法再出来了。我认为这可能是由于在混淆环境中使用反射获取字段和方法时出错,但是我已经创建了理论上应该处理该问题的函数。任何有关此错误原因的意见都将不胜感激。

package com.reimaginedgaming.blur.jwin.events;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

import net.minecraft.entity.Entity;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChunkCoordinates;
import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent;
import cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class BedSleepingFix {
private static Field sleeping;
private static Field sleeptimer;
private static Method setsize;
private static Method func_71013_b;
public static void setupFields() {
    Class bed = EntityPlayer.class;
    Class entity = Entity.class;
    try {
        sleeping = getField("sleeping",bed);
    }
    catch(Exception e){
        System.out.println("Ran into error:\n"+e.getLocalizedMessage()+"\n between lines 34 and 37.");
    }
    try {
        sleeptimer = getField("sleepTimer",bed);
    }
    catch(Exception e){
        System.out.println("Ran into error:\n"+e.getLocalizedMessage()+"\n between lines 34 and 37.");
    }
    try {
        setsize = getMethod("setSize",entity, float.class, float.class);
    }
    catch(Exception e){
        System.out.println("Ran into error:\n"+e.getLocalizedMessage()+"\n between lines 34 and 37.");
    }
    try {
        func_71013_b = getMethod("func_71013_b",bed, int.class);
    } catch (Exception e) {
        System.out.println("Ran into error:\n"+e.getLocalizedMessage()+"between lines 23 and 29.");
    }
    try {
    func_71013_b.setAccessible(true);
    }
    catch(Exception e){
        System.out.println("Ran into error:\n"+e.getLocalizedMessage()+"\n between lines 34 and 37.");
    }
    try {
    setsize.setAccessible(true);
    }
    catch(Exception e){
        System.out.println("Ran into error:\n"+e.getLocalizedMessage()+"\n between lines 34 and 37.");
    }
    try{
    sleeping.setAccessible(true);
    }
    catch(Exception e){
        System.out.println("Ran into error:\n"+e.getLocalizedMessage()+"\n between lines 34 and 37.");
    }
    try{
    sleeptimer.setAccessible(true);
    }
    catch(Exception e){
        System.out.println("Ran into error:\n"+e.getLocalizedMessage()+"\n between lines 34 and 37.");
    }
}
public static Field getField(String methodName, Class classy){
    for(Field i:classy.getDeclaredFields()){
        if(FMLDeobfuscatingRemapper.INSTANCE.isRemappedClass(classy.getName())){
            if(FMLDeobfuscatingRemapper.INSTANCE.unmap(i.getName())==methodName){
                System.out.println("Found Field "+methodName+" as "+i.getName());
                return i;
            }
        } else {
            if(i.getName()==methodName){
                System.out.println("Found Field "+methodName+" as "+methodName);
                return i;
            }
        }
    }
    return null;
}
public static Method getMethod(String methodName, Class classy, Class... parameters){
    for(Method i:classy.getDeclaredMethods()){
        if(FMLDeobfuscatingRemapper.INSTANCE.isRemappedClass(classy.getName())){
            if(FMLDeobfuscatingRemapper.INSTANCE.unmap(i.getName())==methodName){
                if(arraysAreEqual(i.getParameterTypes(),parameters))
                System.out.println("Found Method "+methodName+" as "+i.getName());
                return i;
            }
        } else {
            if(i.getName()==methodName){
                System.out.println("Found Method "+methodName+" as "+methodName);
                return i;
            }
        }
    }
    return null;
}
public static boolean arraysAreEqual(Object[] a, Object[] b){
    if(a.length!=b.length)return false;
    int check = 0;
    for(int i = 0;i<=a.length;i++){
        if(a[i]!=b[i]){
            return false;
        }
        check = i;
    }
    if(b[check]!=null)return false;
    return true;
}
@SubscribeEvent
public void sleepfix(PlayerSleepInBedEvent e) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException{
    if(e.entity.worldObj.isRemote)return;
    if (!e.entity.worldObj.provider.isSurfaceWorld())return;
    if (e.entity.worldObj.isDaytime())return;
    int d0 = 8;
    int d1 = 8;
    int d2 = 8;
    List list = e.entity.worldObj.getEntitiesWithinAABB(EntityMob.class, AxisAlignedBB.getBoundingBox((double)e.x - d0, (double)e.y - d1, (double)e.z - d0, (double)e.x + d0, (double)e.y + d1, (double)e.z + d0));
    EntityPlayer this1 = e.entityPlayer;
    if (!list.isEmpty())
    {
        boolean lineOfSight = false;
        for(Object i:list){
            EntityMob em = (EntityMob) i;
            if(em.canEntityBeSeen(this1)){
                lineOfSight = true;
                System.out.println("A "+em.getClass().getName()+" can see the player.");
            }
            if(em.getBlockPathWeight((int)this1.posX, (int)this1.posY, (int)this1.posZ)<.2){
                lineOfSight = false;
                System.out.println("A "+em.getClass().getName()+" can reach the player.");
            }
        }
        if(lineOfSight){ 
        System.out.println("Deemed unsafe by JWIN");
        e.result = EntityPlayer.EnumStatus.NOT_SAFE;
        return;
        }

    }
    if (this1.isRiding())
    {
        this1.mountEntity((Entity)null);
    }
    if(setsize!=null)
    setsize.invoke(this1, 0.2F, 0.2F);
    this1.yOffset = 0.2F;
    if(!this1.worldObj.isDaytime()){
    if (this1.worldObj.blockExists(e.x, e.y, e.z))
    {
        int l = this1.worldObj.getBlock(e.x, e.y, e.z).getBedDirection(this1.worldObj, e.x, e.y, e.z);
        float f1 = 0.5F;
        float f = 0.5F;

        switch (l)
        {
            case 0:
                f = 0.9F;
                break;
            case 1:
                f1 = 0.1F;
                break;
            case 2:
                f = 0.1F;
                break;
            case 3:
                f1 = 0.9F;
        }
        if(func_71013_b!=null)
        func_71013_b.invoke(this1, l);
        this1.setPosition((double)((float)e.x + f1), (double)((float)e.y + 0.9375F), (double)((float)e.z + f));
    }
    else
    {
        this1.setPosition((double)((float)e.x + 0.5F), (double)((float)e.y + 0.9375F), (double)((float)e.z + 0.5F));
    }
    System.out.println("Deemed safe by JWIN");
    e.result = EntityPlayer.EnumStatus.OK;
    System.out.println(e.result);
    if(sleeping!=null)
    sleeping.setBoolean(this1,true);
    if(sleeptimer!=null)
    sleeptimer.setInt(this1, 0);
    this1.playerLocation = new ChunkCoordinates(e.x, e.y, e.z);
    this1.motionX = this1.motionZ = this1.motionY = 0.0D;
    if(!this1.worldObj.isRemote)
    this1.worldObj.updateAllPlayersSleepingFlag();
    }
    return;
}
}

再次感谢任何帮助或意见。谢谢!

不得不使用位于 build\tmp\reobf 中的混淆名称。似乎是唯一不涉及访问变压器的修复方法。