Jump to content

[1.5.1] Can't interact with Gui


deverionz

Recommended Posts

Hey everyone, Deverionz here, and my mod is broken :P

 

Basically what happens is that when I activate my block to open the gui, the gui opens, but I can't interact with it. I know that this is because my GuiHandler isn't calling the getServerGuiElement method, and so the gui doesn't recieve a container. My gui is for a multiblock, so I might have messed up something, but not as far as I can tell.

 

I have worked with gui's and tile entities in the past, but not extensively, and definitely not in a multiblock situation

 

The Code:

 

MTCore:

 

package deverionx.minetech.core;

 

import net.minecraft.block.Block;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.item.Item;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.Mod.Instance;

import cpw.mods.fml.common.SidedProxy;

import cpw.mods.fml.common.event.FMLInitializationEvent;

import cpw.mods.fml.common.event.FMLPostInitializationEvent;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import cpw.mods.fml.common.network.NetworkRegistry;

import cpw.mods.fml.common.registry.GameRegistry;

import deverionx.minetech.block.BlockBoiler;

import deverionx.minetech.block.BlockMetal;

import deverionx.minetech.block.BlockMortar;

import deverionx.minetech.block.BlockOre;

import deverionx.minetech.block.tile.TileEntitySteam;

import deverionx.minetech.item.ItemIngot;

import deverionx.minetech.item.ItemVanillaDust;

 

@Mod(modid="MineTech",name="MineTech",version="0.0.1a")

public class MTCore {

 

@Instance("MineTech")

public static MTCore instance;

 

@SidedProxy(serverSide="deverionx.minetech.core.CommonProxy",clientSide="deverionx.minetech.core.ClientProxy")

public static CommonProxy proxy;

 

public static CreativeTabs tabMinetech;

 

public static Item itemMetal;

public static Item itemVanillaDust;

 

public static Block blockOre;

public static Block blockMortar;

public static Block blockMetal;

public static Block blockBoiler;

 

@Mod.PreInit

public void Preload(FMLPreInitializationEvent e){

tabMinetech = new TabMinetech("Minetech");

 

ConfigManager config = new ConfigManager();

config.load(e);

 

if(config.worldEnabled){

itemMetal = new ItemIngot(config.itemMetalID);

itemVanillaDust = new ItemVanillaDust(config.itemVanillaDustID);

 

blockOre = new BlockOre(config.oreID);

blockMetal = new BlockMetal(config.metalBlockID);

 

((TabMinetech)tabMinetech).i = itemMetal;

 

if(config.steamEnabled){

blockMortar = new BlockMortar(config.mortarID);

blockBoiler = new BlockBoiler(config.boilerBlockID);

 

}

}

 

}

 

@Mod.Init

public void Load(FMLInitializationEvent e){

NetworkRegistry.instance().registerGuiHandler(this, proxy);

GameRegistry.registerFuelHandler(new FuelHandler());

GameRegistry.registerCraftingHandler(new CraftingHandler());

GameRegistry.registerWorldGenerator(new WorldGenerator());

 

if(ConfigManager.worldEnabled){

Registry.loadWorld();

if(ConfigManager.steamEnabled){

Registry.loadSteam();

}

}

}

 

@Mod.PostInit

public void Postload(FMLPostInitializationEvent e){

 

}

 

}

 

 

 

Common Proxy:

 

package deverionx.minetech.core;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

import cpw.mods.fml.common.network.IGuiHandler;

import deverionx.minetech.block.tile.TileEntityFirebox;

import deverionx.minetech.container.ContainerBoiler;

import deverionx.minetech.gui.GuiBoiler;

 

public class CommonProxy implements IGuiHandler{

 

@Override

public Object getServerGuiElement(int ID, EntityPlayer player, World world,

int x, int y, int z) {

 

TileEntity te = world.getBlockTileEntity(x,y,z);

 

switch(ID){

case 0:return new ContainerBoiler(player.inventory, (TileEntityFirebox)te);

}

return null;

}

 

@Override

public Object getClientGuiElement(int ID, EntityPlayer player, World world,

int x, int y, int z){

 

return null;

}

}

 

 

 

Client Proxy:

 

