Вылетает майнкрафт при открытия gui 1.7.10

Версия Minecraft
1.7.10
API
Forge
TileEntity:
public class TileEntityStandartSP extends TileEntityBase implements IEnergyTile, IWrenchable, IEnergySource, IInventory, INetworkDataProvider, INetworkUpdateListener
{
    public static Random randomizer = new Random();
    public int ticker;
    public int generating;
    public int genDay;
    public int genNight;
    public boolean initialized;
    public boolean sunIsUp;
    public boolean skyIsVisible;
    private short facing = 2;
    private boolean noSunWorld;
    private boolean wetBiome;
    private int machineTire;
    public boolean addedToEnergyNet;
    private boolean created = false;
    private ItemStack[] chargeSlots;
    public int fuel;
    private int lastX;
    private int lastY;
    private int lastZ;
    public int storage;
    private int solarType;
    public String panelName;
    public int production;
    public int maxStorage;
    public boolean loaded = false;
    private static List<String> fields = Arrays.asList();

    public TileEntityStandartSP(String gName, int typeSolar, int gDay, int gNight, int gOutput, int gmaxStorage) {
        this.solarType = typeSolar;
        this.genDay = gDay;
        this.genNight = gNight;
        this.storage = 0;
        this.panelName = gName;
        this.sunIsUp = false;
        this.skyIsVisible = false;
        this.maxStorage = gmaxStorage;
        this.chargeSlots = new ItemStack[4];
        this.initialized = false;
        this.production = gOutput;
        this.ticker = randomizer.nextInt(this.tickRate());
        this.lastX = this.xCoord;
        this.lastY = this.yCoord;
        this.lastZ = this.zCoord;
        this.machineTire = Integer.MAX_VALUE;
    }

    public void validate() {
        super.validate();
        if (!this.isInvalid() && this.worldObj.blockExists(this.xCoord, this.yCoord, this.zCoord)) {
            this.onLoaded();
        }
    }

    public void invalidate() {
        if (this.loaded) {
            this.onUnloaded();
        }

        super.invalidate();
    }

    public void onLoaded() {
        if (!this.worldObj.isRemote) {
            MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
            this.addedToEnergyNet = true;
        }

        this.loaded = true;
    }

    public void onChunkUnload() {
        if (this.loaded) {
            this.onUnloaded();
        }

        super.onChunkUnload();
    }

    public void onUnloaded() {
        if (!this.worldObj.isRemote && this.addedToEnergyNet) {
            MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
            this.addedToEnergyNet = false;
        }

        this.loaded = false;
    }

    public void intialize() {
        this.wetBiome = this.worldObj.getWorldChunkManager().getBiomeGenAt(this.xCoord, this.zCoord).getIntRainfall() > 0;
        this.noSunWorld = this.worldObj.provider.hasNoSky;
        this.updateVisibility();
        this.initialized = true;
        if (!this.addedToEnergyNet) {
            this.onLoaded();
        }

    }

    public void updateEntity() {
        super.updateEntity();
        if (!this.initialized && this.worldObj != null) {
            this.intialize();
        }

        if (!this.worldObj.isRemote) {
            if (this.lastX != this.xCoord || this.lastZ != this.zCoord || this.lastY != this.yCoord) {
                this.lastX = this.xCoord;
                this.lastY = this.yCoord;
                this.lastZ = this.zCoord;
                this.onUnloaded();
                this.intialize();
            }

            this.gainFuel();
            if (this.generating > 0) {
                if (this.storage + this.generating <= this.maxStorage) {
                    this.storage += this.generating;
                } else {
                    this.storage = this.maxStorage;
                }
            }

            boolean needInvUpdate = false;
            double sentPacket = 0.0;

            for(int i = 0; i < this.chargeSlots.length; ++i) {
                if (this.chargeSlots[i] != null && this.chargeSlots[i].getItem() instanceof IElectricItem && this.storage > 0) {
                    sentPacket = ElectricItem.manager.charge(this.chargeSlots[i], (double)this.storage, Integer.MAX_VALUE, false, false);
                    if (sentPacket > 0.0) {
                        needInvUpdate = true;
                    }

                    this.storage = (int)((double)this.storage - sentPacket);
                }
            }

            if (needInvUpdate) {
                super.markDirty();
            }

        }
    }

    public int gainFuel() {
        if (this.ticker++ % this.tickRate() == 0) {
            this.updateVisibility();
        }

        if (this.sunIsUp && this.skyIsVisible) {
            this.generating = 0 + this.genDay;
            return this.generating;
        } else if (this.skyIsVisible) {
            this.generating = 0 + this.genNight;
            return this.generating;
        } else {
            this.generating = 0;
            return this.generating;
        }
    }

