Jump to content

Recommended Posts

Posted

 

Caused by: java.lang.IndexOutOfBoundsException: Index: 36, Size: 36

at java.util.ArrayList.rangeCheck(Unknown Source) ~[?:1.7.0_71]

at java.util.ArrayList.get(Unknown Source) ~[?:1.7.0_71]

at net.minecraft.inventory.Container.getSlot(Container.java:138) ~[Container.class:?]

at net.minecraft.inventory.Container.putStacksInSlots(Container.java:574) ~[Container.class:?]

at net.minecraft.client.network.NetHandlerPlayClient.handleWindowItems(NetHandlerPlayClient.java:1210) ~[NetHandlerPlayClient.class:?]

at net.minecraft.network.play.server.S30PacketWindowItems.func_180732_a(S30PacketWindowItems.java:67) ~[s30PacketWindowItems.class:?]

at net.minecraft.network.play.server.S30PacketWindowItems.processPacket(S30PacketWindowItems.java:81) ~[s30PacketWindowItems.class:?]

at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:24) ~[PacketThreadUtil$1.class:?]

at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.7.0_71]

at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.7.0_71]

at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(FMLCommonHandler.java:709) ~[FMLCommonHandler.class:?]

... 11 more

 

 

I need help for this!!

Posted

yap the error says it

 

at net.minecraft.inventory.Container.getSlot(Container.java:138) ~[Container.class:?]

 

begins in the line 138 from Container.java

but this one could be before

 

whitouth see code and whith this 36,  iam 80% thath there is a "for" to scan the player inventory and is set to

for (int x=0;  x <= inventorysize; x++)  when it must be only  x < inventorysize 

Posted

My Tile Entity

 

package stevekung.mods.moreplanets.planets.fronos.tileentities;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.inventory.Container;

import net.minecraft.inventory.IInventory;

import net.minecraft.inventory.ISidedInventory;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.nbt.NBTTagList;

import net.minecraft.server.gui.IUpdatePlayerListBox;

import net.minecraft.tileentity.TileEntityLockable;

import net.minecraft.util.EnumChatFormatting;

import net.minecraft.util.EnumFacing;

import net.minecraft.util.MathHelper;

import net.minecraft.util.StatCollector;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

import stevekung.mods.moreplanets.common.recipe.CandyExtractorRecipes;

import stevekung.mods.moreplanets.planets.fronos.blocks.BlockCandyExtractor;

import stevekung.mods.moreplanets.planets.fronos.inventory.container.ContainerCandyExtractor;

import stevekung.mods.moreplanets.planets.fronos.items.FronosItems;

 

public class TileEntityCandyExtractor extends TileEntityLockable implements IUpdatePlayerListBox, ISidedInventory

{

private static int[] slotsTop = new int[] {0};

private static int[] slotsBottom = new int[] {2, 1};

private static int[] slotsSides = new int[] {1};

private ItemStack[] itemStacks = new ItemStack[3];

private int burnTime;

private int currentItemBurnTime;

private int cookTime;

private int totalCookTime;

 

@Override

public int getSizeInventory()

{

return this.itemStacks.length;

}

 

@Override

public ItemStack getStackInSlot(int index)

{

return this.itemStacks[index];

}

 

@Override

public ItemStack decrStackSize(int index, int count)

{

if (this.itemStacks[index] != null)

{

ItemStack itemstack;

 

if (this.itemStacks[index].stackSize <= count)

{

itemstack = this.itemStacks[index];

this.itemStacks[index] = null;

return itemstack;

}

else

{

itemstack = this.itemStacks[index].splitStack(count);

 

if (this.itemStacks[index].stackSize == 0)

{

this.itemStacks[index] = null;

}

return itemstack;

}

}

else

{

return null;

}

}

 

@Override

public ItemStack getStackInSlotOnClosing(int index)

{

if (this.itemStacks[index] != null)

{

ItemStack itemstack = this.itemStacks[index];

this.itemStacks[index] = null;

return itemstack;

}

else

{

return null;

}

}

 

@Override

public void setInventorySlotContents(int index, ItemStack stack)

{

boolean flag = stack != null && stack.isItemEqual(this.itemStacks[index]) && ItemStack.areItemStackTagsEqual(stack, this.itemStacks[index]);

this.itemStacks[index] = stack;

 

if (stack != null && stack.stackSize > this.getInventoryStackLimit())

{

stack.stackSize = this.getInventoryStackLimit();

}

if (index == 0 && !flag)

{

this.totalCookTime = this.func_174904_a(stack);

this.cookTime = 0;

this.markDirty();

}

}

 

@Override

public String getName()

{

return EnumChatFormatting.DARK_BLUE + StatCollector.translateToLocal("container.candy.extractor.name");

}

 

@Override

public boolean hasCustomName()

{

return false;

}

 

@Override

public void readFromNBT(NBTTagCompound nbt)

{

super.readFromNBT(nbt);

NBTTagList nbttaglist = nbt.getTagList("Items", 10);

this.itemStacks = 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.itemStacks.length)

{

this.itemStacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);

}

}

