Jump to content

[1.6.4] A mod tried to open a gui on the server without being a NetworkMod


Delilah

Recommended Posts

Hi hello, I did at the end the gui following the tutorial of Containers and Guis here

 

http://www.minecraftforge.net/wiki/Containers_and_GUIs

 

Apparently there is no errors in the code and the game is working, but when I'm doing right click on the block that should open the gui I can see the text "A mod tried to open a gui on the server without being a NetworkMod" I was looking for information but in the tutorial I can't see nothing about that and I don't know how to fixed. If someone know the solution would be a help. Is really complicated the first time that you are doing that.

 

Thanks.

Link to comment
Share on other sites

Did you pass "YourMod.instance" when opening the GUI?

 

Did you make an IGuiHandler class?

 

Does your IGuiHandler return the correct Gui Elements on both the client and the server?

 

Did you put the @NetworkMod and all other necessary annotations in your main class?

 

@Mod(modid = "your_mod_id", name = "Readable Mod Name", version = "1.0")
@NetworkMod(clientSideRequired=true, serverSideRequired=true)

public class YourMod {
@Instance("your_mod_id")
public static YourMod instance;

@SidedProxy(clientSide = "client_proxy_package", serverSide = "common_proxy_package")
public static CommonProxy proxy;

// Initialization events
}

 

If none of those help you, please post your code.

Link to comment
Share on other sites

This is my code:

 

 

 

@Mod(modid = "TeR", name = "TeR", version = "v.001")

@NetworkMod(clientSideRequired = true, serverSideRequired = true)

 

public class MainClass

{

@SidedProxy(clientSide = "JavaBuckets.Modium.Main.ClientProxy", serverSide = "JavaBuckets.Modium.Main.CommonProxy")

public static CommonProxy proxy;

public static String modid = "TeR";

 

@Instance("MainClass")

        public static MainClass instance;

 

@EventHandler

        public void init(FMLInitializationEvent event)

{

            NetworkRegistry.instance().registerGuiHandler(this, new GuiHandler());

          }

 

 

 

Block

 

 

package JavaBuckets.Mods.Modium.Blocks;

 

import java.util.Random;

 

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import JavaBuckets.Modium.Main.MainClass;

import JavaBuckets.Mods.TeR.entity.TileEntityTeRWorkBench;

import net.minecraft.block.Block;

import net.minecraft.block.BlockContainer;

import net.minecraft.block.material.Material;

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

import net.minecraft.entity.EntityLivingBase;

import net.minecraft.entity.item.EntityItem;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.inventory.IInventory;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.util.MathHelper;

import net.minecraft.world.World;

 

public class BlockTeRWorkBench extends BlockContainer

{

 

public BlockTeRWorkBench(int id)

{

super(id, Material.rock);

setCreativeTab(MainClass.TeRTabItem);

this.setBlockBounds(0F, 0F,

0F, 1F,

1F-1F/16F*6F, 1F);

}

 

@Override

public TileEntity createNewTileEntity(World world)

{

return new TileEntityTeRWorkBench();

}

 

public int getRenderType()

{

return -1;

}

 

public boolean isOpaqueCube()

{

return false;

}

 

public boolean renderAsNormalBlock()

{

return false;

}

 

@SideOnly(Side.CLIENT)

public void registerIcons(IconRegister icon)

{

this.blockIcon = icon.registerIcon("modium:work_bench");

}

 

public int idDropped(int par1, Random par2Random, int par3)

{

return this.blockID;

}

 

public int quantityDropped(Random par1Random)

{

return 1;

}

 

//Calculamos la posición del objeto para luego poder rotarlo en la render class

/**

    * Called whenever the block is added into the world. Args: world, x, y, z

    */

 

 

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

{

    super.onBlockAdded(par1World, par2, par3, par4);

    this.setDefaultDirection(par1World, par2, par3, par4);

}

 

 

// set a blocks direction

