Posted September 20, 201312 yr Hi Guys! I want to create a Gui for a new Sign, which is shown when te sign is placed, but it won't work. I don't really know why and I need some help.. My Code: ItemSign: public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { //Rotate the sign correctly par3World.setBlock(par4, par5, par6, Blocks.Sign.blockID, par7, 3); if (!par2EntityPlayer.capabilities.isCreativeMode) --par1ItemStack.stackSize; //Don't Quite know, what's correct. // FMLNetworkHandler.openGui(par2EntityPlayer, Main.instance, 0, par3World, par4, par5, par6); if (!par3World.isRemote) par2EntityPlayer.openGui(Main.instance, 0, par3World, par4, par5, par6); return true; } BlockSign (Copied from a Tutorial) package mod.classes.advanced; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.entity.EntityLiving; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class ModBlockSign extends BlockContainer { public ModBlockSign(int par1, Material par2Material) { super(par1, par2Material); this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); } @Override public TileEntity createNewTileEntity(World world) { return new TileEntitySign(); } @Override public int getRenderType() { return -1; } @Override public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } //I think you don't need this: public void registerIcons(IconRegister icon) { this.blockIcon = icon.registerIcon("moresigns:sign"); } public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLiving par5EntityLiving, ItemStack par6ItemStack) { int l = MathHelper.floor_double((double)(par5EntityLiving.rotationYaw * 4.0F / 360.0F) + 2.5D) & 3; par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2); } @SideOnly(Side.CLIENT) public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4) { this.setBlockBoundsBasedOnState(par1World, par2, par3, par4); return super.getSelectedBoundingBoxFromPool(par1World, par2, par3, par4); } public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4) { int l = par1IBlockAccess.getBlockMetadata(par2, par3, par4); float f = 0.0F; float f1 = 1.0F; float f2 = 0.0F; float f3 = 1.0F; float f4 = 0.125F; this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); if (l == 2) { this.setBlockBounds(f2, f, 1.0F - f4, f3, f1, 1.0F); } if (l == 3) { this.setBlockBounds(f2, f, 0.0F, f3, f1, f4); } if (l == 4) { this.setBlockBounds(1.0F - f4, f, f2, 1.0F, f1, f3); } if (l == 5) { this.setBlockBounds(0.0F, f, f2, f4, f1, f3); } } public AxisAlignedBB getCollisionBoundingBoxFromPool(World par1World, int par2, int par3, int par4) { return null; } } GuiHandler: package mod.classes.gui; import mod.Main; import mod.classes.advanced.TileEntitySign; import net.minecraft.client.gui.inventory.GuiEditSign; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; import cpw.mods.fml.common.network.NetworkRegistry; public class ModGuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getBlockTileEntity(x, y, z); System.out.println("Server"); switch(ID) { case 0: if (entity instanceof TileEntitySign) return null; //Don't know what to return here; think that's the mistake else return null; default: return null; } } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getBlockTileEntity(x, y, z); System.out.println("Client"); switch(ID) { case 0: if (entity instanceof TileEntitySign) return new GuiEditSign((net.minecraft.tileentity.TileEntitySign) world.getBlockTileEntity(x, y, z)); else return null; default: return null; } } public ModGuiHandler() { NetworkRegistry.instance().registerGuiHandler(Main.instance, this); } } GUI: (Copied from Vanilla Sign) package mod.classes.gui; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.multiplayer.NetClientHandler; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.network.packet.Packet130UpdateSign; import net.minecraft.tileentity.TileEntitySign; import net.minecraft.util.ChatAllowedCharacters; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; @SideOnly(Side.CLIENT) public class EditSignGui extends GuiScreen { /** * This String is just a local copy of the characters allowed in text rendering of minecraft. */ private static final String allowedCharacters = ChatAllowedCharacters.allowedCharacters; /** The title string that is displayed in the top-center of the screen. */ protected String screenTitle = "Sign Message (Redstone off):"; /** Reference to the sign object. */ private TileEntitySign entitySign; /** Counts the number of screen updates. */ private int updateCounter; /** The number of the line that is being edited. */ private int editLine; /** Editing the Redstone-active Text or not */ private boolean redstoneText = false; /** "Done" button for the GUI. */ private GuiButton doneBtn; private GuiButton redstonePowered; public EditSignGui(TileEntitySign par1TileEntitySign) { this.entitySign = par1TileEntitySign; } /** * Adds the buttons (and other controls) to the screen in question. */ public void initGui() { this.buttonList.clear(); Keyboard.enableRepeatEvents(true); this.buttonList.add(this.doneBtn = new GuiButton(0, this.width / 2 - 100, this.height / 4 + 120, "Done")); this.buttonList.add(this.redstonePowered = new GuiButton(1, this.width / 2 - 100, this.height / 4 + 80, "Redstone state on/off")); this.entitySign.setEditable(false); } /** * Called when the screen is unloaded. Used to disable keyboard repeat events */ public void onGuiClosed() { //TODO: Need to be edited! /* Keyboard.enableRepeatEvents(false); NetClientHandler netclienthandler = this.mc.getNetHandler(); if (netclienthandler != null) { netclienthandler.addToSendQueue(new Packet130UpdateSign(this.entitySign.xCoord, this.entitySign.yCoord, this.entitySign.zCoord, this.entitySign.signText)); } this.entitySign.setEditable(true); */ } /** * Called from the main game loop to update the screen. */ public void updateScreen() { ++this.updateCounter; } /** * Fired when a control is clicked. This is the equivalent of ActionListener.actionPerformed(ActionEvent e). */ protected void actionPerformed(GuiButton par1GuiButton) { if (par1GuiButton.enabled) { if (par1GuiButton.id == 0) { this.entitySign.onInventoryChanged(); this.mc.displayGuiScreen((GuiScreen)null); } if (par1GuiButton.id == 1) { } } } /** * Fired when a key is typed. This is the equivalent of KeyListener.keyTyped(KeyEvent e). */ protected void keyTyped(char par1, int par2) { if (par2 == 200) { this.editLine = this.editLine - 1 & 3; } if (par2 == 208 || par2 == 28 || par2 == 156) { this.editLine = this.editLine + 1 & 3; } if (par2 == 14 && this.entitySign.signText[this.editLine].length() > 0) { this.entitySign.signText[this.editLine] = this.entitySign.signText[this.editLine].substring(0, this.entitySign.signText[this.editLine].length() - 1); } if (allowedCharacters.indexOf(par1) >= 0 && this.entitySign.signText[this.editLine].length() < 15) { this.entitySign.signText[this.editLine] = this.entitySign.signText[this.editLine] + par1; } if (par2 == 1) { this.actionPerformed(this.doneBtn); } } /** * Draws the screen and all the components in it. */ public void drawScreen(int par1, int par2, float par3) { this.drawDefaultBackground(); this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, 40, 16777215); GL11.glPushMatrix(); GL11.glTranslatef((float)(this.width / 2), 0.0F, 50.0F); float f1 = 93.75F; GL11.glScalef(-f1, -f1, -f1); GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F); Block block = this.entitySign.getBlockType(); if (block == Block.signPost) { float f2 = (float)(this.entitySign.getBlockMetadata() * 360) / 16.0F; GL11.glRotatef(f2, 0.0F, 1.0F, 0.0F); GL11.glTranslatef(0.0F, -1.0625F, 0.0F); } else { int k = this.entitySign.getBlockMetadata(); float f3 = 0.0F; if (k == 2) { f3 = 180.0F; } if (k == 4) { f3 = 90.0F; } if (k == 5) { f3 = -90.0F; } GL11.glRotatef(f3, 0.0F, 1.0F, 0.0F); GL11.glTranslatef(0.0F, -1.0625F, 0.0F); } if (this.updateCounter / 6 % 2 == 0) { this.entitySign.lineBeingEdited = this.editLine; } TileEntityRenderer.instance.renderTileEntityAt(this.entitySign, -0.5D, -0.75D, -0.5D, 0.0F); this.entitySign.lineBeingEdited = -1; GL11.glPopMatrix(); super.drawScreen(par1, par2, par3); } } I hope, anybody knows, which mistake I made. Thanks in Advance! http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
September 21, 201312 yr dont return null on server side. you want to add your tileentity there, or a container. sign gui's are bound to their TE and edit strings from the TE to show the message. https://minecraft.curseforge.com/members/Subaraki/projects
September 21, 201312 yr dont return null on server side. you want to add your tileentity there, or a container. sign gui's are bound to their TE and edit strings from the TE to show the message. For a strictly client side GUI that shouldnt be necessary. Its probably not working because the vanilla sign GUI notices that it doesnt have a container.
September 22, 201312 yr You seriously need to do something here public void onGuiClosed() { //TODO: Need to be edited! /* Keyboard.enableRepeatEvents(false); NetClientHandler netclienthandler = this.mc.getNetHandler(); if (netclienthandler != null) { netclienthandler.addToSendQueue(new Packet130UpdateSign(this.entitySign.xCoord, this.entitySign.yCoord, this.entitySign.zCoord, this.entitySign.signText)); } this.entitySign.setEditable(true); */ }
September 22, 201312 yr Author @GotoLink: But this shouldn't stop the Gui from being shown. @khlorghaal: I tried it with a custom GUI and even this isn't shown I think, it's because the getClientGuiElement method isn't called... Any ideas why? @SenpaiSubaraki: I don't have any container to return and with a TE Java responds with a Cast-Exception. http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
September 22, 201312 yr Author I don't limit the Call to the server side.. I do it like this: public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) { [...] par2EntityPlayer.openGui(Main.instance, 0, par3World, par4, par5, par6); return true; } } } And I don't know, which container to use, because I actually don't have one http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
September 29, 201311 yr Author The problem is, that the client side is never called. Only Server side gets a call. How can I solve this problem? http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
September 29, 201311 yr Author I added System.out.println(par3World.isRemote); And it only prints out false on server side and nothing on client side. I got the same problem in another project: http://www.minecraftforge.net/forum/index.php/topic,12543.0.html Have I done something wrong in the Initialisation of the Mod? package mod; import mod.classes.advanced.TileEntitySign; import mod.initialization.Blocks; import mod.initialization.Configurations; import mod.initialization.Items; import mod.initialization.Languages; import mod.initialization.Registrations; import mod.proxies.ClientProxy; import mod.proxies.CommonProxy; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.*; 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.NetworkMod; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; @Mod(modid = Main.modID, name = Main.modName, version = "1.0.0") @NetworkMod(clientSideRequired = true, serverSideRequired = false) public class Main { public static final String modID = "moreSigns"; public static final String modName = "More Signs Mod"; public static int ItemStartID; public static int BlockStartID; @Instance(modID) public static Main instance; @SidedProxy(clientSide = "mod.proxies.ClientProxy", serverSide = "mod.proxies.CommonProxy") public static CommonProxy proxy; @EventHandler public void PreInit(FMLPreInitializationEvent e){ Configurations.load(e); } @EventHandler public void Init(FMLInitializationEvent e){ Items.init(ItemStartID); //unimportant Blocks.init(BlockStartID); //unimportant Languages.load(); //unimportant Registrations.init(); proxy.renderThings(); } @EventHandler public void PostInit(FMLPostInitializationEvent e){ } } public static void init() { GameRegistry.registerTileEntity(TileEntitySign.class, "tileEntitySign"); new ModGuiHandler(); } public class ClientProxy extends CommonProxy{ public void renderThings(){ ClientRegistry.bindTileEntitySpecialRenderer(TileEntitySign.class, new TileEntitySignRenderer()); } } Write, if you need more code! http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
September 29, 201311 yr TileEntitySign is the name of the vanilla class. Try changing your custom sign to a different name. http://i.imgur.com/NdrFdld.png[/img]
September 30, 201311 yr Author I changed it, but this doesn't solve the problem, that it's only called on Server-side. http://i.imgur.com/wNvtGZw.png[/img] MODS and MODDING TUTORIALS
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.