this.burnTime = nbt.getShort("BurnTime");

this.cookTime = nbt.getShort("CookTime");

this.totalCookTime = nbt.getShort("CookTimeTotal");

this.currentItemBurnTime = getItemBurnTime(this.itemStacks[1]);

}

 

@Override

public void writeToNBT(NBTTagCompound nbt)

{

super.writeToNBT(nbt);

nbt.setShort("BurnTime", (short)this.burnTime);

nbt.setShort("CookTime", (short)this.cookTime);

nbt.setShort("CookTimeTotal", (short)this.totalCookTime);

NBTTagList nbttaglist = new NBTTagList();

 

for (int i = 0; i < this.itemStacks.length; ++i)

{

if (this.itemStacks != null)

{

NBTTagCompound nbttagcompound1 = new NBTTagCompound();

nbttagcompound1.setByte("Slot", (byte)i);

this.itemStacks.writeToNBT(nbttagcompound1);

nbttaglist.appendTag(nbttagcompound1);

}

}

nbt.setTag("Items", nbttaglist);

}

 

@Override

public int getInventoryStackLimit()

{

return 64;

}

 

public boolean isBurning()

{

return this.burnTime > 0;

}

 

@SideOnly(Side.CLIENT)

public static boolean isBurning(IInventory inv)

{

return inv.getField(0) > 0;

}

 

@Override

public void update()

{

boolean flag = this.isBurning();

boolean flag1 = false;

 

if (this.isBurning())

{

--this.burnTime;

}

 

if (!this.worldObj.isRemote)

{

if (!this.isBurning() && (this.itemStacks[1] == null || this.itemStacks[0] == null))

{

if (!this.isBurning() && this.cookTime > 0)

{

this.cookTime = MathHelper.clamp_int(this.cookTime - 2, 0, this.totalCookTime);

}

}

else

{

if (!this.isBurning() && this.canSmelt())

{

this.currentItemBurnTime = this.burnTime = getItemBurnTime(this.itemStacks[1]);

 

if (this.isBurning())

{

flag1 = true;

 

if (this.itemStacks[1] != null)

{

--this.itemStacks[1].stackSize;

 

if (this.itemStacks[1].stackSize == 0)

{

this.itemStacks[1] = this.itemStacks[1].getItem().getContainerItem(this.itemStacks[1]);

}

}

}

}

 

if (this.isBurning() && this.canSmelt())

{

++this.cookTime;

 

if (this.cookTime == this.totalCookTime)

{

this.cookTime = 0;

this.totalCookTime = this.func_174904_a(this.itemStacks[0]);

this.smeltItem();

flag1 = true;

}

}

else

{

this.cookTime = 0;

}

}

 

if (flag != this.isBurning())

{

flag1 = true;

BlockCandyExtractor.setState(this.isBurning(), this.worldObj, this.pos);

}

}

 

if (flag1)

{

this.markDirty();

}

}

 

public int func_174904_a(ItemStack itemStack)

{

return 200;

}

 

private boolean canSmelt()

{

if (this.itemStacks[0] == null)

{

return false;

}

else

{

ItemStack itemstack = CandyExtractorRecipes.instance().getExtractingResult(this.itemStacks[0]);

 

if (itemstack == null)

{

return false;

}

if (this.itemStacks[2] == null)

{

return true;

}

if (!this.itemStacks[2].isItemEqual(itemstack))

{

return false;

}

int result = this.itemStacks[2].stackSize + itemstack.stackSize;

return result <= this.getInventoryStackLimit() && result <= this.itemStacks[2].getMaxStackSize();

}

}

 

public void smeltItem()

{

if (this.canSmelt())

{

ItemStack itemstack = CandyExtractorRecipes.instance().getExtractingResult(this.itemStacks[0]);

 

if (this.itemStacks[2] == null)

{

this.itemStacks[2] = itemstack.copy();

}

else if (this.itemStacks[2].getItem() == itemstack.getItem())

{

this.itemStacks[2].stackSize += itemstack.stackSize;

}

 

--this.itemStacks[0].stackSize;

 

if (this.itemStacks[0].stackSize <= 0)

{

this.itemStacks[0] = null;

}

}

}

 

public static int getItemBurnTime(ItemStack itemStack)

