Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么java(minecraft)似乎在重置我的变量?_Java_String_User Interface_Reset_Minecraft - Fatal编程技术网

为什么java(minecraft)似乎在重置我的变量?

为什么java(minecraft)似乎在重置我的变量?,java,string,user-interface,reset,minecraft,Java,String,User Interface,Reset,Minecraft,我正在制作一个minecraft mod,它是Java代码,我注意到一个奇怪的行为,字符串似乎正在丢失它的数据。我是Java新手,所以我对Java如何处理字符串或其他对象没有很强的理解。因此,我将说明我正在做什么以及问题在哪里:我有一个类,它有一些文本字段ui元素,用户在其中键入这些元素以给项目命名。然后我要做的是,每当用户更改字段中的文本时,它会将其内容的副本发送到另一个类,然后该类会将其发送到另一个类(这是由于minecraft的设置方式所必需的),然后在创建项目时,最后一个类会从其自身内部

我正在制作一个minecraft mod,它是Java代码,我注意到一个奇怪的行为,字符串似乎正在丢失它的数据。我是Java新手,所以我对Java如何处理字符串或其他对象没有很强的理解。因此,我将说明我正在做什么以及问题在哪里:我有一个类,它有一些文本字段ui元素,用户在其中键入这些元素以给项目命名。然后我要做的是,每当用户更改字段中的文本时,它会将其内容的副本发送到另一个类,然后该类会将其发送到另一个类(这是由于minecraft的设置方式所必需的),然后在创建项目时,最后一个类会从其自身内部更新项目的名称。我不确定这是否是最好的方法,但这是我在短期内想到的。问题是,当创建项时,最后一个类的名称字段(字符串)将被删除,并且为空。我不知道为什么会发生这种情况,也不知道它是如何发生的,因为这些名称字段只有在ui中的文本发生变化时才被(重新)定义,并且它们各自的类都是私有的。所以,我不知所措。我将发布我的课程,希望你们能理解它们并帮助我

GuiRecorder.java

package net.minecraft.src;

import org.lwjgl.opengl.GL11;

public class GuiRecorder extends GuiContainer
{
private TileEntityRecorder recorderInventory;
private GuiTextField discName;
private GuiTextField musicPath;
private ContainerRecorder record;
private boolean isInit;


public GuiRecorder(InventoryPlayer par1InventoryPlayer, TileEntityRecorder par2TileEntityRecorder)
{
    super(new ContainerRecorder(par1InventoryPlayer, par2TileEntityRecorder));
    this.recorderInventory = par2TileEntityRecorder;
    this.record = (ContainerRecorder)(this.inventorySlots);

    int var5 = (this.width - this.xSize) / 2;
    int var6 = (this.height - this.ySize) / 2;

    this.isInit = false;
}

/**
 * Capture Any/All key presses from the user and put them in the correct text field.
 */
protected void keyTyped(char par1, int par2)
{
    if (par2 == 1)
    {
        this.mc.thePlayer.closeScreen();
    }

    else if (this.discName.isFocused())
    {
        this.discName.textboxKeyTyped(par1, par2);
    }
    else if (this.musicPath.isFocused())
    {
        this.musicPath.textboxKeyTyped(par1, par2);
    }

    System.out.println("Keyboard hit! Code: " + par2);

    this.record.setName(this.discName.getText());
    this.record.setPath(this.musicPath.getText());
}

/**
 * Capture Any/All mouse clicks on the GUI.
 */
protected void mouseClicked(int par1, int par2, int par3)
{
    super.mouseClicked(par1, par2, par3);
    this.musicPath.mouseClicked(par1, par2, par3);
    this.discName.mouseClicked(par1, par2, par3);
}

public void onGuiClosed()
{
    this.record.setName(this.discName.getText());
    this.record.setPath(this.musicPath.getText());

    if (this.mc.thePlayer != null)
    {
        this.inventorySlots.onCraftGuiClosed(this.mc.thePlayer);
    }
}

/**
 * Draw the foreground layer for the GuiContainer (everything in front of the items)
 */
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
    this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
    this.fontRenderer.drawString("Disc Name:", (int)(this.xSize*0.02), (int)(this.ySize*0.03)+1, 4210752);
    this.fontRenderer.drawString("Music Path:", (int)(this.xSize*0.02), (int)(this.ySize*0.2)-1, 4210752);
}

