Jump to content

[1.7.10] GUI Problem, can't move blocks around


ATimmeh33

Recommended Posts

Hey everyone,

 

I'm trying out  the basics of modding, however I've ran into a problem. I made a GUI but I can't move the blocks around. I've recorded a little clip where you can see what happens.

 

 

I've searched around and found a lot of other people with this problem, but it were mostly very old versions (1.4.3 and older), and they said the fix was to use @NetworkMod, which afaik doesn't exist anymore on 1.7.10.

 

I can provide code, just tell me where the problem probably occurs (proxies, main, entity, container, etc).

Link to comment
Share on other sites

Problem may occur anywhere in listed classes :D

 

Proxy, GuiHandler, Container, Gui, if you are using custom slots - also might be useful and IInventory - if you implement one.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Okay, here is the code. Sorry if I missed something, in a hurry. Will be  back in the evening ;)

 

Proxy's

 

public class ClientProxy extends CommonProxy {

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
	TileEntity tileEntity = world.getTileEntity(x, y, z);

	if(tileEntity != null)
	{
		if (ID == GUIs.carbon_pressurizer.ordinal())
			return new CarbonPressurizerGUI(player.inventory, (TileEntityCarbonPressurizer)tileEntity);
		else
			return null;
	}
	else
		return null;
}
}

public class CommonProxy implements IGuiHandler {

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
	return null;
}

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z)
{
	TileEntity tileEntity = world.getTileEntity(x, y, z);

	if(tileEntity != null)
	{
		if (ID == GUIs.carbon_pressurizer.ordinal())
			return new CarbonPressurizerGUI(player.inventory, (TileEntityCarbonPressurizer)tileEntity);
		else
			return null;
	}
	else
		return null;
}
}

 

 

Container

 

public class ContainerCarbonPressurizer extends Container {

private TileEntityCarbonPressurizer carbonPressurizer;

public ContainerCarbonPressurizer(InventoryPlayer par1InventoryPlayer, TileEntityCarbonPressurizer par2)
{		 
	 carbonPressurizer = par2;
	 addSlotToContainer(new Slot(par2, 0, 90, 56));
	 addSlotToContainer(new Slot(par2, 1, 54, 56));
	 addSlotToContainer(new Slot(par2, 2, 51, 17));

	 for (int i = 0; i < 3; i++)
	 {
		 for (int k = 0; k < 9; k++)
		 {
			 addSlotToContainer(new Slot(par1InventoryPlayer, k + i * 9 + 9, 8 + k * 18, 84 + i * 18));
		 }
	 }

	 for (int j = 0; j < 9; j++)
	 {
		 addSlotToContainer(new Slot(par1InventoryPlayer, j, 8 + j * 18, 142));
	 }
}

@Override
public boolean canInteractWith(EntityPlayer par1EntityPlayer) {
	 return carbonPressurizer.isUseableByPlayer(par1EntityPlayer);
}
}

 

 

Block

 

public class CarbonPressurizer extends BlockContainer {

private static boolean keepInventory = false;

private IIcon side0;
private IIcon side1;
private IIcon side2;
private IIcon side3;
private IIcon side4;
private IIcon side5;

public CarbonPressurizer(Material m) {
	super(m);
	this.setCreativeTab(CreativeTabs.tabBlock);
	this.setBlockName("carbon_pressurizer");
	this.setHardness(3.5f);
	this.setResistance(17.5f);
	this.setStepSound(Block.soundTypePiston);
}

public void registerBlockIcons(IIconRegister icon) {
	side0 = icon.registerIcon("timmehutils:carbon_pressurizer_bottom");
	side1 = icon.registerIcon("timmehutils:carbon_pressurizer_top");
	side2 = icon.registerIcon("timmehutils:carbon_pressurizer_side");
	side3 = icon.registerIcon("timmehutils:carbon_pressurizer_side");
	side4 = icon.registerIcon("timmehutils:carbon_pressurizer_side");
	side5 = icon.registerIcon("timmehutils:carbon_pressurizer_side");
}

public IIcon getIcon(int side, int meta) {
	switch (side)
	{
		case 0:
			return side0;
		case 1:
			return side1;
		case 2:
			return side2;
		case 3:
			return side3;
		case 4:
			return side4;
		case 5:
			return side5;
		default:
			return null;
	}
}

@Override
public TileEntity createNewTileEntity(World world, int i) {
	return new TileEntityCarbonPressurizer();
}

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float hitX, float hitY, float hitZ) {
        if(world.isRemote) {
            if (world.getTileEntity(x, y, z) != null)
                player.openGui(Main.instance, GUIs.carbon_pressurizer.ordinal(), world, x, y, z);
            return true;
        }
        return true;
    }
}

 

 

TileEntity

 

public class TileEntityCarbonPressurizer extends TileEntity implements IInventory {

public ItemStack items[];

public TileEntityCarbonPressurizer()
{
	 items = new ItemStack[3];
}

@Override
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
	 super.readFromNBT(par1NBTTagCompound);
	 NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items", 0);
	 items = new ItemStack[getSizeInventory()];