{

if (itemStack == null)

{

return 0;

}

else

{

if (itemStack.getItem() == FronosItems.fronos_item && itemStack.getItemDamage() == 1)

{

return 500;

}

}

return 0;

}

 

public static boolean isItemFuel(ItemStack itemStack)

{

return getItemBurnTime(itemStack) > 0;

}

 

@Override

public boolean isUseableByPlayer(EntityPlayer player)

{

return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq(this.pos.getX() + 0.5D, this.pos.getY() + 0.5D, this.pos.getZ() + 0.5D) <= 64.0D;

}

 

@Override

public void openInventory(EntityPlayer player) {}

 

@Override

public void closeInventory(EntityPlayer player) {}

 

@Override

public boolean isItemValidForSlot(int slot, ItemStack itemStack)

{

return slot == 2 ? false : slot == 1 ? TileEntityCandyExtractor.isItemFuel(itemStack) : true;

}

 

@Override

public int[] getSlotsForFace(EnumFacing side)

{

return side == EnumFacing.DOWN ? slotsBottom : side == EnumFacing.UP ? slotsTop : slotsSides;

}

 

@Override

public boolean canInsertItem(int index, ItemStack itemStack, EnumFacing direction)

{

return this.isItemValidForSlot(index, itemStack);

}

 

@Override

public boolean canExtractItem(int index, ItemStack itemStack, EnumFacing direction)

{

return true;

}

 

@Override

public String getGuiID()

{

return "moreplanets:candy_extractor";

}

 

@Override

public Container createContainer(InventoryPlayer playerInventory, EntityPlayer player)

{

return new ContainerCandyExtractor(playerInventory, this);

}

 

@Override

public int getField(int id)

{

switch (id)

{

case 0:

return this.burnTime;

case 1:

return this.currentItemBurnTime;

case 2:

return this.cookTime;

case 3:

return this.totalCookTime;

default:

return 0;

}

}

 

@Override

public void setField(int id, int value)

{

switch (id)

{

case 0:

this.burnTime = value;

break;

case 1:

this.currentItemBurnTime = value;

break;

case 2:

this.cookTime = value;

break;

case 3:

this.totalCookTime = value;

}

}

 

@Override

public int getFieldCount()

{

return 4;

}

 

@Override

public void clear()

{

for (int i = 0; i < this.itemStacks.length; ++i)

{

this.itemStacks = null;

}

}

}

 

 

My GUI

 

package stevekung.mods.moreplanets.planets.fronos.client.gui;

 

import net.minecraft.client.gui.inventory.GuiContainer;

import net.minecraft.client.renderer.GlStateManager;

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.inventory.IInventory;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

import stevekung.mods.moreplanets.planets.fronos.inventory.container.ContainerCandyExtractor;

import stevekung.mods.moreplanets.planets.fronos.tileentities.TileEntityCandyExtractor;

 

@SideOnly(Side.CLIENT)

public class GuiCandyExtractor extends GuiContainer

{

private ResourceLocation candyExtractorGuiTextures = new ResourceLocation("moreplanets:textures/gui/candy_extractor.png");

private InventoryPlayer playerInventory;

private IInventory tileFurnace;

 

public GuiCandyExtractor(InventoryPlayer playerInv, IInventory furnaceInv)

{

super(new ContainerCandyExtractor(playerInv, furnaceInv));

this.playerInventory = playerInv;

this.tileFurnace = furnaceInv;

}

 

@Override

protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)

{

String s = this.tileFurnace.getDisplayName().getUnformattedText();

this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);

this.fontRendererObj.drawString(this.playerInventory.getDisplayName().getUnformattedText(), 8, this.ySize - 96 + 2, 4210752);

}

 

@Override

protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)

{

GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);

this.mc.getTextureManager().bindTexture(this.candyExtractorGuiTextures);

int k = (this.width - this.xSize) / 2;

int l = (this.height - this.ySize) / 2;

this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);

int i1;

 

if (TileEntityCandyExtractor.isBurning(this.tileFurnace))

{

i1 = this.getBurnTimeRemainingScaled(13);

this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 1);

}

i1 = this.getCookProgressScaled(24);

this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16);

}

 

private int getCookProgressScaled(int time)

{

int j = this.tileFurnace.getField(2);

int k = this.tileFurnace.getField(3);

return k != 0 && j != 0 ? j * time / k : 0;

}

 

private int getBurnTimeRemainingScaled(int time)

{

int j = this.tileFurnace.getField(1);

 

if (j == 0)

{

j = 200;

}

return this.tileFurnace.getField(0) * time / j;

}

}

 

 

My Container

 

package stevekung.mods.moreplanets.planets.fronos.inventory.container;

 

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.IInventory;