/**
 * Draw the background layer for the GuiContainer (everything behind the items)
 */
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{       
    int var4 = this.mc.renderEngine.getTexture("/gui/recorder.png");
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    this.mc.renderEngine.bindTexture(var4);
    int var5 = (this.width - this.xSize) / 2;
    int var6 = (this.height - this.ySize) / 2;
    this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize);
    int var7;

    if(!this.isInit)
    {            
        this.discName = new GuiTextField(this.fontRenderer, var5 + 7, var6 + 16, 68, 10);
        this.musicPath = new GuiTextField(this.fontRenderer, var5 + 7, var6 + 39, 68, 10);

        this.discName.setFocused(true);
        this.musicPath.setFocused(false);

        this.discName.setText("Untitled");
        this.musicPath.setText("cat");

        this.isInit = true;
    }

    var7 = this.recorderInventory.getCookProgressScaled(24);
    this.drawTexturedModalRect(var5 + 111, var6 + 34, 176, 14, var7 + 1, 16);

    this.discName.drawTextBox();
    this.musicPath.drawTextBox();
}
} 
package net.minecraft.src;

import java.util.Iterator;

public class ContainerRecorder extends Container
{
private TileEntityRecorder recorder;
private int lastCookTime = 0;
private int lastBurnTime = 0;
private int lastItemBurnTime = 0;
public volatile String name;
public volatile String path;

public ContainerRecorder(InventoryPlayer par1InventoryPlayer, TileEntityRecorder par2TileEntityRecorder)
{
    this.recorder = par2TileEntityRecorder;
    this.addSlotToContainer(new Slot(par2TileEntityRecorder, 0, 87, 35));
    this.addSlotToContainer(new SlotRecorder(par1InventoryPlayer.player, par2TileEntityRecorder, 2, 148, 36));

    int var3;

    for (var3 = 0; var3 < 3; ++var3)
    {
        for (int var4 = 0; var4 < 9; ++var4)
        {
            this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
        }
    }

    for (var3 = 0; var3 < 9; ++var3)
    {
        this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142));
    }

    this.name = "Untitled";
    this.path = "cat";
}

public void addCraftingToCrafters(ICrafting par1ICrafting)
{
    super.addCraftingToCrafters(par1ICrafting);
    par1ICrafting.updateCraftingInventoryInfo(this, 0, this.recorder.currentBurnTime);
    par1ICrafting.updateCraftingInventoryInfo(this, 2, this.recorder.currentItemBurnTime);
}

/**
 * Updates crafting matrix; called from onCraftMatrixChanged. Args: none
 */
public void updateCraftingResults()
{
    super.updateCraftingResults();
    Iterator var1 = this.crafters.iterator();

    while (var1.hasNext())
    {
        ICrafting var2 = (ICrafting)var1.next();

        if (this.lastCookTime != this.recorder.currentBurnTime)
        {
            var2.updateCraftingInventoryInfo(this, 0, this.recorder.currentBurnTime);
        }

        if (this.lastItemBurnTime != this.recorder.currentItemBurnTime)
        {
            var2.updateCraftingInventoryInfo(this, 2, this.recorder.currentItemBurnTime);
        }
    }

    this.lastCookTime = this.recorder.currentBurnTime;
    this.lastBurnTime = this.recorder.burnTime;
    this.lastItemBurnTime = this.recorder.currentItemBurnTime;
}