    public void updateVisibility() {
        Boolean rainWeather = this.wetBiome && (this.worldObj.isRaining() || this.worldObj.isThundering());
        if (this.worldObj.isDaytime() && !rainWeather) {
            this.sunIsUp = true;
        } else {
            this.sunIsUp = false;
        }

        if (this.worldObj.canBlockSeeTheSky(this.xCoord, this.yCoord + 1, this.zCoord) && !this.noSunWorld) {
            this.skyIsVisible = true;
        } else {
            this.skyIsVisible = false;
        }

    }

    public void readFromNBT(NBTTagCompound nbttagcompound) {
        super.readFromNBT(nbttagcompound);
        this.storage = nbttagcompound.getInteger("storage");
        this.lastX = nbttagcompound.getInteger("lastX");
        this.lastY = nbttagcompound.getInteger("lastY");
        this.lastZ = nbttagcompound.getInteger("lastZ");
        NBTTagList nbttaglist = nbttagcompound.getTagList("Items", 10);
        this.chargeSlots = new ItemStack[this.getSizeInventory()];

        for(int i = 0; i < nbttaglist.tagCount(); ++i) {
            NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
            int j = nbttagcompound1.getByte("Slot") & 255;
            if (j >= 0 && j < this.chargeSlots.length) {
                this.chargeSlots[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
            }
        }

    }

    public void writeToNBT(NBTTagCompound nbttagcompound) {
        super.writeToNBT(nbttagcompound);
        NBTTagList nbttaglist = new NBTTagList();
        nbttagcompound.setInteger("storage", this.storage);
        nbttagcompound.setInteger("lastX", this.lastX);
        nbttagcompound.setInteger("lastY", this.lastY);
        nbttagcompound.setInteger("lastZ", this.lastZ);

        for(int i = 0; i < this.chargeSlots.length; ++i) {
            if (this.chargeSlots[i] != null) {
                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                nbttagcompound1.setByte("Slot", (byte)i);
                this.chargeSlots[i].writeToNBT(nbttagcompound1);
                nbttaglist.appendTag(nbttagcompound1);
            }
        }

        nbttagcompound.setTag("Items", nbttaglist);
    }

    public boolean isAddedToEnergyNet() {
        return this.addedToEnergyNet;
    }

    public int getMaxEnergyOutput() {
        return this.production;
    }

    public int gaugeEnergyScaled(int i) {
        return this.storage * i / this.maxStorage;
    }

    public int gaugeFuelScaled(int i) {
        return i;
    }

    public boolean isUseableByPlayer(EntityPlayer entityplayer) {
        return entityplayer.getDistance((double)this.xCoord + 0.5, (double)this.yCoord + 0.5, (double)this.zCoord + 0.5) <= 64.0;
    }

    public void openInventory() {
    }

    public void closeInventory() {
    }

    public int tickRate() {
        return 128;
    }

    public short getFacing() {
        return this.facing;
    }

    public void setFacing(short facing) {
        this.facing = facing;
    }

    public boolean wrenchCanSetFacing(EntityPlayer entityplayer, int i) {
        return false;
    }

    public boolean wrenchCanRemove(EntityPlayer entityplayer) {
        return true;
    }

    public float getWrenchDropRate() {
        return 1.0F;
    }

    public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
        return new ItemStack(this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord), 1, this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord));
    }

    public ItemStack[] getContents() {
        return this.chargeSlots;
    }

    public int getSizeInventory() {
        return 4;
    }

    public ItemStack getStackInSlot(int i) {
        return this.chargeSlots[i];
    }

    public ItemStack decrStackSize(int i, int j) {
        if (this.chargeSlots[i] != null) {
            ItemStack itemstack1;
            if (this.chargeSlots[i].stackSize <= j) {
                itemstack1 = this.chargeSlots[i];
                this.chargeSlots[i] = null;
                return itemstack1;
            } else {
                itemstack1 = this.chargeSlots[i].splitStack(j);
                if (this.chargeSlots[i].stackSize == 0) {
                    this.chargeSlots[i] = null;
                }

                return itemstack1;
            }
        } else {
            return null;
        }
    }

    public void setInventorySlotContents(int i, ItemStack itemstack) {
        this.chargeSlots[i] = itemstack;
        if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()) {
            itemstack.stackSize = this.getInventoryStackLimit();
        }

    }

    public String getInventoryName() {
        return "WilerLand AddonIndustry";
    }

    public boolean hasCustomInventoryName() {
        return true;
    }

    public int getInventoryStackLimit() {
        return 64;
    }

    public Container getGuiContainer(InventoryPlayer inventoryplayer) {
        return new ContainerStandartSP(inventoryplayer, this);
    }

    public String getInvName() {
        return null;
    }

    public ItemStack getStackInSlotOnClosing(int var1) {
        if (this.chargeSlots[var1] != null) {
            ItemStack var2 = this.chargeSlots[var1];
            this.chargeSlots[var1] = null;
            return var2;
        } else {
            return null;
        }
    }

    public boolean isItemValidForSlot(int i, ItemStack itemstack) {
        return true;
    }

    public void onNetworkUpdate(String field) {
    }

    public List<String> getNetworkedFields() {
        return fields;
    }

    public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction) {
        return true;
    }

    public double getOfferedEnergy() {
        return (double)Math.min(this.production, this.storage);
    }

    public void drawEnergy(double amount) {
        this.storage = (int)((double)this.storage - amount);
    }

    public int getSourceTier() {
        return this.machineTire;
    }