import net.minecraft.inventory.Slot;

import net.minecraft.item.ItemStack;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

import stevekung.mods.moreplanets.common.recipe.CandyExtractorRecipes;

import stevekung.mods.moreplanets.planets.fronos.inventory.slot.SlotCandyExtractorFuel;

import stevekung.mods.moreplanets.planets.fronos.inventory.slot.SlotCandyExtractorOutput;

import stevekung.mods.moreplanets.planets.fronos.tileentities.TileEntityCandyExtractor;

 

public class ContainerCandyExtractor extends Container

{

private IInventory tileFurnace;

private int field_178152_f;

private int field_178153_g;

private int field_178154_h;

private int field_178155_i;

 

public ContainerCandyExtractor(InventoryPlayer p_i45794_1_, IInventory furnaceInventory)

{

this.tileFurnace = furnaceInventory;

this.addSlotToContainer(new Slot(furnaceInventory, 0, 56, 17));

this.addSlotToContainer(new SlotCandyExtractorFuel(furnaceInventory, 1, 56, 53));

this.addSlotToContainer(new SlotCandyExtractorOutput(p_i45794_1_.player, furnaceInventory, 2, 116, 35));

int i;

 

for (i = 0; i < 3; ++i)

{

for (int j = 0; j < 9; ++j)

{

this.addSlotToContainer(new Slot(p_i45794_1_, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));

}

}

 

for (i = 0; i < 9; ++i)

{

this.addSlotToContainer(new Slot(p_i45794_1_, i, 8 + i * 18, 142));

}

}

 

@Override

public void addCraftingToCrafters(ICrafting listener)

{

super.addCraftingToCrafters(listener);

listener.func_175173_a(this, this.tileFurnace);

}

 

@Override

public void detectAndSendChanges()

{

super.detectAndSendChanges();

 

for (int i = 0; i < this.crafters.size(); ++i)

{

ICrafting icrafting = (ICrafting)this.crafters.get(i);

 

if (this.field_178152_f != this.tileFurnace.getField(2))

{

icrafting.sendProgressBarUpdate(this, 2, this.tileFurnace.getField(2));

}

if (this.field_178154_h != this.tileFurnace.getField(0))

{

icrafting.sendProgressBarUpdate(this, 0, this.tileFurnace.getField(0));

}

if (this.field_178155_i != this.tileFurnace.getField(1))

{

icrafting.sendProgressBarUpdate(this, 1, this.tileFurnace.getField(1));

}

if (this.field_178153_g != this.tileFurnace.getField(3))

{

icrafting.sendProgressBarUpdate(this, 3, this.tileFurnace.getField(3));

}

}

this.field_178152_f = this.tileFurnace.getField(2);

this.field_178154_h = this.tileFurnace.getField(0);

this.field_178155_i = this.tileFurnace.getField(1);

this.field_178153_g = this.tileFurnace.getField(3);

}

 

@Override

@SideOnly(Side.CLIENT)

public void updateProgressBar(int id, int data)

{

this.tileFurnace.setField(id, data);

}

 

@Override

public boolean canInteractWith(EntityPlayer player)

{

return this.tileFurnace.isUseableByPlayer(player);

}

 

@Override

public ItemStack transferStackInSlot(EntityPlayer player, int index)

{

ItemStack itemstack = null;

Slot slot = (Slot)this.inventorySlots.get(index);

 

if (slot != null && slot.getHasStack())

{

ItemStack itemstack1 = slot.getStack();

itemstack = itemstack1.copy();

 

if (index == 2)

{

if (!this.mergeItemStack(itemstack1, 3, 39, true))

{

return null;

}

slot.onSlotChange(itemstack1, itemstack);

}

else if (index != 1 && index != 0)

{

if (CandyExtractorRecipes.instance().getExtractingResult(itemstack1) != null)

{

if (!this.mergeItemStack(itemstack1, 0, 1, false))

{

return null;

}

}

else if (TileEntityCandyExtractor.isItemFuel(itemstack1))

{

if (!this.mergeItemStack(itemstack1, 1, 2, false))

{

return null;

}

}

else if (index >= 3 && index < 30)

{

if (!this.mergeItemStack(itemstack1, 30, 39, false))

{

return null;

}

}

else if (index >= 30 && index < 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((ItemStack)null);

}

else

{

slot.onSlotChanged();

}

 

if (itemstack1.stackSize == itemstack.stackSize)

{

return null;

}

slot.onPickupFromSlot(player, itemstack1);

}

return itemstack;

}

}

 

 

Slot

 

package stevekung.mods.moreplanets.planets.fronos.inventory.slot;

 

import net.minecraft.inventory.IInventory;

import net.minecraft.inventory.Slot;

import net.minecraft.item.ItemStack;

import stevekung.mods.moreplanets.planets.fronos.tileentities.TileEntityCandyExtractor;

 

public class SlotCandyExtractorFuel extends Slot

{

public SlotCandyExtractorFuel(IInventory inventory, int slotIndex, int xPosition, int yPosition)

{

super(inventory, slotIndex, xPosition, yPosition);

}

 

@Override

public boolean isItemValid(ItemStack itemStack)

{

return TileEntityCandyExtractor.isItemFuel(itemStack);

}

 

@Override

public int getItemStackLimit(ItemStack itemStack)

{

return super.getItemStackLimit(itemStack);

}

}

 

 

 

package stevekung.mods.moreplanets.planets.fronos.inventory.slot;

 

import net.minecraft.entity.item.EntityXPOrb;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.inventory.IInventory;

import net.minecraft.inventory.Slot;

import net.minecraft.item.ItemStack;

import net.minecraft.util.MathHelper;

import stevekung.mods.moreplanets.common.recipe.CandyExtractorRecipes;

 

public class SlotCandyExtractorOutput extends Slot

{

private EntityPlayer thePlayer;

private int field_75228_b;

 

public SlotCandyExtractorOutput(EntityPlayer player, IInventory inv, int slotIndex, int xPosition, int yPosition)

{

super(inv, slotIndex, xPosition, yPosition);

this.thePlayer = player;

}

 

@Override

public boolean isItemValid(ItemStack itemStack)

{

return false;

}

 

@Override

public ItemStack decrStackSize(int amount)

{

if (this.getHasStack())

{

this.field_75228_b += Math.min(amount, this.getStack().stackSize);

}

return super.decrStackSize(amount);

}

 

@Override

public void onPickupFromSlot(EntityPlayer player, ItemStack itemStack)

{

this.onCrafting(itemStack);

super.onPickupFromSlot(player, itemStack);

}

 

@Override

protected void onCrafting(ItemStack itemStack, int amount)

{

this.field_75228_b += amount;

this.onCrafting(itemStack);

}

 

@Override

protected void onCrafting(ItemStack itemStack)

{

itemStack.onCrafting(this.thePlayer.worldObj, this.thePlayer, this.field_75228_b);

 

if (!this.thePlayer.worldObj.isRemote)

{

int i = this.field_75228_b;

float f = CandyExtractorRecipes.instance().getExtractingExperience(itemStack);

int j;

 

if (f == 0.0F)

{

i = 0;

}

else if (f < 1.0F)

{

j = MathHelper.floor_float(i * f);

 

if (j < MathHelper.ceiling_float_int(i * f) && Math.random() < i * f - j)

{

++j;

}

i = j;

}

 

while (i > 0)

{

j = EntityXPOrb.getXPSplit(i);

i -= j;

this.thePlayer.worldObj.spawnEntityInWorld(new EntityXPOrb(this.thePlayer.worldObj, this.thePlayer.posX, this.thePlayer.posY + 0.5D, this.thePlayer.posZ + 0.5D, j));

}

}

this.field_75228_b = 0;

}

}

 

Posted

Block

 

package stevekung.mods.moreplanets.planets.fronos.blocks;

 

import java.util.Random;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.block.properties.IProperty;

import net.minecraft.block.properties.PropertyDirection;

import net.minecraft.block.state.BlockState;

import net.minecraft.block.state.IBlockState;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.inventory.Container;

import net.minecraft.inventory.InventoryHelper;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.BlockPos;

import net.minecraft.util.EnumFacing;

import net.minecraft.util.EnumParticleTypes;

import net.minecraft.util.EnumWorldBlockLayer;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.world.World;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

import stevekung.mods.moreplanets.common.blocks.BlockContainerMP;

import stevekung.mods.moreplanets.core.MorePlanetsCore;

import stevekung.mods.moreplanets.core.proxy.ClientProxyMP.ParticleTypesMP;

import stevekung.mods.moreplanets.planets.fronos.tileentities.TileEntityCandyExtractor;

 

public class BlockCandyExtractor extends BlockContainerMP

{

private boolean isActive;

private static boolean keepExtractorInventory;

public static PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL);

 

public BlockCandyExtractor(String name, boolean active)

{

super(Material.rock);

this.isActive = active;

this.setHardness(4.0F);

this.setDefaultState(this.getDefaultState().withProperty(FACING, EnumFacing.NORTH));

this.setUnlocalizedName(name);

 

if (this.isActive)

{

this.setLightLevel(1.0F);

}

}

 

@Override

public Item getItemDropped(IBlockState state, Random rand, int fortune)

{

return Item.getItemFromBlock(FronosBlocks.candy_extractor_idle);

}

 

@Override

public CreativeTabs getCreativeTabToDisplayOn()

{

if (!this.isActive)

{

return MorePlanetsCore.mpBlocksTab;

}

return null;

}

 

@Override

@SideOnly(Side.CLIENT)

public EnumWorldBlockLayer getBlockLayer()

{

return EnumWorldBlockLayer.SOLID;

}

 

@Override

public boolean isOpaqueCube()

{

return false;

}

 

@Override

public boolean isFullCube()

{

return false;

}

 

@Override

public int getRenderType()

{

return 3;

}

 

@Override

public void onBlockAdded(World world, BlockPos pos, IBlockState state)

{

this.setDefaultFacing(world, pos, state);

}

 

private void setDefaultFacing(World world, BlockPos pos, IBlockState state)

{

if (!world.isRemote)

{

Block block = world.getBlockState(pos.north()).getBlock();

Block block1 = world.getBlockState(pos.south()).getBlock();

Block block2 = world.getBlockState(pos.west()).getBlock();

Block block3 = world.getBlockState(pos.east()).getBlock();

EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);

 

if (enumfacing == EnumFacing.NORTH && block.isFullBlock() && !block1.isFullBlock())

{

enumfacing = EnumFacing.SOUTH;

}

else if (enumfacing == EnumFacing.SOUTH && block1.isFullBlock() && !block.isFullBlock())

{

enumfacing = EnumFacing.NORTH;

}

else if (enumfacing == EnumFacing.WEST && block2.isFullBlock() && !block3.isFullBlock())

{

enumfacing = EnumFacing.EAST;

}

else if (enumfacing == EnumFacing.EAST && block3.isFullBlock() && !block2.isFullBlock())

{

enumfacing = EnumFacing.WEST;

}

world.setBlockState(pos, state.withProperty(FACING, enumfacing), 2);

}

}

 