public void updateProgressBar(int par1, int par2)
{
    if (par1 == 0)
    {
        this.recorder.currentBurnTime = par2;
    }

    if (par1 == 1)
    {
        this.recorder.burnTime = par2;
    }

    if (par1 == 2)
    {
        this.recorder.currentItemBurnTime = par2;
    }
}

public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
    return this.recorder.isUseableByPlayer(par1EntityPlayer);
}

public ItemStack func_82846_b(EntityPlayer par1EntityPlayer, int par2)
{
    ItemStack var3 = null;
    Slot var4 = (Slot)this.inventorySlots.get(par2);

    if (var4 != null && var4.getHasStack())
    {
        ItemStack var5 = var4.getStack();
        var3 = var5.copy();

        if (par2 == 2)
        {
            if (!this.mergeItemStack(var5, 3, 39, true))
            {
                return null;
            }

            var4.onSlotChange(var5, var3);
        }
        else if (par2 != 1 && par2 != 0)
        {
            if (RecorderRecipes.smelting().getSmeltingResult(var5.getItem().shiftedIndex) != null)
            {
                if (!this.mergeItemStack(var5, 0, 1, false))
                {
                    return null;
                }
            }
            else if (TileEntityRecorder.isItemFuel(var5))
            {
                if (!this.mergeItemStack(var5, 1, 2, false))
                {
                    return null;
                }
            }
            else if (par2 >= 3 && par2 < 30)
            {
                if (!this.mergeItemStack(var5, 30, 39, false))
                {
                    return null;
                }
            }
            else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(var5, 3, 30, false))
            {
                return null;
            }
        }
        else if (!this.mergeItemStack(var5, 3, 39, false))
        {
            return null;
        }

        if (var5.stackSize == 0)
        {
            var4.putStack((ItemStack)null);
        }
        else
        {
            var4.onSlotChanged();
        }

        if (var5.stackSize == var3.stackSize)
        {
            return null;
        }

        var4.func_82870_a(par1EntityPlayer, var5);
    }

    return var3;
}

public void setName(final String aName)
{
    this.name = aName;
    System.out.println("<ContainerRecorder>Record Name Set! Name: " + this.name);
    this.recorder.setDiscName(this.name);
    this.recorder.setMusicPath(this.path);
}

public void setPath(final String aPath)
{
    this.path = aPath;
    System.out.println("<ContainerRecorder>Record Path Set! Path: " + this.path);
    this.recorder.setDiscName(this.name);
    this.recorder.setMusicPath(this.path);
}
}
ContainerRecorder.java

package net.minecraft.src;

import org.lwjgl.opengl.GL11;

public class GuiRecorder extends GuiContainer
{
private TileEntityRecorder recorderInventory;
private GuiTextField discName;
private GuiTextField musicPath;
private ContainerRecorder record;
private boolean isInit;


public GuiRecorder(InventoryPlayer par1InventoryPlayer, TileEntityRecorder par2TileEntityRecorder)
{
    super(new ContainerRecorder(par1InventoryPlayer, par2TileEntityRecorder));
    this.recorderInventory = par2TileEntityRecorder;
    this.record = (ContainerRecorder)(this.inventorySlots);

    int var5 = (this.width - this.xSize) / 2;
    int var6 = (this.height - this.ySize) / 2;

    this.isInit = false;
}

/**
 * Capture Any/All key presses from the user and put them in the correct text field.
 */
protected void keyTyped(char par1, int par2)
{
    if (par2 == 1)
    {
        this.mc.thePlayer.closeScreen();
    }

    else if (this.discName.isFocused())
    {
        this.discName.textboxKeyTyped(par1, par2);
    }
    else if (this.musicPath.isFocused())
    {
        this.musicPath.textboxKeyTyped(par1, par2);
    }

    System.out.println("Keyboard hit! Code: " + par2);

    this.record.setName(this.discName.getText());
    this.record.setPath(this.musicPath.getText());
}

/**
 * Capture Any/All mouse clicks on the GUI.
 */
protected void mouseClicked(int par1, int par2, int par3)
{
    super.mouseClicked(par1, par2, par3);
    this.musicPath.mouseClicked(par1, par2, par3);
    this.discName.mouseClicked(par1, par2, par3);
}

public void onGuiClosed()
{
    this.record.setName(this.discName.getText());
    this.record.setPath(this.musicPath.getText());

    if (this.mc.thePlayer != null)
    {
        this.inventorySlots.onCraftGuiClosed(this.mc.thePlayer);
    }
}

/**
 * Draw the foreground layer for the GuiContainer (everything in front of the items)
 */
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
    this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
    this.fontRenderer.drawString("Disc Name:", (int)(this.xSize*0.02), (int)(this.ySize*0.03)+1, 4210752);
    this.fontRenderer.drawString("Music Path:", (int)(this.xSize*0.02), (int)(this.ySize*0.2)-1, 4210752);
}

