It's always the same, in every version I cannot make the block opening the gui, am I missing something?
Main File:
package com.thelorizz.advanced;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import net.minecraftforge.fml.common.registry.GameRegistry;
import com.thelorizz.advanced.handler.ForgeEventHandler;
import com.thelorizz.advanced.handler.GuiHandler;
import com.thelorizz.advanced.registry.BlockRegistry;
import com.thelorizz.advanced.tileentity.TileEntityFusion;
@Mod(modid = mod_advanced.MODID, version = mod_advanced.VERSION)
public class mod_advanced {
public static final String MODID = "thelorizz_advanced";
public static final String VERSION = "Beta";
@Instance(mod_advanced.MODID)
public static mod_advanced instance;
@SidedProxy(clientSide = "com.thelorizz.advanced.ClientProxy", serverSide = "com.thelorizz.advanced.ServerProxy")
public static ServerProxy proxy;
@EventHandler
public void preinit(FMLPreInitializationEvent e) {
MinecraftForge.EVENT_BUS.register(new ForgeEventHandler());
}
@EventHandler
public void init(FMLInitializationEvent e) {
BlockRegistry.registerBlocks();
GameRegistry.registerTileEntity(TileEntityFusion.class, "containerFusion");
NetworkRegistry.INSTANCE.registerGuiHandler(instance, new GuiHandler());
}
@EventHandler
public void postinit(FMLPostInitializationEvent e) {
}
}
GuiHandler:
package com.thelorizz.advanced.handler;
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 com.thelorizz.advanced.container.ContainerFusion;
import com.thelorizz.advanced.gui.GuiFusion;
import com.thelorizz.advanced.tileentity.TileEntityFusion;
public class GuiHandler implements IGuiHandler {
public GuiHandler() {
System.out.println("Initialized");
}
@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world,
int x, int y, int z) {
TileEntity tileEntity = world.getTileEntity(new BlockPos(x, y, z));
if (tileEntity instanceof TileEntityFusion) {
return new ContainerFusion(player.inventory,
(TileEntityFusion) tileEntity);
}
return null;
}
// returns an instance of the Gui you made earlier
@Override
public Object getClientGuiElement(int id, EntityPlayer player, World world,
int x, int y, int z) {
TileEntity tileEntity = world.getTileEntity(new BlockPos(x, y, z));
// System.out.println("AIRds:");
if (tileEntity instanceof TileEntityFusion) {
// System.out.println("AddsdIR:");
return new GuiFusion(player.inventory,
(TileEntityFusion) tileEntity);
}
return null;
}
}
ContainerFusion:
package com.thelorizz.advanced.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.world.World;
import com.thelorizz.advanced.tileentity.TileEntityFusion;
public class ContainerFusion extends Container {
protected TileEntityFusion tileEntity;
public ContainerFusion(InventoryPlayer inventoryPlayer, TileEntityFusion te) {
tileEntity = te;
// the Slot constructor takes the IInventory and the slot number in that
// it binds to
// and the x-y coordinates it resides on-screen
addSlotToContainer(new Slot(tileEntity, 30, 123, 57));
addSlotToContainer(new Slot(tileEntity, 31, 370, 57));
addSlotToContainer(new Slot(tileEntity, 32, 246, 162));
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
addSlotToContainer(new Slot(tileEntity, j + i * 3, 62 + j * 18,
17 + i * 18));
}
}
// commonly used vanilla code that adds the player's inventory
bindPlayerInventory(inventoryPlayer);
}
protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9,
8 + j * 18, 84 + i * 18));
}
}
for (int i = 0; i < 9; i++) {
addSlotToContainer(new Slot(inventoryPlayer, i, 8 + i * 18, 142));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
ItemStack stack = null;
Slot slotObject = (Slot) inventorySlots.get(slot);
// null checks and checks if the item can be stacked (maxStackSize > 1)
if (slotObject != null && slotObject.getHasStack()) {
ItemStack stackInSlot = slotObject.getStack();
stack = stackInSlot.copy();
// merges the item into player inventory since its in the tileEntity
if (slot < tileEntity.getSizeInventory()) {
if (!this.mergeItemStack(stackInSlot,
tileEntity.getSizeInventory(),
36 + tileEntity.getSizeInventory(), true)) {
return null;
}
}
// places it into the tileEntity is possible since its in the player
// inventory
else if (!this.mergeItemStack(stackInSlot, 0,
tileEntity.getSizeInventory(), false)) {
return null;
}
if (stackInSlot.stackSize == 0) {
slotObject.putStack(null);
} else {
slotObject.onSlotChanged();
}
if (stackInSlot.stackSize == stack.stackSize) {
return null;
}
slotObject.onPickupFromSlot(player, stackInSlot);
}
return stack;
}
public boolean canInteractWith(EntityPlayer playerIn) {
return this.tileEntity.isUseableByPlayer(playerIn);
}
}
GuiFusion:
package com.thelorizz.advanced.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraftforge.fml.client.FMLClientHandler;
import org.lwjgl.opengl.GL11;
import com.thelorizz.advanced.mod_advanced;
import com.thelorizz.advanced.container.ContainerFusion;
import com.thelorizz.advanced.tileentity.TileEntityFusion;
public class GuiFusion extends GuiContainer {
ResourceLocation texture = new ResourceLocation(mod_advanced.MODID, "textures/gui/gui_fusion.png");
public GuiFusion (InventoryPlayer inventoryPlayer,
TileEntityFusion tileEntity) {
//the container is instantiated and passed to the superclass for handling
super(new ContainerFusion(inventoryPlayer, tileEntity));
}
@Override
protected void drawGuiContainerForegroundLayer(int param1, int param2) {
//draw text and stuff here
//the parameters for drawString are: string, x, y, color
fontRendererObj.drawString("Fusion", 8, 6, 4210752);
//draws "Inventory" or your regional equivalent
fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2,
int par3) {
//draw your Gui here, only thing you need to change is the path
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.renderEngine.bindTexture(texture);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
}
}
BlockFusion:
package com.thelorizz.advanced.block;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.fml.common.registry.GameRegistry;
import com.thelorizz.advanced.mod_advanced;
import com.thelorizz.advanced.tileentity.TileEntityFusion;
public class BlockFusion extends Block {
public BlockFusion(Material materialIn) {
super(materialIn);
this.setUnlocalizedName("blockFusion");
this.setCreativeTab(CreativeTabs.tabBlock);
this.register();
}
public boolean onBlockActivated(World worldIn, BlockPos pos,
IBlockState state, EntityPlayer playerIn, EnumFacing side,
float hitX, float hitY, float hitZ) {
if (worldIn.isRemote) {
return true;
} else {
TileEntity tileentity = worldIn.getTileEntity(pos);
if (tileentity instanceof TileEntityFusion) {
playerIn.openGui(mod_advanced.instance, 0, worldIn, pos.getX(),
pos.getY(), pos.getZ());
}
return true;
}
}
public void register() {
GameRegistry
.registerBlock(this, this.getUnlocalizedName().substring(5));
}
}
TileEntityFusion:
package com.thelorizz.advanced.tileentity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IChatComponent;
public class TileEntityFusion extends TileEntity implements IInventory {
private ItemStack[] inv;
public TileEntityFusion() {
inv = new ItemStack[9];
}
@Override
public int getSizeInventory() {
return inv.length;
}
@Override
public ItemStack getStackInSlot(int slot) {
return inv[slot];
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
inv[slot] = stack;
if (stack != null && stack.stackSize > getInventoryStackLimit()) {
stack.stackSize = getInventoryStackLimit();
}
}
@Override
public ItemStack decrStackSize(int slot, int amt) {
ItemStack stack = getStackInSlot(slot);
if (stack != null) {
if (stack.stackSize <= amt) {
setInventorySlotContents(slot, null);
} else {
stack = stack.splitStack(amt);
if (stack.stackSize == 0) {
setInventorySlotContents(slot, null);
}
}
}
return stack;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
ItemStack stack = getStackInSlot(slot);
if (stack != null) {
setInventorySlotContents(slot, null);
}
return stack;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
public boolean isUseableByPlayer(EntityPlayer player) {
return this.worldObj.getTileEntity(this.pos) != this ? false : player
.getDistanceSq((double) this.pos.getX() + 0.5D,
(double) this.pos.getY() + 0.5D,
(double) this.pos.getZ() + 0.5D) <= 64.0D;
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
NBTTagList tagList = (NBTTagList) tagCompound.getTag("Inventory");
for (int i = 0; i < tagList.tagCount(); i++) {
NBTTagCompound tag = (NBTTagCompound) tagList.getCompoundTagAt(i);
byte slot = tag.getByte("Slot");
if (slot >= 0 && slot < inv.length) {
inv[slot] = ItemStack.loadItemStackFromNBT(tag);
}
}
}
@Override
public void writeToNBT(NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
NBTTagList itemList = new NBTTagList();
for (int i = 0; i < inv.length; i++) {
ItemStack stack = inv[i];
if (stack != null) {
NBTTagCompound tag = new NBTTagCompound();
tag.setByte("Slot", (byte) i);
stack.writeToNBT(tag);
itemList.appendTag(tag);
}
}
tagCompound.setTag("Inventory", itemList);
}
@Override
public String getName() {
// TODO Auto-generated method stub
return "gui_fusion";
}
@Override
public boolean hasCustomName() {
// TODO Auto-generated method stub
return true;
}
@Override
public IChatComponent getDisplayName() {
// TODO Auto-generated method stub
return null;
}
@Override
public void openInventory(EntityPlayer player) {
// TODO Auto-generated method stub
}
@Override
public void closeInventory(EntityPlayer player) {
// TODO Auto-generated method stub
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
if (stack.getItem() instanceof ItemSword) {
return true;
}
return false;
}
@Override
public int getField(int id) {
// TODO Auto-generated method stub
return 0;
}
@Override
public void setField(int id, int value) {
// TODO Auto-generated method stub
}
@Override
public int getFieldCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void clear() {
// TODO Auto-generated method stub
}
}