@Override

public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ)

{

if (world.isRemote)

{

return true;

}

else

{

TileEntity tileentity = world.getTileEntity(pos);

 

if (tileentity instanceof TileEntityCandyExtractor)

{

player.openGui(MorePlanetsCore.instance, -1, world, pos.getX(), pos.getY(), pos.getZ());

}

return true;

}

}

 

public static void setState(boolean active, World world, BlockPos pos)

{

IBlockState state = world.getBlockState(pos);

TileEntity tile = world.getTileEntity(pos);

keepExtractorInventory = true;

 

if (active)

{

world.setBlockState(pos, FronosBlocks.candy_extractor_active.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);

world.setBlockState(pos, FronosBlocks.candy_extractor_active.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);

}

else

{

world.setBlockState(pos, FronosBlocks.candy_extractor_idle.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);

world.setBlockState(pos, FronosBlocks.candy_extractor_idle.getDefaultState().withProperty(FACING, state.getValue(FACING)), 3);

}

 

keepExtractorInventory = false;

 

if (tile != null)

{

tile.validate();

world.setTileEntity(pos, tile);

}

}

 

@Override

@SideOnly(Side.CLIENT)

public void randomDisplayTick(World world, BlockPos pos, IBlockState state, Random rand)

{

if (this.isActive)

{

EnumFacing enumfacing = (EnumFacing)state.getValue(FACING);

double d0 = pos.getX() + 0.5D;

double d1 = pos.getY() + rand.nextDouble() * 6.0D / 16.0D;

double d2 = pos.getZ() + 0.5D;

double d3 = 0.52D;

double d4 = rand.nextDouble() * 0.6D - 0.3D;

 

switch (SwitchEnumFacing.FACING_LOOKUP[enumfacing.ordinal()])

{

case 1:

world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 - d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);

MorePlanetsCore.proxy.spawnParticle(ParticleTypesMP.BLUE_FLAME, d0 - d3, d1, d2 + d4);

break;

case 2:

world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D, new int[0]);

MorePlanetsCore.proxy.spawnParticle(ParticleTypesMP.BLUE_FLAME, d0 + d3, d1, d2 + d4);

break;

case 3:

world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 - d3, 0.0D, 0.0D, 0.0D, new int[0]);

