Jump to content

Recommended Posts

Posted

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!

 

Posted

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.

Posted

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); */
    }

Posted

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

Posted

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!

 

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Ah, it appears I spoke too soon, I still need a little help here. I now have the forceloading working reliably.  However, I've realized it's not always the first tick that loads the entity.  I've seen it take anywhere from 2-20ish to actually go through, in which time my debugging has revealed that the chunk is loaded, but during which time calling  serverLevelIn.getEntity(uuidIn) returns a null result.  I suspect this has to do with queuing and how entities are loaded into the game.  While not optimal, it's acceptable, and I don't think there's a whole ton I can do to avoid it. However, my concern is that occasionally teleporting an entity in this manner causes a lag spike.  It's not every time and gives the appearance of being correlated with when other chunks are loading in.  It's also not typically a long spike, but can last a second or two, which is less than ideal.  The gist of how I'm summoning is here (although I've omitted some parts that weren't relevant.  The lag occurs before the actual summon so I'm pretty confident it's the loading, and not the actual summon call). ChunkPos chunkPos = new ChunkPos(entityPosIn); if (serverLevelIn.areEntitiesLoaded(chunkPos.toLong())) { boolean isSummoned = // The method I'm using for actual summoning is called here. Apart from a few checks, the bulk of it is shown later on. if (isSummoned) { // Code that runs here just notifies the player of the summon, clears it from the queue, and removes the forceload } } else { // I continue forcing the chunk until the summon succeeds, to make sure it isn't inadvertently cleared ForgeChunkManager.forceChunk(serverLevelIn, MODID, summonPosIn, chunkPos.x, chunkPos.z, true, true); } The summon code itself uses serverLevelIn.getEntity(uuidIn) to retrieve the entity, and moves it as such.  It is then moved thusly: if (entity.isAlive()) { entity.moveTo(posIn.getX(), posIn.getY(), posIn.getZ()); serverLevelIn.playSound(null, entity, SoundEvents.ENDERMAN_TELEPORT, SoundSource.NEUTRAL, 1.0F, 1.0F); return true; } I originally was calling .getEntity() more frequently and didn't have the check for whether or not entities were loaded in place to prevent unnecessary code calls, but even with those safety measures in place, the lag still persists.  Could this just be an issue with 1.18's lack of optimization in certain areas?  Is there anything I can do to mitigate it?  Is there a performance boosting mod I could recommend alongside my own to reduce the chunk loading lag? At the end of the day, it does work, and I'm putting measures in place to prevent players from abusing the system to cause lag (i.e. each player can only have one queued summon at a time-- trying to summon another replaces the first call).  It's also not an unacceptable level of lag, IMO, given the infrequency of such calls, and the fact that I'm providing the option to toggle off the feature if server admins don't want it used.  However, no amount of lag is ideal, so if possible I'd love to find a more elegant solution-- or at least a mod recommendation to help improve it. Thanks!
    • When i start my forge server its on but when i try to join its come a error Internal Exception: java.lang.OutOfMemoryError: Requested array size exceeds VM limit Server infos: Linux Minecraft version 1.20.1 -Xmx11G -Xms8G
    • Also add the latest.log from your logs-folder
    • Add the mods in groups
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.