package deverionx.minetech.core;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

import deverionx.minetech.block.tile.TileEntityFirebox;

import deverionx.minetech.gui.GuiBoiler;

 

public class ClientProxy extends CommonProxy {

 

@Override

public Object getClientGuiElement(int ID, EntityPlayer player, World world,

int x, int y, int z) {

TileEntity te = world.getBlockTileEntity(x,y,z);

 

if(te instanceof TileEntityFirebox){

return new GuiBoiler(player.inventory,(TileEntityFirebox)te);

}

return null;

}

 

}

 

 

 

BlockBoiler:

 

package deverionx.minetech.block;

 

import java.util.List;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.renderer.texture.IconRegister;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.Icon;

import net.minecraft.world.IBlockAccess;

import net.minecraft.world.World;

import cpw.mods.fml.common.network.FMLNetworkHandler;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import deverionx.minetech.block.tile.TileEntityBoilerBase;

import deverionx.minetech.block.tile.TileEntityBoilerInput;

import deverionx.minetech.block.tile.TileEntityBoilerValve;

import deverionx.minetech.block.tile.TileEntityBoilerWall;

import deverionx.minetech.block.tile.TileEntityBoilerWindow;

import deverionx.minetech.block.tile.TileEntityFirebox;

import deverionx.minetech.core.MTCore;

 