    //

private void setDefaultDirection(World par1World, int par2, int par3, int par4)

{

    if (!par1World.isRemote)

    {

            int l = par1World.getBlockId(par2, par3, par4 - 1);

            int i1 = par1World.getBlockId(par2, par3, par4 + 1);

            int j1 = par1World.getBlockId(par2 - 1, par3, par4);

            int k1 = par1World.getBlockId(par2 + 1, par3, par4);

            byte b0 = 3;

 

            if (Block.opaqueCubeLookup[l] && !Block.opaqueCubeLookup[i1])

            {

                    b0 = 3;

            }

 

            if (Block.opaqueCubeLookup[i1] && !Block.opaqueCubeLookup[l])

            {

                    b0 = 2;

            }

 

            if (Block.opaqueCubeLookup[j1] && !Block.opaqueCubeLookup[k1])

            {

                    b0 = 5;

            }

 

            if (Block.opaqueCubeLookup[k1] && !Block.opaqueCubeLookup[j1])

            {

                    b0 = 4;

            }

 

            par1World.setBlockMetadataWithNotify(par2, par3, par4, b0, 2);

    }

}

public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)

{

    int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;

 

    if (l == 0)

    {

            par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);

    }

 

    if (l == 1)

    {

            par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);

    }

 

    if (l == 2)

    {

            par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);

    }

 

    if (l == 3)

    {

            par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);

    }

 

    //if (par6ItemStack.hasDisplayName())

    //{

    // ((TileEntityFurnace)par1World.getBlockTileEntity(par2, par3, par4)).setGuiDisplayName(par6ItemStack.getDisplayName());

    //}

}

 

private static int getMetadataBasedOnRotation(int rotation)

{

if (rotation >= 315 || rotation < 45)

{

return 1;

}

else if (rotation >= 45 && rotation < 135)

{

return 2;

}

else if (rotation >= 135 && rotation < 225)

{

return 0;

}

else

{

return 3;

}

}

 

//Añadimos todo lo de la interfaz Gui

@Override

    public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int metadata, float what, float these, float are)

{

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

            if (tileEntity == null || player.isSneaking())

            {

                return false;

            }

            //code to open gui explained later

            player.openGui(MainClass.instance, 0, world, x, y, z);

            return true;

}

 

    @Override

    public void breakBlock(World world, int x, int y, int z, int par5, int par6)

    {

            dropItems(world, x, y, z);

            super.breakBlock(world, x, y, z, par5, par6);

    }

 

    private void dropItems(World world, int x, int y, int z)

    {

            Random rand = new Random();

 

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

            if (!(tileEntity instanceof IInventory))

            {

                    return;

            }

            IInventory inventory = (IInventory) tileEntity;

 

            for (int i = 0; i < inventory.getSizeInventory(); i++)

            {

                    ItemStack item = inventory.getStackInSlot(i);

 

                    if (item != null && item.stackSize > 0)

                    {

                            float rx = rand.nextFloat() * 0.8F + 0.1F;

                            float ry = rand.nextFloat() * 0.8F + 0.1F;

                            float rz = rand.nextFloat() * 0.8F + 0.1F;

 

                            EntityItem entityItem = new EntityItem(world,

                                            x + rx, y + ry, z + rz,

                                            new ItemStack(item.itemID, item.stackSize, item.getItemDamage()));

 

                            if (item.hasTagCompound())

                            {

                                    entityItem.getEntityItem().setTagCompound((NBTTagCompound) item.getTagCompound().copy());

                            }

 

                            float factor = 0.05F;

                            entityItem.motionX = rand.nextGaussian() * factor;

                            entityItem.motionY = rand.nextGaussian() * factor + 0.2F;

                            entityItem.motionZ = rand.nextGaussian() * factor;

                            world.spawnEntityInWorld(entityItem);

                            item.stackSize = 0;

                    }

            }

    }

 

    /*

    @Override

    public TileEntity createNewTileEntity(World world) {

            return new TileEntityTiny();

    }

*/

 

}

 

 

 

 

Container

 

 

package JavaBuckets.Modium.Main;

 

import JavaBuckets.Mods.TeR.entity.TileEntityGui;

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;

 

public class ContainerGui extends Container

{

 

        protected TileEntityGui tileEntity;

 

        public ContainerGui (InventoryPlayer inventoryPlayer, TileEntityGui 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

                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);

        }

 

        @Override

        public boolean canInteractWith(EntityPlayer player) {

                return tileEntity.isUseableByPlayer(player);

        }

 

 

        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 < 9) {

                                if (!this.mergeItemStack(stackInSlot, 0, 35, true)) {

                                        return null;

                                }

                        }

                        //places it into the tileEntity is possible since its in the player inventory

                        else if (!this.mergeItemStack(stackInSlot, 0, 9, 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;

        }

}

 

 

 