Gui:
public class GuiUniversalSP extends GuiContainer
{
    private static final ResourceLocation guitext = new ResourceLocation(wlAddonIndustry.DOMAIN, "textures/gui/GuiSP.png");

    public GuiUniversalSP(InventoryPlayer inventory, TileEntityUniversalSolarPanel tile) {
        super(new ContainerStandartSP(inventory, tile));

        this.xSize = 185;
        this.ySize = 185;
    }

    @Override
    protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        try {
            Minecraft.getMinecraft().getResourceManager().getResource(guitext);
        } catch(IOException e) {
            System.out.println("Texture gui not reloaded!");
            e.printStackTrace();
        }
        drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize);
    }
}
GuiHandler:
public class GuiHandlerUniversalSP implements IGuiHandler
{
    @Override
    public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        TileEntity entity = world.getTileEntity(x, y, z);
        switch(ID) {
            case 0:
                if(entity != null && entity instanceof TileEntityUniversalSolarPanel) {
                    return new ContainerStandartSP(player.inventory, (TileEntityUniversalSolarPanel) entity);
                } else {
                    return null;
                }
        }
        return null;
    }

    @Override
    public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
        TileEntity entity = world.getTileEntity(x, y, z);
        switch(ID) {
            case 0:
                if(entity != null && entity instanceof TileEntityUniversalSolarPanel) {
                    return new ContainerStandartSP(player.inventory, (TileEntityUniversalSolarPanel) entity);
                } else {
                    return null;
                }
        }
        return null;
    }
}
Container:
public class ContainerStandartSP extends Container
{
    private TileEntityStandartSP tileentity;
    private int storage = 0;
    private int fuel = 0;
    private boolean sunIsUp;
    private boolean skyIsVisible;
    private int generating;

    public ContainerStandartSP(InventoryPlayer inventoryplayer, TileEntityStandartSP tileentitystandartsp) {
        this.tileentity = tileentitystandartsp;

        int j;
        for(j = 0; j < 4; ++j) {
            this.addSlotToContainer(new Slot(this.tileentity, j, 17 + j * 18, 59));
        }

        for(j = 0; j < 9; ++j) {
            for(int k = 0; k < 9; ++k) {
                this.addSlotToContainer(new Slot(inventoryplayer, k + j * 9 + 9, 17 + k * 18, 86 + j * 18));
            }
        }

        for(j = 0; j < 9; ++j) {
            this.addSlotToContainer(new Slot(inventoryplayer, j, 17 + j * 18, 144));
        }
    }

    public void addCraftingToCrafters(ICrafting icrafting) {
        super.addCraftingToCrafters(icrafting);
        icrafting.sendProgressBarUpdate(this, 0, this.tileentity.sunIsUp ? 1 : 0);
        icrafting.sendProgressBarUpdate(this, 1, this.tileentity.skyIsVisible ? 1 : 0);
        icrafting.sendProgressBarUpdate(this, 2, this.tileentity.generating);
        icrafting.sendProgressBarUpdate(this, 3, this.tileentity.storage & '\uffff');
        icrafting.sendProgressBarUpdate(this, 4, this.tileentity.storage >>> 16);
    }

    public void detectAndSendChanges() {
        super.detectAndSendChanges();

        for(int i = 0; i < this.crafters.size(); ++i) {
            ICrafting icrafting = (ICrafting)this.crafters.get(i);
            icrafting.sendProgressBarUpdate(this, 0, this.tileentity.sunIsUp ? 1 : 0);
            icrafting.sendProgressBarUpdate(this, 1, this.tileentity.skyIsVisible ? 1 : 0);
            icrafting.sendProgressBarUpdate(this, 2, this.tileentity.generating);
            icrafting.sendProgressBarUpdate(this, 3, this.tileentity.storage & '\uffff');
            icrafting.sendProgressBarUpdate(this, 4, this.tileentity.storage >>> 16);
        }

        this.sunIsUp = this.tileentity.sunIsUp;
        this.skyIsVisible = this.tileentity.skyIsVisible;
        this.generating = this.tileentity.generating;
        this.storage = this.tileentity.storage;
    }