	 for (int i = 0; i < nbttaglist.tagCount(); i++)
	 {
		 NBTTagCompound nbttagcompound = (NBTTagCompound)nbttaglist.getCompoundTagAt(i);
		 byte byte0 = nbttagcompound.getByte("Slot");

		 if (byte0 >= 0 && byte0 < items.length)
		 {
			 items[byte0] = ItemStack.loadItemStackFromNBT(nbttagcompound);
		 }
	 }
}

@Override
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
	 super.writeToNBT(par1NBTTagCompound);
	 NBTTagList nbttaglist = new NBTTagList();

	 for (int i = 0; i < items.length; i++)
	 {
		 if (items[i] != null)
		 {
			 NBTTagCompound nbttagcompound = new NBTTagCompound();
			 nbttagcompound.setByte("Slot", (byte)i);
			 items[i].writeToNBT(nbttagcompound);
			 nbttaglist.appendTag(nbttagcompound);
		 }
	 }

	 par1NBTTagCompound.setTag("Items", nbttaglist);
}

@Override
    public ItemStack getStackInSlot(int slot) {
            return items[slot];
    }
    
    @Override
    public void setInventorySlotContents(int slot, ItemStack stack) {
            items[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 String getInventoryName() {
	return "tile_entity.carbon_pressurizer";
}


@Override
public boolean hasCustomInventoryName() {
	return false;
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this &&
                player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}

@Override
public void openInventory() {
	// TODO Auto-generated method stub

}

@Override
public void closeInventory() {
	// TODO Auto-generated method stub

}

@Override
public boolean isItemValidForSlot(int par1, ItemStack par2) {
	// TODO Auto-generated method stub
	return true;
}

@Override
public int getSizeInventory() {
	return items.length;
}	
}

 

 

GUI

 

public class CarbonPressurizerGUI extends GuiContainer {
private TileEntityCarbonPressurizer carbonPressurizerInventory;

public CarbonPressurizerGUI(InventoryPlayer inventory, TileEntityCarbonPressurizer entity)
{
	 super(new ContainerCarbonPressurizer(inventory, entity));
	 carbonPressurizerInventory = entity;
}

protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
	 fontRendererObj.drawString(StatCollector.translateToLocal("container.inventory"), 8, (ySize - 96) + 2, 0xffffff);
}

protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
	 ResourceLocation i = new ResourceLocation("timmehutils:textures\\guis\\carbon_pressurizer_gui.png");
	 GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	 mc.renderEngine.bindTexture(i);
	 int j = (width - xSize) / 2;
	 int k = (height - ySize) / 2;
	 drawTexturedModalRect(j, k, 0, 0, xSize, ySize);
}
}

 

 

Main

 

@Mod(modid=Main.MODID, name=Main.MODNAME, version=Main.MODVER)
public class Main {	
@Instance("Main")
    public static Main instance;

@SidedProxy(clientSide="com.atimmeh33.timmehutils.ClientProxy", serverSide="com.atimmeh33.timmehutils.ServerProxy")
public static CommonProxy proxy; 

public final static String MODID = "timmehutils";
public final static String MODNAME = "Timmeh's Utilities";
public final static String MODVER = "1.0";

// Items
public static Item carbonChunk, carbonCluster, denseCarbonCluster, crystalizedCarbon;

// Blocks

// BlocksContainers
public static BlockContainer carbonPressurizer;

@EventHandler
    public void preInit (FMLPreInitializationEvent event) {
	NetworkRegistry.INSTANCE.registerGuiHandler(this, this.proxy);
	instance = this;
    }

@EventHandler
public static void Load(FMLInitializationEvent Event) {
	// Forge Events
	MinecraftForge.EVENT_BUS.register(new BlockBreakEventHandler());

	RegisterItems();
	RegisterBlocks();
	RegisterBlockContainers();
	RegisterRecipes();
}

@EventHandler
    public void postInit (FMLPostInitializationEvent event) {
        // Stub Method
    }

public static void RegisterItems()	{
	carbonChunk = new CarbonChunk();
	GameRegistry.registerItem(carbonChunk, "carbon_chunk");
	LanguageRegistry.addName(carbonChunk, "Carbon Chunk");

	carbonCluster = new CarbonCluster();
	GameRegistry.registerItem(carbonCluster, "carbon_cluster");
	LanguageRegistry.addName(carbonCluster, "Carbon Cluster");

	denseCarbonCluster = new DenseCarbonCluster();
	GameRegistry.registerItem(denseCarbonCluster, "dense_carbon_cluster");
	LanguageRegistry.addName(denseCarbonCluster, "Dense Carbon Cluster");

	crystalizedCarbon = new CrystalizedCarbon();
	GameRegistry.registerItem(crystalizedCarbon, "crystalized_carbon");
	LanguageRegistry.addName(crystalizedCarbon, "Crystalized Carbon");	
}

public static  void RegisterBlocks() {

}

public static void RegisterBlockContainers() {
	carbonPressurizer = new CarbonPressurizer(Material.rock);
	GameRegistry.registerBlock(carbonPressurizer, "carbon_pressurizer");
	LanguageRegistry.addName(carbonPressurizer, "Carbon Pressurizer");
}

public static void RegisterRecipes() {
	GameRegistry.addRecipe(new ItemStack(Items.coal),
			"AA",
			"AA",
                'A', carbonChunk);

	GameRegistry.addRecipe(new ItemStack(carbonCluster),
			"AAA",
			"AAA",
			"AAA",
                'A', carbonChunk);

	GameRegistry.addRecipe(new ItemStack(denseCarbonCluster),
			"AAA",
			"AAA",
			"AAA",
                'A', carbonCluster);

	GameRegistry.addRecipe(new ItemStack(carbonPressurizer),
			"AAA",
			"BCB",
			"AAA",
                'A', Blocks.cobblestone, 'B', Blocks.coal_block, 'C', Items.lava_bucket);
}
}

 