public class BlockBoiler extends Block {

 

public Icon[] icons;

public Icon[] firebox;

public Icon[] wall;

public Icon[] valve;

public Icon[] window;

public Icon[] input;

 

public BlockBoiler(int i){

super(i, Material.iron);

setUnlocalizedName("MineTech.blockBoiler");

setResistance(10.0F);

setCreativeTab(MTCore.tabMinetech);

}

 

public Icon getBlockTexture(IBlockAccess iba, int x, int y, int z, int s){

if(((TileEntityBoilerBase)iba.getBlockTileEntity(x,y,z)).isValid){

if(iba.getBlockTileEntity(x,y,z) instanceof TileEntityFirebox){

 

int i = ((TileEntityFirebox)iba.getBlockTileEntity(x,y,z)).pos;

 

if(i == 0){

return s==2?firebox[2]:S==4?firebox[0]:super.brick.getBlockTextureFromSide(0);

}else if(i == 1){

return s>1?firebox[1]:super.brick.getBlockTextureFromSide(0);

}else if(i == 2){

return s<2?super.brick.getBlockTextureFromSide(0):S==4?firebox[2]:firebox[0];

}else if(i == 3){

return s!=1?firebox[1]:super.brick.getBlockTextureFromSide(0);

}else if(i == 4){

return super.brick.getBlockTextureFromSide(0);

}else if(i == 5){

return s>1?firebox[1]:super.brick.getBlockTextureFromSide(0);

}else if(i == 6){

return s<2?super.brick.getBlockTextureFromSide(0):S==5?firebox[2]:firebox[0];

}else if(i == 7){

return s>1?firebox[1]:super.brick.getBlockTextureFromSide(0);

}else if(i == 8){

return s==3?firebox[2]:S==5?firebox[0]:super.brick.getBlockTextureFromSide(0);

}

}else if(iba.getBlockTileEntity(x,y,z) instanceof TileEntityBoilerWall){

 

int i = ((TileEntityBoilerWall)iba.getBlockTileEntity(x, y, z)).pos;

 

if(i == 0){

return s<2?icons[1]:wall[0];

}if(i == 1){

return s<2?icons[1]:wall[0];

}if(i == 2){

return s<2?icons[1]:wall[0];

}if(i == 3){

return s<2?icons[1]:wall[0];

}else if(i == 4){

return s<2?icons[1]:wall[1];

}else if(i == 5){

return s<2?icons[1]:wall[1];

}else if(i == 6){

return s<2?icons[1]:wall[1];

}else if(i == 7){

return s<2?icons[1]:wall[1];

}else if(i == 8){

return s<1?icons[1]:S==1?wall[2]:S==2?wall[4]:wall[2];

}else if(i == 9){

return s<1?icons[1]:S==1?wall[1]:wall[3];

}else if(i == 10){

return s<1?icons[1]:S==1?wall[5]:S==4?wall[4]:wall[2];

}else if(i == 11){

return s<1?icons[1]:S==1?wall[3]:wall[3];

}else if(i == 12){

return s<1?icons[1]:S==1?wall[3]:wall[3];

}else if(i == 13){

return s<1?icons[1]:S==1?wall[4]:S==5?wall[4]:wall[2];

}else if(i == 14){

return s<1?icons[1]:S==1?wall[1]:wall[3];

}else if(i == 15){

return s<1?icons[1]:S==1?wall[6]:S==3?wall[4]:wall[2];

}

}else if(iba.getBlockTileEntity(x,y,z) instanceof TileEntityBoilerValve){

return valve[0];

}else if(iba.getBlockTileEntity(x,y,z) instanceof TileEntityBoilerWindow){

if(iba.getBlockMetadata(x,y+1,z) == 4){

return s>1?window[1]:window[3];

}else if(iba.getBlockMetadata(x,y-1,z) == 4){

return s>1?window[0]:window[3];

}else{

return window[2];

}

}else if(iba.getBlockTileEntity(x, y, z) instanceof TileEntityBoilerInput){

return input[0];

}

}

 

return getIcon(s,iba.getBlockMetadata(x, y, z));

}

 

public boolean onBlockActivated(World w, int x, int y, int z, EntityPlayer p, int l, float f, float f1, float f2){

 

if(w.getBlockTileEntity(x,y,z) != null && w.getBlockTileEntity(x,y,z) instanceof TileEntityBoilerBase){

if(((TileEntityBoilerBase)w.getBlockTileEntity(x,y,z)).isValid){

TileEntityBoilerBase te = (TileEntityBoilerBase)w.getBlockTileEntity(x,y,z);

if(te != null){

p.openGui(MTCore.instance, 0, w, te.homePos[0], te.homePos[1], te.homePos[2]);

}

}

}

 

return false;

}

 

public boolean shouldSideBeRendered(IBlockAccess iba, int x, int y, int z, int side){

return true;

}

 

public boolean isOpaqueCube(){

return false;

}

 

public float getBlockHardness(World w, int x, int y, int z){

return w.getBlockMetadata(x,y,z) != 4 ? 5.0F : 3.5F;

}

 

@SideOnly(Side.CLIENT)

public int getRenderBlockPass()

{

return 0;

}

 

public boolean renderAsNormalBlock()

{

return false;

}

 

@SideOnly(Side.CLIENT)

public void registerIcons(IconRegister ir){

icons = new Icon[5];

 

icons[0] = ir.registerIcon("MineTech:boilerBase");

icons[1] = ir.registerIcon("MineTech:boilerWall");

icons[2] = ir.registerIcon("MineTech:boilerValve");

icons[3] = ir.registerIcon("MineTech:boilerInput");

icons[4] = ir.registerIcon("MineTech:boilerWindow");

 

firebox = new Icon[3];

firebox[0] = ir.registerIcon("MineTech:boilerBaseJoined1");

firebox[1] = ir.registerIcon("MineTech:boilerBaseJoined2");

firebox[2] = ir.registerIcon("MineTech:boilerBaseJoined3");

 

wall = new Icon[7];

wall[0] = ir.registerIcon("MineTech:boilerWallJoined1");

wall[1] = ir.registerIcon("MineTech:boilerWallJoined2");

wall[2] = ir.registerIcon("MineTech:boilerWallJoined3");

wall[3] = ir.registerIcon("MineTech:boilerWallJoined4");

wall[4] = ir.registerIcon("MineTech:boilerWallJoined5");

wall[5] = ir.registerIcon("MineTech:boilerWallJoined6");

wall[6] = ir.registerIcon("MineTech:boilerWallJoined7");

 

valve = new Icon[1];

valve[0] = ir.registerIcon("MineTech:boilerValveJoined");

 

window = new Icon[4];

window[0] = ir.registerIcon("MineTech:boilerWindowJoined1");

window[1] = ir.registerIcon("MineTech:boilerWindowJoined2");

window[2] = ir.registerIcon("MineTech:boilerWindowJoined3");

window[3] = ir.registerIcon("MineTech:boilerWindowJoined4");

 

input = new Icon[1];

input[0] = ir.registerIcon("MineTech:boilerInputJoined");

}

 

@SideOnly(Side.CLIENT)

public Icon getIcon(int i, int j){

switch(j){

case 0:return i < 2 ? Block.brick.getBlockTextureFromSide(2) : icons[0];

case 1:return icons[1];

case 2:return icons[2];

case 3:return icons[3];

case 4:return icons[4];

default:return Block.bedrock.getBlockTextureFromSide(2);

}

}

 

@Override

public TileEntity createTileEntity(World world, int m) {

switch(m){

case 0:return new TileEntityFirebox();

case 1:return new TileEntityBoilerWall();

case 2:return new TileEntityBoilerValve();

case 3:return new TileEntityBoilerInput();

case 4:return new TileEntityBoilerWindow();

}

return null;

}

 

@Override

public boolean hasTileEntity(int i){

return true;

}

@SideOnly(Side.CLIENT)

public void getSubBlocks(int i, CreativeTabs tab, List l){

for(int a = 0; a < 5; a++){

l.add(new ItemStack(i, 1, a));

}

}

 

public int damageDropped(int i){

return i;

}

 

public void onBlockAdded(World par1World, int par2, int par3, int par4)

{

par1World.setBlockTileEntity(par2, par3, par4, this.createTileEntity(par1World, par1World.getBlockMetadata(par2, par3, par4)));

((TileEntityBoilerBase)par1World.getBlockTileEntity(par2,par3,par4)).homePos = new int[]{};

}

 

}

 

 

 