/**
 * Draw the background layer for the GuiContainer (everything behind the items)
 */
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{       
    int var4 = this.mc.renderEngine.getTexture("/gui/recorder.png");
    GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
    this.mc.renderEngine.bindTexture(var4);
    int var5 = (this.width - this.xSize) / 2;
    int var6 = (this.height - this.ySize) / 2;
    this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize);
    int var7;

    if(!this.isInit)
    {            
        this.discName = new GuiTextField(this.fontRenderer, var5 + 7, var6 + 16, 68, 10);
        this.musicPath = new GuiTextField(this.fontRenderer, var5 + 7, var6 + 39, 68, 10);

        this.discName.setFocused(true);
        this.musicPath.setFocused(false);

        this.discName.setText("Untitled");
        this.musicPath.setText("cat");

        this.isInit = true;
    }

    var7 = this.recorderInventory.getCookProgressScaled(24);
    this.drawTexturedModalRect(var5 + 111, var6 + 34, 176, 14, var7 + 1, 16);

    this.discName.drawTextBox();
    this.musicPath.drawTextBox();
}
} 
package net.minecraft.src;

import java.util.Iterator;

public class ContainerRecorder extends Container
{
private TileEntityRecorder recorder;
private int lastCookTime = 0;
private int lastBurnTime = 0;
private int lastItemBurnTime = 0;
public volatile String name;
public volatile String path;

public ContainerRecorder(InventoryPlayer par1InventoryPlayer, TileEntityRecorder par2TileEntityRecorder)
{
    this.recorder = par2TileEntityRecorder;
    this.addSlotToContainer(new Slot(par2TileEntityRecorder, 0, 87, 35));
    this.addSlotToContainer(new SlotRecorder(par1InventoryPlayer.player, par2TileEntityRecorder, 2, 148, 36));

    int var3;

    for (var3 = 0; var3 < 3; ++var3)
    {
        for (int var4 = 0; var4 < 9; ++var4)
        {
            this.addSlotToContainer(new Slot(par1InventoryPlayer, var4 + var3 * 9 + 9, 8 + var4 * 18, 84 + var3 * 18));
        }
    }

    for (var3 = 0; var3 < 9; ++var3)
    {
        this.addSlotToContainer(new Slot(par1InventoryPlayer, var3, 8 + var3 * 18, 142));
    }

    this.name = "Untitled";
    this.path = "cat";
}

public void addCraftingToCrafters(ICrafting par1ICrafting)
{
    super.addCraftingToCrafters(par1ICrafting);
    par1ICrafting.updateCraftingInventoryInfo(this, 0, this.recorder.currentBurnTime);
    par1ICrafting.updateCraftingInventoryInfo(this, 2, this.recorder.currentItemBurnTime);
}

/**
 * Updates crafting matrix; called from onCraftMatrixChanged. Args: none
 */
public void updateCraftingResults()
{
    super.updateCraftingResults();
    Iterator var1 = this.crafters.iterator();

    while (var1.hasNext())
    {
        ICrafting var2 = (ICrafting)var1.next();

        if (this.lastCookTime != this.recorder.currentBurnTime)
        {
            var2.updateCraftingInventoryInfo(this, 0, this.recorder.currentBurnTime);
        }

        if (this.lastItemBurnTime != this.recorder.currentItemBurnTime)
        {
            var2.updateCraftingInventoryInfo(this, 2, this.recorder.currentItemBurnTime);
        }
    }

    this.lastCookTime = this.recorder.currentBurnTime;
    this.lastBurnTime = this.recorder.burnTime;
    this.lastItemBurnTime = this.recorder.currentItemBurnTime;
}

public void updateProgressBar(int par1, int par2)
{
    if (par1 == 0)
    {
        this.recorder.currentBurnTime = par2;
    }

    if (par1 == 1)
    {
        this.recorder.burnTime = par2;
    }

    if (par1 == 2)
    {
        this.recorder.currentItemBurnTime = par2;
    }
}

public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
    return this.recorder.isUseableByPlayer(par1EntityPlayer);
}