Link to comment
Share on other sites

The problem is that you are opening GUI only on client side.

 

Try something like this:

@Override
onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
        TileEntity te = world.getTileEntity(x, y, z);
        if (te != null && te instanceof TileEntityCarbonPressurizer)
                player.openGui(Main.instance, GUIs.carbon_pressurizer.ordinal(), world, x, y, z);

        return super.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ);
}

 

Link to comment
Share on other sites

The problem is that you are opening GUI only on client side.

 

Try something like this:

@Override
onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
        TileEntity te = world.getTileEntity(x, y, z);
        if (te != null && te instanceof TileEntityCarbonPressurizer)
                player.openGui(Main.instance, GUIs.carbon_pressurizer.ordinal(), world, x, y, z);

        return super.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ);
}

 

Hmm, when I changed  this I got the following  error when I open up the GUI

 

-- System Details --
Details:
Minecraft Version: 1.7.10
Operating System: Windows 8.1 (amd64) version 6.3
Java Version: 1.8.0_45, Oracle Corporation
Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
Memory: 874221728 bytes (833 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)
JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M
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.141.1403 Minecraft Forge 10.13.3.1403 4 mods loaded, 4 mods active
mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
FML{7.10.141.1403} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.3.1403-1.7.10.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
Forge{10.13.3.1403} [Minecraft Forge] (forgeSrc-1.7.10-10.13.3.1403-1.7.10.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
timmehutils{1.0} [Timmeh's Utilities] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available
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['Player83'/347, l='New World', x=208,95, y=79,00, z=246,07]]
Type: Integrated Server (map_client.txt)
Is Modded: Definitely; Client brand changed to 'fml,forge'
[18:14:29] [Client thread/INFO] [sTDOUT]: [net.minecraft.client.Minecraft:displayCrashReport:393]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2015-05-17_18.14.29-server.txt
[18:14:29] [Client thread/INFO] [FML]: Waiting for the server to terminate/save.
[18:14:29] [server thread/INFO]: Saving worlds
[18:14:29] [server thread/INFO]: Saving chunks for level 'New World'/Overworld
[18:14:29] [server thread/ERROR] [FML]: A TileEntity type com.atimmeh33.timmehutils.blocks.TileEntityCarbonPressurizer has throw an exception trying to write state. It will not persist. Report this to the mod author
java.lang.RuntimeException: class com.atimmeh33.timmehutils.blocks.TileEntityCarbonPressurizer is missing a mapping! This is a bug!
at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:96) ~[TileEntity.class:?]
at com.atimmeh33.timmehutils.blocks.TileEntityCarbonPressurizer.writeToNBT(TileEntityCarbonPressurizer.java:43) ~[TileEntityCarbonPressurizer.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:395) [AnvilChunkLoader.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:204) [AnvilChunkLoader.class:?]
at net.minecraft.world.gen.ChunkProviderServer.safeSaveChunk(ChunkProviderServer.java:287) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:340) [ChunkProviderServer.class:?]
at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:863) [WorldServer.class:?]
at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:370) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:405) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:266) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:538) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752) [MinecraftServer$2.class:?]

Link to comment
Share on other sites

Cough

java.lang.RuntimeException: class com.atimmeh33.timmehutils.blocks.TileEntityCarbonPressurizer is missing a mapping! This is a bug!

You didn't register your TE

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.

Link to comment
Share on other sites

Cough

java.lang.RuntimeException: class com.atimmeh33.timmehutils.blocks.TileEntityCarbonPressurizer is missing a mapping! This is a bug!

You didn't register your TE

 

Oh shit, while I was writing the code I was even saying to myself when I finish this method I gotta register the tile entity, and still I forgot D:

Let me try and see if that fixes it.

 

Edit:

 

Still getting an error

 

java.lang.ClassCastException: com.atimmeh33.timmehutils.blocks.CarbonPressurizerGUI cannot be cast to net.minecraft.inventory.Container
at cpw.mods.fml.common.network.NetworkRegistry.getRemoteGuiContainer(NetworkRegistry.java:243)
at cpw.mods.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:75)
at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2501)
at com.atimmeh33.timmehutils.blocks.CarbonPressurizer.onBlockActivated(CarbonPressurizer.java:78)

 

Edit 2: Wasn't returning a container @ server-sided proxy. Fixed now. Thanks everyone.

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.