MorePlanetsCore.proxy.spawnParticle(ParticleTypesMP.BLUE_FLAME, d0 + d4, d1, d2 - d3);

break;

case 4:

world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, d0 + d4, d1, d2 + d3, 0.0D, 0.0D, 0.0D, new int[0]);

MorePlanetsCore.proxy.spawnParticle(ParticleTypesMP.BLUE_FLAME, d0 + d4, d1, d2 + d3);

}

}

}

 

@Override

public TileEntity createNewTileEntity(World world, int meta)

{

return new TileEntityCandyExtractor();

}

 

@Override

public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)

{

return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());

}

 

@Override

public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)

{

world.setBlockState(pos, state.withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);

}

 

@Override

public void breakBlock(World world, BlockPos pos, IBlockState state)

{

if (!keepExtractorInventory)

{

TileEntity tileentity = world.getTileEntity(pos);

 

if (tileentity instanceof TileEntityCandyExtractor)

{

InventoryHelper.dropInventoryItems(world, pos, (TileEntityCandyExtractor)tileentity);

world.updateComparatorOutputLevel(pos, this);

}

}

super.breakBlock(world, pos, state);

}

 

@Override

public boolean hasComparatorInputOverride()

{

return true;

}

 

@Override

public int getComparatorInputOverride(World world, BlockPos pos)