ContainerBoiler:

 

package deverionx.minetech.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.Slot;

import net.minecraft.inventory.SlotFurnace;

import net.minecraft.item.ItemStack;

import net.minecraft.item.crafting.FurnaceRecipes;

import net.minecraft.tileentity.TileEntityFurnace;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import deverionx.minetech.block.tile.TileEntityFirebox;

 

public class ContainerBoiler extends Container

{

    private TileEntityFirebox fb;

 

    public ContainerBoiler(InventoryPlayer par1InventoryPlayer, TileEntityFirebox f)

    {

        this.fb = f;

        this.addSlotToContainer(new Slot(f, 0, 28, 11));

        this.addSlotToContainer(new Slot(f, 1, 28, 58));

        this.addSlotToContainer(new Slot(f, 2, 75, 41));

        int i;

 

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

        {

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

            {

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

            }

        }

 

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

        {

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

        }

    }

 

    public boolean canInteractWith(EntityPlayer par1EntityPlayer)

    {

        return this.fb.isUseableByPlayer(par1EntityPlayer);

    }

 

    /**

    * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.

    */

    public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)

    {

        return null; //Ignore please, I'm lazy! :P

    }

}

 

 

 

GuiBoiler:

 

package deverionx.minetech.gui;

 

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

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.util.StatCollector;

 

import org.lwjgl.opengl.GL11;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import deverionx.minetech.block.tile.TileEntityFirebox;

import deverionx.minetech.container.ContainerBoiler;

 

@SideOnly(Side.CLIENT)

public class GuiBoiler extends GuiContainer

{

    private TileEntityFirebox fb;

 

    public GuiBoiler(InventoryPlayer par1InventoryPlayer, TileEntityFirebox f)

    {

        super(new ContainerBoiler(par1InventoryPlayer, f));

        this.fb = f;

    }

 

    protected void drawGuiContainerForegroundLayer(int par1, int par2)

    {

        this.fontRenderer.drawString("Boiler", this.xSize / 2 - 40, 4, 4210752);

        this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 91, 4210752);

    }

 

    protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)

    {

        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);

        this.mc.renderEngine.bindTexture("/mods/MineTech/textures/gui/boiler.png");

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

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

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

    }

}

 

 

 

And that should be everything, any and all help is appreciated  :)

 

(I am aware that my code is beyond untidy and is extremely inefficient, but at this point of time I'm going for functionality over efficiency)

Writing a steampunk mod called MineTech, and author of a long dead fishing mod

Link to comment
Share on other sites

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.