- 25
- 2
- 0
У меня есть блок с ГУИ, но при нажатии на него крашится майн по причине ArrayIndexOutOfBoundsException: 9 и я так понимаю это происходит при копировании инвентаря и инвентарь блока
NetworkRegistry.INSTANCE.regosterGuiHandler(this, new CommonProxy()); есть
p.s. код копировал с печки и изменял под мой блок
Java:
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import ru.wertyfiregames.craftablecreatures.CraftableCreatures;
import ru.wertyfiregames.craftablecreatures.client.particle.EntitySoulFX;
import ru.wertyfiregames.craftablecreatures.creativetab.CCCreativeTabs;
import ru.wertyfiregames.craftablecreatures.tile.TileEntitySoulExtractor;
import java.util.Random;
public class BlockSoulExtractor extends BlockDefaultContainer
{
private final Random rnd = new Random();
private final boolean isWorking;
private static boolean isLit;
@SideOnly(Side.CLIENT)
private IIcon topTextures;
@SideOnly(Side.CLIENT)
private IIcon frontTexture;
protected BlockSoulExtractor(boolean isWorking)
{
super(Material.iron, "soulExtractor", "custom", isWorking ? null : CCCreativeTabs.tabCraftableCreatures,
"pickaxe", 2, 5f, 10f);
this.isWorking = isWorking;
}
public Item getItemDropped(int par1, Random random, int par2)
{
return Item.getItemFromBlock(CCBlocks.soul_extractor);
}
public void onBlockAdded(World world, int x, int y, int z)
{
super.onBlockAdded(world, x, y, z);
this.setBlockMeta(world, x, y, z);
}
private void setBlockMeta(World world, int x, int y, int z)
{
if (!world.isRemote)
{
Block block = world.getBlock(x, y, z - 1);
Block block1 = world.getBlock(x, y, z + 1);
Block block2 = world.getBlock(x - 1, y, z);
Block block3 = world.getBlock(x + 1, y, z);
byte b0 = 3;
if (block.func_149730_j() && !block1.func_149730_j())
{
b0 = 3;
}
if (block1.func_149730_j() && !block.func_149730_j())
{
b0 = 2;
}
if (block2.func_149730_j() && !block3.func_149730_j())
{
b0 = 5;
}
if (block3.func_149730_j() && !block2.func_149730_j())
{
b0 = 4;
}
world.setBlockMetadataWithNotify(x, y, z, b0, 2);
}
}
@SideOnly(Side.CLIENT)
public IIcon getIcon(int side, int meta)
{
return side == 1 ? this.topTextures : (side == 0 ? this.topTextures : (side != meta ? this.blockIcon : this.frontTexture));
}
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iconRegister)
{
this.blockIcon = iconRegister.registerIcon("soul_extractor_side");
this.frontTexture = iconRegister.registerIcon(this.isWorking ? "soul_extractor_front_on" : "soul_extractor_front_off");
this.topTextures = iconRegister.registerIcon("soul_extractor_top");
}
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par1, float par2, float par3, float par4)
{
if (world.isRemote)
{
return true;
}
else
{
TileEntitySoulExtractor tileEntitySoulExtractor = (TileEntitySoulExtractor) world.getTileEntity(x, y, z);
if (tileEntitySoulExtractor != null)
{
player.openGui(CraftableCreatures.INSTANCE, CraftableCreatures.GUI_SOUL_EXTRACTOR, world, x, y, z);
}
return true;
}
}
public static void updateSoulExtractorBlockState(boolean isLitNow, World world, int x, int y, int z)
{
int l = world.getBlockMetadata(x, y, z);
TileEntity tileentity = world.getTileEntity(x, y, z);
isLit = true;
if (isLitNow)
{
world.setBlock(x, y, z, CCBlocks.lit_soul_extractor);
}
else
{
world.setBlock(x, y, z, CCBlocks.soul_extractor);
}
isLit = false;
world.setBlockMetadataWithNotify(x, y, z, l, 2);
if (tileentity != null)
{
tileentity.validate();
world.setTileEntity(x, y, z, tileentity);
}
}
public TileEntity createNewTileEntity(World world, int par1)
{
return new TileEntitySoulExtractor();
}
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLivingBase, ItemStack stack)
{
int l = MathHelper.floor_double((double)(entityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
if (l == 0)
{
world.setBlockMetadataWithNotify(x, y, z, 2, 2);
}
if (l == 1)
{
world.setBlockMetadataWithNotify(x, y, z, 5, 2);
}
if (l == 2)
{
world.setBlockMetadataWithNotify(x, y, z, 3, 2);
}
if (l == 3)
{
world.setBlockMetadataWithNotify(x, y, z, 4, 2);
}
if (stack.hasDisplayName())
{
((TileEntitySoulExtractor)world.getTileEntity(x, y, z)).func_145951_a(stack.getDisplayName());
}
}
public void breakBlock(World world, int x, int y, int z, Block block, int par1)
{
if (!isLit)
{
TileEntitySoulExtractor tileEntitySoulExtractor = (TileEntitySoulExtractor) world.getTileEntity(x, y, z);
if (tileEntitySoulExtractor != null)
{
for (int i1 = 0; i1 < tileEntitySoulExtractor.getSizeInventory(); ++i1)
{
ItemStack itemstack = tileEntitySoulExtractor.getStackInSlot(i1);
if (itemstack != null)
{
float f = this.rnd.nextFloat() * 0.8F + 0.1F;
float f1 = this.rnd.nextFloat() * 0.8F + 0.1F;
float f2 = this.rnd.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0)
{
int j1 = this.rnd.nextInt(21) + 10;
if (j1 > itemstack.stackSize)
{
j1 = itemstack.stackSize;
}
itemstack.stackSize -= j1;
EntityItem entityitem = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage()));
if (itemstack.hasTagCompound())
{
entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
}
float f3 = 0.05F;
entityitem.motionX = (double)((float)this.rnd.nextGaussian() * f3);
entityitem.motionY = (double)((float)this.rnd.nextGaussian() * f3 + 0.2F);
entityitem.motionZ = (double)((float)this.rnd.nextGaussian() * f3);
world.spawnEntityInWorld(entityitem);
}
}
}
world.func_147453_f(x, y, z, block);
}
}
super.breakBlock(world, x, y, z, block, par1);
}
@SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, int x, int y, int z, Random random)
{
if (this.isWorking)
{
int l = world.getBlockMetadata(x, y, z);
float f = (float)x + 0.5F;
float f1 = (float)y + 0.0F + random.nextFloat() * 6.0F / 16.0F;
float f2 = (float)z + 0.5F;
float f3 = 0.52F;
float f4 = random.nextFloat() * 0.6F - 0.3F;
if (l == 4)
{
Minecraft.getMinecraft().effectRenderer.addEffect(new EntitySoulFX(world, f - f3, f1, f2 + f4));
world.spawnParticle("flame", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
}
else if (l == 5)
{
world.spawnParticle("smoke", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
}
else if (l == 2)
{
world.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
}
else if (l == 3)
{
world.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
world.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
}
}
}
public boolean hasComparatorInputOverride()
{
return true;
}
public int getComparatorInputOverride(World world, int x, int y, int z, int par1)
{
return Container.calcRedstoneFromInventory((IInventory)world.getTileEntity(x, y, z));
}
@SideOnly(Side.CLIENT)
public Item getItem(World world, int x, int y, int z)
{
return Item.getItemFromBlock(CCBlocks.soul_extractor);
}
}
Java:
public class TileEntitySoulExtractor extends TileEntity implements ISidedInventory {
private static final int[] slotsTop = new int[] {0};
private static final int[] slotsBottom = new int[] {2, 1};
private static final int[] slotsSides = new int[] {1};
private ItemStack[] soulExtractorItemStacks = new ItemStack[3];
public int soulExtractorBurnTime;
public int currentItemBurnTime;
public int soulExtractorCookTime;
private String invName;
public int getSizeInventory()
{
return this.soulExtractorItemStacks.length;
}
public ItemStack getStackInSlot(int slot)
{
return this.soulExtractorItemStacks[slot];
}
public ItemStack decrStackSize(int slot, int specNumber)
{
if (this.soulExtractorItemStacks[slot] != null)
{
ItemStack itemStack;
if (this.soulExtractorItemStacks[slot].stackSize <= specNumber)
{
itemStack = this.soulExtractorItemStacks[slot];
this.soulExtractorItemStacks[slot] = null;
return itemStack;
}
else
{
itemStack = this.soulExtractorItemStacks[slot].splitStack(specNumber);
if (this.soulExtractorItemStacks[slot].stackSize == 0)
{
this.soulExtractorItemStacks[slot] = null;
}
return itemStack;
}
}
else
{
return null;
}
}
public ItemStack getStackInSlotOnClosing(int slot)
{
if (this.soulExtractorItemStacks[slot] != null)
{
ItemStack itemstack = this.soulExtractorItemStacks[slot];
this.soulExtractorItemStacks[slot] = null;
return itemstack;
}
else
{
return null;
}
}
public void setInventorySlotContents(int slot, ItemStack contents)
{
this.soulExtractorItemStacks[slot] = contents;
if (contents != null && contents.stackSize > this.getInventoryStackLimit())
{
contents.stackSize = this.getInventoryStackLimit();
}
}
public String getInventoryName()
{
return this.hasCustomInventoryName() ? this.invName : "container.soulExtractor";
}
public boolean hasCustomInventoryName()
{
return this.invName != null && this.invName.length() > 0;
}
public void func_145951_a(String name)
{
this.invName = name;
}
public void readFromNBT(NBTTagCompound nbtTagCompound)
{
super.readFromNBT(nbtTagCompound);
NBTTagList nbtTagList = nbtTagCompound.getTagList("Items", 10);
this.soulExtractorItemStacks = new ItemStack[this.getSizeInventory()];
for (int i = 0; i < nbtTagList.tagCount(); ++i)
{
NBTTagCompound nbtTagCompound1 = nbtTagList.getCompoundTagAt(i);
byte b0 = nbtTagCompound1.getByte("Slot");
if (b0 >= 0 && b0 < this.soulExtractorItemStacks.length)
{
this.soulExtractorItemStacks[b0] = ItemStack.loadItemStackFromNBT(nbtTagCompound1);
}
}
this.soulExtractorBurnTime = nbtTagCompound.getShort("BurnTime");
this.soulExtractorCookTime = nbtTagCompound.getShort("CookTime");
this.currentItemBurnTime = getItemBurnTime(this.soulExtractorItemStacks[1]);
if (nbtTagCompound.hasKey("CustomName", 8))
{
this.invName = nbtTagCompound.getString("CustomName");
}
}
public void writeToNBT(NBTTagCompound nbtTagCompound)
{
super.writeToNBT(nbtTagCompound);
nbtTagCompound.setShort("BurnTime", (short)this.soulExtractorBurnTime);
nbtTagCompound.setShort("CookTime", (short)this.soulExtractorCookTime);
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < this.soulExtractorItemStacks.length; ++i)
{
if (this.soulExtractorItemStacks[i] != null)
{
NBTTagCompound nbtTagCompound1 = new NBTTagCompound();
nbtTagCompound1.setByte("Slot", (byte)i);
this.soulExtractorItemStacks[i].writeToNBT(nbtTagCompound1);
nbttaglist.appendTag(nbtTagCompound1);
}
}
nbtTagCompound.setTag("Items", nbttaglist);
if (this.hasCustomInventoryName())
{
nbtTagCompound.setString("CustomName", this.invName);
}
}
public int getInventoryStackLimit()
{
return 64;
}
@SideOnly(Side.CLIENT)
public int getCookProgressScaled(int scale)
{
return this.soulExtractorCookTime * scale / 200;
}
@SideOnly(Side.CLIENT)
public int getBurnTimeRemainingScaled(int scale)
{
if (this.currentItemBurnTime == 0)
{
this.currentItemBurnTime = 200;
}
return this.soulExtractorBurnTime * scale / this.currentItemBurnTime;
}
public boolean isBurning()
{
return this.soulExtractorBurnTime > 0;
}
public void updateEntity()
{
boolean flag = this.soulExtractorBurnTime > 0;
boolean flag1 = false;
if (this.soulExtractorBurnTime > 0)
{
--this.soulExtractorBurnTime;
}
if (!this.worldObj.isRemote)
{
if (this.soulExtractorBurnTime != 0 || this.soulExtractorItemStacks[1] != null && this.soulExtractorItemStacks[0] != null)
{
if (this.soulExtractorBurnTime == 0 && this.canSmelt())
{
this.currentItemBurnTime = this.soulExtractorBurnTime = getItemBurnTime(this.soulExtractorItemStacks[1]);
if (this.soulExtractorBurnTime > 0)
{
flag1 = true;
if (this.soulExtractorItemStacks[1] != null)
{
--this.soulExtractorItemStacks[1].stackSize;
if (this.soulExtractorItemStacks[1].stackSize == 0)
{
this.soulExtractorItemStacks[1] = soulExtractorItemStacks[1].getItem().getContainerItem(soulExtractorItemStacks[1]);
}
}
}
}
if (this.isBurning() && this.canSmelt())
{
++this.soulExtractorCookTime;
if (this.soulExtractorCookTime == 200)
{
this.soulExtractorCookTime = 0;
this.smeltItem();
flag1 = true;
}
}
else
{
this.soulExtractorCookTime = 0;
}
}
if (flag != this.soulExtractorBurnTime > 0)
{
flag1 = true;
BlockSoulExtractor.updateSoulExtractorBlockState(this.soulExtractorBurnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
}
}
if (flag1)
{
this.markDirty();
}
}
private boolean canSmelt()
{
if (this.soulExtractorItemStacks[0] == null)
{
return false;
}
else
{
ItemStack itemStack = SoulExtractorRecipes.extracting().getExtractingResult(this.soulExtractorItemStacks[0]);
if (itemStack == null) return false;
if (this.soulExtractorItemStacks[2] == null) return true;
if (!this.soulExtractorItemStacks[2].isItemEqual(itemStack)) return false;
int result = soulExtractorItemStacks[2].stackSize + itemStack.stackSize;
return result <= getInventoryStackLimit() && result <= this.soulExtractorItemStacks[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly.
}
}
public void smeltItem()
{
if (this.canSmelt())
{
ItemStack itemstack = SoulExtractorRecipes.extracting().getExtractingResult(this.soulExtractorItemStacks[0]);
if (this.soulExtractorItemStacks[2] == null)
{
this.soulExtractorItemStacks[2] = itemstack.copy();
}
else if (this.soulExtractorItemStacks[2].getItem() == itemstack.getItem())
{
this.soulExtractorItemStacks[2].stackSize += itemstack.stackSize;
}
--this.soulExtractorItemStacks[0].stackSize;
if (this.soulExtractorItemStacks[0].stackSize <= 0)
{
this.soulExtractorItemStacks[0] = null;
}
}
}
public static int getItemBurnTime(ItemStack fuel)
{
if (fuel == null)
{
return 0;
}
else
{
int moddedBurnTime = net.minecraftforge.event.ForgeEventFactory.getFuelBurnTime(fuel);
if (moddedBurnTime >= 0) return moddedBurnTime;
Item item = fuel.getItem();
if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air)
{
Block block = Block.getBlockFromItem(item);
if (block == CCBlocks.bluestone_block)
{
return 16000;
}
}
if (item == CCItems.bluestone) return 1600;
return GameRegistry.getFuelValue(fuel);
}
}
public static boolean isItemFuel(ItemStack stack)
{
return getItemBurnTime(stack) > 0;
}
public boolean isUseableByPlayer(EntityPlayer player)
{
return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) == this && player.getDistanceSq((double) this.xCoord + 0.5D, (double) this.yCoord + 0.5D, (double) this.zCoord + 0.5D) <= 64.0D;
}
public void openInventory() { }
public void closeInventory() { }
public boolean isItemValidForSlot(int slot, ItemStack stack)
{
return slot == 2 ? false : (slot == 1 ? isItemFuel(stack) : true);
}
public int[] getAccessibleSlotsFromSide(int slot)
{
return slot == 0 ? slotsBottom : (slot == 1 ? slotsTop : slotsSides);
}
public boolean canInsertItem(int slot, ItemStack stack, int count)
{
return this.isItemValidForSlot(slot, stack);
}
public boolean canExtractItem(int slot, ItemStack stack, int count)
{
return count != 0 || slot != 1;
}
}
[/SPOILER]
[SPOILER="CommonProxy"]
[CODE=java]
@SideOnly(Side.CLIENT)
public class ClientProxy extends CommonProxy {
public void preInit(FMLPreInitializationEvent event) {
CraftableCreatures.configDir = event.getModConfigurationDirectory().toString();
CCConfigHandler.register(CraftableCreatures.configDir);
FMLCommonHandler.instance().bus().register(new CCConfigHandler());
FMLCommonHandler.instance().bus().register(new CCFMLEventListener());
FMLLog.info("Craftable Creatures config loaded");
CCItems.register();
FMLLog.info("CC Items loaded");
CCBlocks.register();
FMLLog.info("CC Blocks loaded");
CCTileEntities.register();
FMLLog.info("CC Tile entities loaded");
CCWorldGenVines.register();
FMLLog.info("CC Ore generation loaded");
CCAchievementList.register();
FMLLog.info("CC Achievements loaded");
for (int i = 0; i < 5; i++) {
VillagerRegistry.instance().registerVillageTradeHandler(i, new TradeHandler());
}
FMLLog.info("CC Villager trades loaded");
super.preInit(event);
FMLLog.info("Pre initialization of Craftable Creatures complete");
}
public void init(FMLInitializationEvent event) {
CCRenderers.registerItemRenderers();
FMLLog.info("CC Item renderers loaded");
super.init(event);
FMLLog.info("Initialization of Craftable Creatures complete");
}
public void postInit(FMLPostInitializationEvent event) {
CCRecipes.register();
CCOreDictionary.register();
FMLLog.info("CC Recipes loaded");
super.postInit(event);
FMLLog.info("Post initialization of Craftable Creatures complete");
}
}
Java:
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
if (ID == CraftableCreatures.GUI_SOUL_EXTRACTOR)
{
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileEntitySoulExtractor)
{
return new ContainerSoulExtractor(player.inventory, (TileEntitySoulExtractor) tile);
}
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
if (ID == CraftableCreatures.GUI_SOUL_EXTRACTOR)
{
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileEntitySoulExtractor)
{
return new GuiSoulExtractor(player.inventory, (TileEntitySoulExtractor) tile);
}
}
return null;
}
Java:
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import ru.wertyfiregames.craftablecreatures.recipe.SoulExtractorRecipes;
import ru.wertyfiregames.craftablecreatures.tile.TileEntitySoulExtractor;
public class ContainerSoulExtractor extends Container
{
private TileEntitySoulExtractor tileSoulExtractor;
private int lastCookTime, lastBurnTime, lastItemBurnTime;
public ContainerSoulExtractor(InventoryPlayer inv, TileEntitySoulExtractor tile)
{
this.tileSoulExtractor = tile;
this.addSlotToContainer(new Slot(tile, 0, 56, 17));
this.addSlotToContainer(new Slot(tile, 1, 56, 53));
this.addSlotToContainer(new SlotSoulExtractor(inv.player, tile, 2, 116, 35));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
this.addSlotToContainer(new Slot(tile, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (int i = 0; i < 9; i++) {
this.addSlotToContainer(new Slot(tile, i, 8 + i * 18, 142));
}
}
@Override
public void addCraftingToCrafters(ICrafting iCrafting) {
super.addCraftingToCrafters(iCrafting);
iCrafting.sendProgressBarUpdate(this, 0, this.tileSoulExtractor.soulExtractorCookTime);
iCrafting.sendProgressBarUpdate(this, 1, this.tileSoulExtractor.soulExtractorBurnTime);
iCrafting.sendProgressBarUpdate(this, 2, this.tileSoulExtractor.currentItemBurnTime);
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < this.crafters.size(); i++) {
ICrafting iCrafting = (ICrafting) this.crafters.get(i);
if (this.lastCookTime != this.tileSoulExtractor.soulExtractorCookTime) {
iCrafting.sendProgressBarUpdate(this, 0, this.tileSoulExtractor.soulExtractorCookTime);
}
if (this.lastBurnTime != this.tileSoulExtractor.soulExtractorBurnTime) {
iCrafting.sendProgressBarUpdate(this, 1, this.tileSoulExtractor.soulExtractorBurnTime);
}
if (this.lastItemBurnTime != this.tileSoulExtractor.currentItemBurnTime) {
iCrafting.sendProgressBarUpdate(this, 2, this.tileSoulExtractor.currentItemBurnTime);
}
}
this.lastCookTime = this.tileSoulExtractor.soulExtractorCookTime;
this.lastBurnTime = this.tileSoulExtractor.soulExtractorBurnTime;
this.lastItemBurnTime = this.tileSoulExtractor.currentItemBurnTime;
}
@SideOnly(Side.CLIENT)
@Override
public void updateProgressBar(int bar, int progress) {
if (bar == 0) {
this.tileSoulExtractor.soulExtractorCookTime = progress;
}
if (bar == 1) {
this.tileSoulExtractor.soulExtractorBurnTime = progress;
}
if (bar == 2) {
this.tileSoulExtractor.currentItemBurnTime = progress;
}
}
@Override
public boolean canInteractWith(EntityPlayer player) {
return this.tileSoulExtractor.isUseableByPlayer(player);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotNum) {
ItemStack itemStack = null;
Slot slot = (Slot) this.inventorySlots.get(slotNum);
if (slot != null && slot.getHasStack()) {
ItemStack itemStack1 = slot.getStack();
itemStack = itemStack1.copy();
if (slotNum == 2) {
if (!this.mergeItemStack(itemStack1, 3, 39, true)) {
return null;
}
slot.onSlotChange(itemStack1, itemStack);
} else if (slotNum != 1 && slotNum != 0) {
if (SoulExtractorRecipes.extracting().getExtractingResult(itemStack1) != null) {
if (!this.mergeItemStack(itemStack1, 0, 1, false)) {
return null;
}
} else if (TileEntitySoulExtractor.isItemFuel(itemStack1)) {
if (!this.mergeItemStack(itemStack1, 1, 2, false)) {
return null;
}
} else if (slotNum >= 30 && slotNum < 39 && !this.mergeItemStack(itemStack1, 3, 30, false)) {
return null;
}
} else if (!this.mergeItemStack(itemStack1, 3, 39, false)) {
return null;
}
if (itemStack1.stackSize == 0)
{
slot.putStack(null);
}
else
{
slot.onSlotChanged();
}
if (itemStack1.stackSize == itemStack.stackSize)
{
return null;
}
slot.onPickupFromSlot(player, itemStack1);
}
return itemStack;
}
}
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import ru.wertyfiregames.craftablecreatures.CraftableCreatures;
import ru.wertyfiregames.craftablecreatures.inventory.ContainerSoulExtractor;
import ru.wertyfiregames.craftablecreatures.tile.TileEntitySoulExtractor;
@SideOnly(Side.CLIENT)
public class GuiSoulExtractor extends GuiContainer
{
private static final ResourceLocation soulExtractorGuiTextures = new ResourceLocation(CraftableCreatures.getModId(), "textures/gui/container/soul_extractor.png");
private TileEntitySoulExtractor tileSoulExtractor;
public GuiSoulExtractor(InventoryPlayer inv, TileEntitySoulExtractor tile)
{
super(new ContainerSoulExtractor(inv, tile));
}
@Override
protected void drawGuiContainerForegroundLayer(int x, int y)
{
String s = this.tileSoulExtractor.hasCustomInventoryName() ? this.tileSoulExtractor.getInventoryName() : I18n.format(this.tileSoulExtractor.getInventoryName());
this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int x, int y)
{
GL11.glColor4f(1f, 1f, 1f, 1f);
this.mc.getTextureManager().bindTexture(soulExtractorGuiTextures);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
if (this.tileSoulExtractor.isBurning())
{
int i1 = this.tileSoulExtractor.getBurnTimeRemainingScaled(13);
this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 1);
i1 = this.tileSoulExtractor.getCookProgressScaled(24);
this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16);
}
}
}
[/CODE]
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import ru.wertyfiregames.craftablecreatures.CraftableCreatures;
import ru.wertyfiregames.craftablecreatures.inventory.ContainerSoulExtractor;
import ru.wertyfiregames.craftablecreatures.tile.TileEntitySoulExtractor;
@SideOnly(Side.CLIENT)
public class GuiSoulExtractor extends GuiContainer
{
private static final ResourceLocation soulExtractorGuiTextures = new ResourceLocation(CraftableCreatures.getModId(), "textures/gui/container/soul_extractor.png");
private TileEntitySoulExtractor tileSoulExtractor;
public GuiSoulExtractor(InventoryPlayer inv, TileEntitySoulExtractor tile)
{
super(new ContainerSoulExtractor(inv, tile));
}
@Override
protected void drawGuiContainerForegroundLayer(int x, int y)
{
String s = this.tileSoulExtractor.hasCustomInventoryName() ? this.tileSoulExtractor.getInventoryName() : I18n.format(this.tileSoulExtractor.getInventoryName());
this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int x, int y)
{
GL11.glColor4f(1f, 1f, 1f, 1f);
this.mc.getTextureManager().bindTexture(soulExtractorGuiTextures);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
if (this.tileSoulExtractor.isBurning())
{
int i1 = this.tileSoulExtractor.getBurnTimeRemainingScaled(13);
this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 1);
i1 = this.tileSoulExtractor.getCookProgressScaled(24);
this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16);
}
}
}
[/CODE]
NetworkRegistry.INSTANCE.regosterGuiHandler(this, new CommonProxy()); есть
p.s. код копировал с печки и изменял под мой блок
- Краш-лог
-
---- Minecraft Crash Report ----
// Don't do that.
Time: 29.11.23 19:36
Description: Ticking memory connection
java.lang.ArrayIndexOutOfBoundsException: 9
at ru.wertyfiregames.craftablecreatures.tile.TileEntitySoulExtractor.getStackInSlot(TileEntitySoulExtractor.java:40)
at net.minecraft.inventory.Slot.getStack(Slot.java:88)
at net.minecraft.inventory.Container.getInventory(Container.java:67)
at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:53)
at ru.wertyfiregames.craftablecreatures.inventory.ContainerSoulExtractor.addCraftingToCrafters(ContainerSoulExtractor.java:44)
at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501)
at ru.wertyfiregames.craftablecreatures.block.BlockSoulExtractor.onBlockActivated(BlockSoulExtractor.java:120)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:409)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at ru.wertyfiregames.craftablecreatures.tile.TileEntitySoulExtractor.getStackInSlot(TileEntitySoulExtractor.java:40)
at net.minecraft.inventory.Slot.getStack(Slot.java:88)
at net.minecraft.inventory.Container.getInventory(Container.java:67)
at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:53)
at ru.wertyfiregames.craftablecreatures.inventory.ContainerSoulExtractor.addCraftingToCrafters(ContainerSoulExtractor.java:44)
at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501)
at ru.wertyfiregames.craftablecreatures.block.BlockSoulExtractor.onBlockActivated(BlockSoulExtractor.java:120)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:409)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
-- Ticking connection --
Details:
Connection: net.minecraft.network.NetworkManager@70c5a701
Stacktrace:
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)
-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 10 (amd64) version 10.0
Java Version: 1.8.0_241, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 358092936 bytes (341 MB) / 632815616 bytes (603 MB) up to 1398276096 bytes (1333 MB)
JVM Flags: 0 total;
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1614 6 mods loaded, 6 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
UCHIJAAAAAAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar)
UCHIJAAAAAAAAA FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar)
UCHIJAAAAAAAAA Forge{10.13.4.1614} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar)
UCHIJAAAAAAAAA CodeChickenCore{1.0.7.48} [CodeChicken Core] (minecraft.jar)
UCHIJAAAAAAAAA NotEnoughItems{1.0.5.120} [Not Enough Items] (NotEnoughItems-1.7.10-1.0.5.120-universal.jar)
UCHIJAAAAAAAAA craftable_creatures{beta-0.1.3(05)-1.7.10} [Craftable Creatures] (CraftableCreatures-0.2.0b (05).jar)
GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['Player76'/733, l='TileEntitiesTest', x=-64,27, y=64,00, z=281,75]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'
Краш-лог:
---- Minecraft Crash Report ----
// Don't do that.
Time: 29.11.23 19:36
Description: Ticking memory connection
java.lang.ArrayIndexOutOfBoundsException: 9
at ru.wertyfiregames.craftablecreatures.tile.TileEntitySoulExtractor.getStackInSlot(TileEntitySoulExtractor.java:40)
at net.minecraft.inventory.Slot.getStack(Slot.java:88)
at net.minecraft.inventory.Container.getInventory(Container.java:67)
at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:53)
at ru.wertyfiregames.craftablecreatures.inventory.ContainerSoulExtractor.addCraftingToCrafters(ContainerSoulExtractor.java:44)
at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501)
at ru.wertyfiregames.craftablecreatures.block.BlockSoulExtractor.onBlockActivated(BlockSoulExtractor.java:120)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:409)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)
A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------
-- Head --
Stacktrace:
at ru.wertyfiregames.craftablecreatures.tile.TileEntitySoulExtractor.getStackInSlot(TileEntitySoulExtractor.java:40)
at net.minecraft.inventory.Slot.getStack(Slot.java:88)
at net.minecraft.inventory.Container.getInventory(Container.java:67)
at net.minecraft.inventory.Container.addCraftingToCrafters(Container.java:53)
at ru.wertyfiregames.craftablecreatures.inventory.ContainerSoulExtractor.addCraftingToCrafters(ContainerSoulExtractor.java:44)
at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:88)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501)
at ru.wertyfiregames.craftablecreatures.block.BlockSoulExtractor.onBlockActivated(BlockSoulExtractor.java:120)
at net.minecraft.server.management.ItemInWorldManager.activateBlockOrUseItem(ItemInWorldManager.java:409)
at net.minecraft.network.NetHandlerPlayServer.processPlayerBlockPlacement(NetHandlerPlayServer.java:593)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:74)
at net.minecraft.network.play.client.C08PacketPlayerBlockPlacement.processPacket(C08PacketPlayerBlockPlacement.java:122)
at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:241)
-- Ticking connection --
Details:
Connection: net.minecraft.network.NetworkManager@70c5a701
Stacktrace:
at net.minecraft.network.NetworkSystem.networkTick(NetworkSystem.java:182)
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:726)
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)
-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 10 (amd64) version 10.0
Java Version: 1.8.0_241, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 358092936 bytes (341 MB) / 632815616 bytes (603 MB) up to 1398276096 bytes (1333 MB)
JVM Flags: 0 total;
AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
IntCache: cache: 0, tcache: 0, allocated: 13, tallocated: 95
FML: MCP v9.05 FML v7.10.99.99 Minecraft Forge 10.13.4.1614 6 mods loaded, 6 mods active
States: 'U' = Unloaded 'L' = Loaded 'C' = Constructed 'H' = Pre-initialized 'I' = Initialized 'J' = Post-initialized 'A' = Available 'D' = Disabled 'E' = Errored
UCHIJAAAAAAAAA mcp{9.05} [Minecraft Coder Pack] (minecraft.jar)
UCHIJAAAAAAAAA FML{7.10.99.99} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar)
UCHIJAAAAAAAAA Forge{10.13.4.1614} [Minecraft Forge] (forgeSrc-1.7.10-10.13.4.1614-1.7.10.jar)
UCHIJAAAAAAAAA CodeChickenCore{1.0.7.48} [CodeChicken Core] (minecraft.jar)
UCHIJAAAAAAAAA NotEnoughItems{1.0.5.120} [Not Enough Items] (NotEnoughItems-1.7.10-1.0.5.120-universal.jar)
UCHIJAAAAAAAAA craftable_creatures{beta-0.1.3(05)-1.7.10} [Craftable Creatures] (CraftableCreatures-0.2.0b (05).jar)
GL info: ~~ERROR~~ RuntimeException: No OpenGL context found in the current thread.
Profiler Position: N/A (disabled)
Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used
Player Count: 1 / 8; [EntityPlayerMP['Player76'/733, l='TileEntitiesTest', x=-64,27, y=64,00, z=281,75]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'