    public void updateProgressBar(int i, int j) {
        if (i == 0) {
            this.tileentity.sunIsUp = j != 0;
        }

        if (i == 1) {
            this.tileentity.skyIsVisible = j != 0;
        }

        if (i == 2) {
            this.tileentity.generating = j;
        }

        if (i == 3) {
            this.tileentity.storage = this.tileentity.storage & -65536 | j;
        }

        if (i == 4) {
            this.tileentity.storage = this.tileentity.storage & '\uffff' | j << 16;
        }

    }

    public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
        ItemStack stack = null;
        Slot slotObject = (Slot)this.inventorySlots.get(par2);
        if (slotObject != null && slotObject.getHasStack()) {
            ItemStack stackInSlot = slotObject.getStack();
            stack = stackInSlot.copy();
            if (par2 >= 0 && par2 <= 3) {
                if (!this.mergeItemStack(stackInSlot, 4, 40, true)) {
                    return null;
                }
            } else if (par2 >= 4 && par2 < 31) {
                if (!this.mergeItemStack(stackInSlot, 0, 4, false) && !this.mergeItemStack(stackInSlot, 31, 40, false)) {
                    return null;
                }
            } else if (par2 >= 31 && par2 < 39) {
                if (!this.mergeItemStack(stackInSlot, 0, 30, false)) {
                    return null;
                }
            } else if (!this.mergeItemStack(stackInSlot, 0, 30, false)) {
                return null;
            }

            if (stackInSlot.stackSize == 0) {
                slotObject.putStack((ItemStack)null);
            } else {
                slotObject.onSlotChanged();
            }

            if (stack.stackSize == stackInSlot.stackSize) {
                return null;
            }

            slotObject.onPickupFromSlot(par1EntityPlayer, stackInSlot);
        }

        return stack;
    }

    public boolean canInteractWith(EntityPlayer entityplayer) {
        return this.tileentity.isUseableByPlayer(entityplayer);
    }
}
onBlockActivated:
@Override
    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
        if(world.isRemote) {
            return true;
        } else {
            TileEntityUniversalSolarPanel tile = (TileEntityUniversalSolarPanel) world.getTileEntity(x, y, z);

            if(tile != null) {
                player.openGui(wlAddonIndustry.instance, 0, world, x, y, z);
            }
        }
        return true;
    }
RegisterGuiHandler:
NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandlerUniversalSP());

Создавал панель по примеру AdvancedSolarPanel, буду рад если поможите.
 

Вложения

  • crash-2024-02-08_19.23.12-server.txt
    5.4 KB · Просмотры: 3
Решение
Java:
public ContainerStandartSP(InventoryPlayer inventoryplayer, TileEntityStandartSP tileentitystandartsp) {
        this.tileentity = tileentitystandartsp;

        int j;
        for(j = 0; j < 4; ++j) {
            this.addSlotToContainer(new Slot(this.tileentity, j, 17 + j * 18, 59));
        }

        for(j = 0; j < 9; ++j) {
            for(int k = 0; k < 9; ++k) {
                this.addSlotToContainer(new Slot(inventoryplayer, k + j * 9 + 9, 17 + k * 18, 86 + j * 18));
            }
        }

        for(j = 0; j < 9; ++j) {
            this.addSlotToContainer(new Slot(inventoryplayer, j, 17 + j * 18, 144));
        }
    }
В первом цикле у тебя последний элемент с номером 3, а в том же методе addCraftingToCrafters()...
Все проблемы исходят из-за использования декомпилированного кода. Приведи его в порядок и многое сразу станет понятным. @Override имеет смысл добавить, сразу будет видно какие неиспользуемые методы можно выкинуть.
 
Java:
public ContainerStandartSP(InventoryPlayer inventoryplayer, TileEntityStandartSP tileentitystandartsp) {
        this.tileentity = tileentitystandartsp;

        int j;
        for(j = 0; j < 4; ++j) {
            this.addSlotToContainer(new Slot(this.tileentity, j, 17 + j * 18, 59));
        }

        for(j = 0; j < 9; ++j) {
            for(int k = 0; k < 9; ++k) {
                this.addSlotToContainer(new Slot(inventoryplayer, k + j * 9 + 9, 17 + k * 18, 86 + j * 18));
            }
        }

        for(j = 0; j < 9; ++j) {
            this.addSlotToContainer(new Slot(inventoryplayer, j, 17 + j * 18, 144));
        }
    }
В первом цикле у тебя последний элемент с номером 3, а в том же методе addCraftingToCrafters() происходит обращение к 4-му элементу массива, которого не существует, поэтому и выдает ArrayIndexOutOfBoundsException.
 
Назад
Сверху