{

return Container.calcRedstone(world.getTileEntity(pos));

}

 

@Override

@SideOnly(Side.CLIENT)

public ItemStack getPickBlock(MovingObjectPosition mov, World world, BlockPos pos)

{

return new ItemStack(FronosBlocks.candy_extractor_idle, 1, 0);

}

 

@Override

@SideOnly(Side.CLIENT)

public IBlockState getStateForEntityRender(IBlockState state)

{

return this.getDefaultState().withProperty(FACING, EnumFacing.SOUTH);

}

 

@Override

public IBlockState getStateFromMeta(int meta)

{

EnumFacing enumfacing = EnumFacing.getFront(meta);

 

if (enumfacing.getAxis() == EnumFacing.Axis.Y)

{

enumfacing = EnumFacing.NORTH;

}

return this.getDefaultState().withProperty(FACING, enumfacing);

}

 

@Override

public int getMetaFromState(IBlockState state)

{

return ((EnumFacing)state.getValue(FACING)).getIndex();

}

 

@Override

protected BlockState createBlockState()

{

return new BlockState(this, new IProperty[] {FACING});

}

 

@SideOnly(Side.CLIENT)

static class SwitchEnumFacing

{

static int[] FACING_LOOKUP = new int[EnumFacing.values().length];

 

static

{

try

{

FACING_LOOKUP[EnumFacing.WEST.ordinal()] = 1;

}

catch (NoSuchFieldError var4)

{

}

 

try

{

FACING_LOOKUP[EnumFacing.EAST.ordinal()] = 2;

}

catch (NoSuchFieldError var3)

{

}

 

try

{

FACING_LOOKUP[EnumFacing.NORTH.ordinal()] = 3;

}

catch (NoSuchFieldError var2)

{

}

 

try

{

FACING_LOOKUP[EnumFacing.SOUTH.ordinal()] = 4;

}

catch (NoSuchFieldError var1)

{

}

}

}

}

 

 

GUI Handler

 

package stevekung.mods.moreplanets.common.eventhandler;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.BlockPos;

import net.minecraft.world.World;

import net.minecraftforge.fml.common.FMLCommonHandler;

import net.minecraftforge.fml.common.network.IGuiHandler;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

import stevekung.mods.moreplanets.planets.fronos.client.gui.GuiCandyExtractor;

import stevekung.mods.moreplanets.planets.fronos.inventory.container.ContainerCandyExtractor;

import stevekung.mods.moreplanets.planets.fronos.tileentities.TileEntityCandyExtractor;

 

public class GuiEventHandler implements IGuiHandler

{

@Override

public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)

{

//EntityPlayerMP playerBase = PlayerUtil.getPlayerBaseServerFromPlayer(player, false);

BlockPos pos = new BlockPos(x, y, z);

TileEntity tile = world.getTileEntity(pos);

 

/*if (playerBase == null)

{

player.addChatMessage(new ChatComponentText("More Planets player instance null server-side. This is a bug."));

return null;

}*/

if (tile != null && !player.isSpectator())

{

/*if (tile instanceof TileEntityUltraVioletSolarPanel)

{

return new ContainerUltraVioletSolarPanel(player.inventory, (TileEntityUltraVioletSolarPanel) tile);

}

else if (tile instanceof TileEntityPowerCrystalGenerator)

{

return new ContainerPowerCrystalGenerator(player.inventory, (TileEntityPowerCrystalGenerator) tile);

}

else */if (tile instanceof TileEntityCandyExtractor)

{

return new ContainerCandyExtractor(player.inventory, (TileEntityCandyExtractor) tile);

}

/*else if (tile instanceof TileEntityMineralWaterGenerator)

{

return new ContainerMineralWaterGenerator(player.inventory, (TileEntityMineralWaterGenerator) tile);

}*/

}

return tile;

}

 

@Override

@SideOnly(Side.CLIENT)