public ItemStack func_82846_b(EntityPlayer par1EntityPlayer, int par2)
{
    ItemStack var3 = null;
    Slot var4 = (Slot)this.inventorySlots.get(par2);

    if (var4 != null && var4.getHasStack())
    {
        ItemStack var5 = var4.getStack();
        var3 = var5.copy();

        if (par2 == 2)
        {
            if (!this.mergeItemStack(var5, 3, 39, true))
            {
                return null;
            }

            var4.onSlotChange(var5, var3);
        }
        else if (par2 != 1 && par2 != 0)
        {
            if (RecorderRecipes.smelting().getSmeltingResult(var5.getItem().shiftedIndex) != null)
            {
                if (!this.mergeItemStack(var5, 0, 1, false))
                {
                    return null;
                }
            }
            else if (TileEntityRecorder.isItemFuel(var5))
            {
                if (!this.mergeItemStack(var5, 1, 2, false))
                {
                    return null;
                }
            }
            else if (par2 >= 3 && par2 < 30)
            {
                if (!this.mergeItemStack(var5, 30, 39, false))
                {
                    return null;
                }
            }
            else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(var5, 3, 30, false))
            {
                return null;
            }
        }
        else if (!this.mergeItemStack(var5, 3, 39, false))
        {
            return null;
        }

        if (var5.stackSize == 0)
        {
            var4.putStack((ItemStack)null);
        }
        else
        {
            var4.onSlotChanged();
        }

        if (var5.stackSize == var3.stackSize)
        {
            return null;
        }

        var4.func_82870_a(par1EntityPlayer, var5);
    }

    return var3;
}

public void setName(final String aName)
{
    this.name = aName;
    System.out.println("<ContainerRecorder>Record Name Set! Name: " + this.name);
    this.recorder.setDiscName(this.name);
    this.recorder.setMusicPath(this.path);
}