GuiHandler

 

 

package JavaBuckets.Modium.Main;

 

import JavaBuckets.Mods.TeR.entity.TileEntityGui;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.tileentity.TileEntity;

import net.minecraft.world.World;

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

 

public class GuiHandler implements IGuiHandler

{

        //returns an instance of the Container you made earlier

        @Override

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

        {

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

                if(tileEntity instanceof TileEntityGui)

                {

                        return new ContainerGui(player.inventory, (TileEntityGui) 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.getBlockTileEntity(x, y, z);

                if(tileEntity instanceof TileEntityGui)

                {

                        return new TeRGui(player.inventory, (TileEntityGui) tileEntity);

                }

                return null;

 

        }

}

 

 

 

Gui

 

 

package JavaBuckets.Modium.Main;

 

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

import net.minecraft.entity.player.InventoryPlayer;

import net.minecraft.util.ResourceLocation;

import net.minecraft.util.StatCollector;

 

import org.lwjgl.opengl.GL11;

 

import JavaBuckets.Mods.TeR.entity.TileEntityGui;

 

public class TeRGui extends GuiContainer

{

 

        public TeRGui (InventoryPlayer inventoryPlayer,

                        TileEntityGui tileEntity)

        {

                //the container is instanciated and passed to the superclass for handling

                super(new ContainerGui(inventoryPlayer, tileEntity));

        }

 

        @Override

        protected void drawGuiContainerForegroundLayer(int param1, int param2) {

                //draw text and stuff here

                //the parameters for drawString are: string, x, y, color

                fontRenderer.drawString("Tiny", 8, 6, 4210752);

                //draws "Inventory" or your regional equivalent

                fontRenderer.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

               

        //int texture = mc.renderEngine.getTexture("modium:craftinggui.png");

        final ResourceLocation texture = new ResourceLocation("modium:textures/blocks/craftinggui.png");

               

        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);

        }

 

}

 

 

 

ClientProxy

 

 

package JavaBuckets.Modium.Main;

 

import JavaBuckets.Mods.TeR.Models.slimegreen;

import JavaBuckets.Mods.TeR.Models.slimenblue;

import JavaBuckets.Mods.TeR.Models.tercorruptor;

import JavaBuckets.Mods.TeR.Renders.SlimeBlueRender;

import JavaBuckets.Mods.TeR.Renders.SlimeGreenRender;

import JavaBuckets.Mods.TeR.Renders.TeRCorruptorRender;

import JavaBuckets.Mods.TeR.entity.Entityslimeblue;

import JavaBuckets.Mods.TeR.entity.Entityslimegreen;

import JavaBuckets.Mods.TeR.entity.Entityter_corruptor;

import cpw.mods.fml.client.registry.RenderingRegistry;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

 

public class ClientProxy extends CommonProxy

{

 

@SideOnly(Side.CLIENT)

public void registerRenderInformation()

{

}

}

 

 

 

CommonProxy

 

 

package JavaBuckets.Modium.Main;

 

public class CommonProxy

{

public void registerRenderInformation()

{

 

}

}

 

 

 

 

TileEntityGui

 

 

package JavaBuckets.Mods.TeR.entity;

 

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.inventory.IInventory;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.nbt.NBTTagList;

import net.minecraft.tileentity.TileEntity;

 

public class TileEntityGui extends TileEntity implements IInventory {

 

        private ItemStack[] inv;

 

        public TileEntityGui(){

                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;

        }

 

        @Override

        public boolean isUseableByPlayer(EntityPlayer player) {

                return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this &&

                player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;

        }

 

        @Override

        public void openChest() {}

 

        @Override

        public void closeChest() {}

       

        @Override

        public void readFromNBT(NBTTagCompound tagCompound) {

                super.readFromNBT(tagCompound);

               

                NBTTagList tagList = tagCompound.getTagList("Inventory");

                for (int i = 0; i < tagList.tagCount(); i++) {

                        NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(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;

                        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 getInvName() {

                        return "tco.tileentitytiny";

                }

 

//Métodos implementados

                @Override

public boolean isInvNameLocalized()

{

// TODO Auto-generated method stub

return false;

}

 

@Override

public boolean isItemValidForSlot(int i, ItemStack itemstack)

{

// TODO Auto-generated method stub

return false;

}

}

 

 

 

Thanks

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.