public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)

{

BlockPos pos = new BlockPos(x, y, z);

TileEntity tile = world.getTileEntity(pos);

 

if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)

{

if (tile != null)

{

/*if (tile instanceof TileEntityUltraVioletSolarPanel)

{

return new GuiUltraVioletSolarPanel(player.inventory, (TileEntityUltraVioletSolarPanel) world.getTileEntity(position.intX(), position.intY(), position.intZ()));

}

else if (tile instanceof TileEntityPowerCrystalGenerator)

{

return new GuiPowerCrystalGenerator(player.inventory, (TileEntityPowerCrystalGenerator) world.getTileEntity(position.intX(), position.intY(), position.intZ()));

}

else */if (tile instanceof TileEntityCandyExtractor)

{

return new GuiCandyExtractor(player.inventory, (TileEntityCandyExtractor) world.getTileEntity(pos));

}

/*else if (tile instanceof TileEntityMineralWaterGenerator)

{

return new GuiMineralWaterGenerator(player.inventory, (TileEntityMineralWaterGenerator) world.getTileEntity(position.intX(), position.intY(), position.intZ()));

}*/

}

}

return tile;

}

}

 

 

[image]http://puu.sh/gTTNa/ccdb7c1d5d.png[/image]

  • 1 month later...
Posted

 

package stevekung.mods.moreplanets.common.eventhandler;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.BlockPos;

import net.minecraft.world.World;

import net.minecraftforge.fml.common.network.IGuiHandler;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

import stevekung.mods.moreplanets.planets.fronos.client.gui.GuiCandyExtractor;

import stevekung.mods.moreplanets.planets.fronos.inventory.container.ContainerCandyExtractor;

import stevekung.mods.moreplanets.planets.fronos.tileentities.TileEntityCandyExtractor;

 

public class GuiEventHandler implements IGuiHandler

{

@Override

public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)

{

TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));

 

if (tile != null)

{

if (tile instanceof TileEntityCandyExtractor)

{

return new ContainerCandyExtractor(player.inventory, (TileEntityCandyExtractor)tile);

}

}

return null;

}

 

@Override

@SideOnly(Side.CLIENT)

public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z)

{

TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));

 

if (tile != null)

{

if (tile instanceof TileEntityCandyExtractor)

{

return new GuiCandyExtractor(player.inventory, (TileEntityCandyExtractor)tile);

}

}

return null;

}

 

/*TODO: Waiting for Galacticraft

*

* //EntityPlayerMP playerBase = PlayerUtil.getPlayerBaseServerFromPlayer(player, false);

TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));

 

if (playerBase == null)

{

player.addChatMessage(new ChatComponentText("More Planets player instance null server-side. This is a bug."));

return null;

}

if (tile != null)

{

if (tile instanceof TileEntityUltraVioletSolarPanel)

{

return new ContainerUltraVioletSolarPanel(player.inventory, (TileEntityUltraVioletSolarPanel) tile);

}

else if (tile instanceof TileEntityPowerCrystalGenerator)

{

return new ContainerPowerCrystalGenerator(player.inventory, (TileEntityPowerCrystalGenerator) tile);

}

else if (tile instanceof TileEntityCandyExtractor)

{

return new ContainerCandyExtractor(player.inventory, (TileEntityCandyExtractor)tile);

}

else if (tile instanceof TileEntityMineralWaterGenerator)

{

return new ContainerMineralWaterGenerator(player.inventory, (TileEntityMineralWaterGenerator) tile);

}

}

return null;

 

if (tile instanceof TileEntityUltraVioletSolarPanel)

{

return new GuiUltraVioletSolarPanel(player.inventory, (TileEntityUltraVioletSolarPanel) world.getTileEntity(position.intX(), position.intY(), position.intZ()));

}

else if (tile instanceof TileEntityPowerCrystalGenerator)

{

return new GuiPowerCrystalGenerator(player.inventory, (TileEntityPowerCrystalGenerator) world.getTileEntity(position.intX(), position.intY(), position.intZ()));

}

else if (tile instanceof TileEntityCandyExtractor)

{

return new GuiCandyExtractor(player.inventory, (TileEntityCandyExtractor)tile);

}

else if (tile instanceof TileEntityMineralWaterGenerator)

{

return new GuiMineralWaterGenerator(player.inventory, (TileEntityMineralWaterGenerator) world.getTileEntity(position.intX(), position.intY(), position.intZ()));

}

*/

}

 

Posted

 

That class on the server returns a Container (just as you said) and on the client returns a GuiContainer (not like you said).

 

public class GuiInventoryFurnace extends GuiContainer

 

I see MBE Code they return Container on server, client return Inventory. - -

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.