public void setPath(final String aPath)
{
    this.path = aPath;
    System.out.println("<ContainerRecorder>Record Path Set! Path: " + this.path);
    this.recorder.setDiscName(this.name);
    this.recorder.setMusicPath(this.path);
}
}
package net.minecraft.src;
导入java.util.Iterator;
公共类ContainerRecorder扩展了容器
{
专用TileEntityRecorder记录器;
private int lastCookTime=0;
private int lastBurnTime=0;
private int lastItemBurnTime=0;
公共易失性字符串名称;
公共易失性字符串路径;
公共容器记录(InventoryPlayer par1InventoryPlayer,TileEntityRecorder par2TileEntityRecorder)
{
this.recorder=par2titleentityrecorder;
这个.addSlotToContainer(新插槽(par2TileEntityRecorder,0,87,35));
这个.addSlotToContainer(新的SlotRecorder(par1InventoryPlayer.player,par2TileEntityRecorder,2148,36));
int-var3;
对于(var3=0;var3<3;++var3)
{
对于(int var4=0;var4<9;++var4)
{
这个.addSlotToContainer(新插槽(par1InventoryPlayer,var4+var3*9+9,8+var4*18,84+var3*18));
}
}
对于(var3=0;var3<9;++var3)
{
这个.addSlotToContainer(新插槽(par1InventoryPlayer,var3,8+var3*18142));
}
this.name=“Untitled”;
this.path=“cat”;
}
公共作废添加工艺流程(ICrafting PAR1工艺流程)
{
super.添加手工制作手稿(par1crafting);
par1crafting.updateCraftingInventoryInfo(this,0,this.recorder.currentBurnTime);
par1crafting.updateCraftingInventoryInfo(this,2,this.recorder.currentItemBurnTime);
}
/**
*更新工艺矩阵;从onCraftMatrixChanged调用。参数:无
*/
public void updateCraftingResults()
{
super.updateCraftingResults();
迭代器var1=this.crafters.Iterator();
while(var1.hasNext())
{
ICrafting var2=(ICrafting)var1.next();
if(this.lastCookTime!=this.recorder.currentBurnTime)
{
var2.updateCraftingInventoryInfo(this,0,this.recorder.currentBurnTime);
}
if(this.lastItemBurnTime!=this.recorder.currentItemBurnTime)
{
var2.updateCraftingInventoryInfo(this,2,this.recorder.currentItemBurnTime);
}
}
this.lastCookTime=this.recorder.currentBurnTime;
this.lastBurnTime=this.recorder.burnTime;
this.lastItemBurnTime=this.recorder.currentItemBurnTime;
}
public void updateProgressBar(intpar1,intpar2)
{
如果(par1==0)
{
this.recorder.currentBurnTime=par2;
}
如果(par1==1)
{
this.recorder.burnTime=par2;
}
如果(par1==2)
{
this.recorder.currentItemBurnTime=par2;
}
}
公共布尔CAINTERACTWITH(EntityLayer Par1EntityLayer)
{
返回此.recorder.isUsableByPlayer(Par1EntityLayer);
}
公共项堆栈函数\u 82846\u b(EntityLayer参数EntityLayer,int参数2)
{
ItemStack var3=null;
Slot var4=(Slot)this.inventorySlots.get(par2);
if(var4!=null&&var4.getHasStack()
{
ItemStack var5=var4.getStack();
var3=var5.copy();
if(par2==2)
{
if(!this.mergeItemStack(var5,3,39,true))
{
返回null;
}
var4.onSlotChange(var5,var3);
}
else如果(par2!=1&&par2!=0)
{
if(RecorderRecipes.Melting().GetMeltingResult(var5.getItem().shiftedIndex)!=null)
{
if(!this.mergeItemStack(var5,0,1,false))
{
返回null;
}
}
else if(TileEntityRecorder.isItemFuel(var5))
{
if(!this.mergeItemStack(var5,1,2,false))
{
返回null;
}
}
否则如果(par2>=3&&par2<30)
{
if(!this.mergeItemStack(var5、30、39、false))
{
返回null;
}
}
else if(par2>=30&&par2<39&&!this.mergeItemStack(var5,3,30,false))
{
返回null;
}
}
如果(!this.mergeItemStack(var5、3、39、false))为else
{
返回null;
}
if(var5.stackSize==0)
{
var4.putStack((ItemStack)null);
}
其他的
{
var4.onSlotChanged();
}
if(var5.stackSize==var3.stackSize)
{
返回null;
}
var4.func \-u 82870 \-a(PAR1实体层,var5);
}
返回变量3;
}
public void setName(最终字符串aName)
{
this.name=aName;
System.out.println(“记录名称集!名称:“+this.Name”);
this.recorder.setDiscName(this.name);
this.recorder.setMusicPath(this.path);
}
公共void设置路径(最终字符串aPath)
{
这条路=