Jump to content

Bugzoo

Members
  • Posts

    268
  • Joined

  • Last visited

Posts posted by Bugzoo

  1.   On 11/16/2014 at 5:02 PM, diesieben07 said:

    Don't return the message in onMessage! What you return there is send as a response to whoever sent the incoming packet. Normally you want to return null there. And again: Do not register your packets for both sides! (If you had fixed that the error would be different).

     

    Where am I registering it on both sides?

  2.   On 11/16/2014 at 4:47 PM, diesieben07 said:

    Copy and paste the full console output from your IDE.

     

    Oh, right

     

      Reveal hidden contents

     

  3.   On 11/16/2014 at 4:15 PM, diesieben07 said:

    Post the full log.

     

     

      Reveal hidden contents

     

  4.   On 11/16/2014 at 3:55 PM, diesieben07 said:

    a) Why do you register your packet for being sent both ways? It should only go client -> server.

    b) Why do you send and integer and a boolean when you never use them?

    c) You need to use the serverside player when receiving the packet, you get it from the MessageContext.

    d) Your packet has the potential of allowing players to infinitely create your Item over and over again. The server needs to check if it is ok for the client to send that packet, otherwise hacked clients could exploit it.

     

    How do I get it from the MessageContext?

  5. Ok, this may potentially be the most nooby question you will ever see, and it might make you want to shoot yourself. Please dont. So, I want to give the player an item when I click a button, but this isn't working

     

    Button:

    public void actionPerformed(GuiButton guibutton){
    	if(guibutton.id == 24){
    		// Sending packet to server
    		IMessage msg = new SimplePacket.SimpleMessage(500, true);
    		PacketHandler.net.sendToServer(msg);
    
    	}
    }

     

    PacketHandler:

    package com.bugzoo.FinancialMod;
    
    import cpw.mods.fml.common.network.NetworkRegistry;
    import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
    import cpw.mods.fml.relauncher.Side;
    
    public class PacketHandler
    {
    public static SimpleNetworkWrapper net;
    public static void initPackets()
    {
    net = NetworkRegistry.INSTANCE.newSimpleChannel("YourModId".toUpperCase());
    registerMessage(SimplePacket.class, SimplePacket.SimpleMessage.class);
    }
    private static int nextPacketId = 0;
    private static void registerMessage(Class packet, Class message)
    {
    	net.registerMessage(packet, message, nextPacketId, Side.CLIENT);
    	net.registerMessage(packet, message, nextPacketId, Side.SERVER);
    	nextPacketId++;
    }
    }

     

    SimplePacket:

    package com.bugzoo.FinancialMod;
    
    import io.netty.buffer.ByteBuf;
    import net.minecraft.client.Minecraft;
    import net.minecraft.item.ItemStack;
    
    import com.bugzoo.FinancialMod.SimplePacket.SimpleMessage;
    
    import cpw.mods.fml.common.network.simpleimpl.IMessage;
    import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
    import cpw.mods.fml.common.network.simpleimpl.MessageContext;
    
    public class SimplePacket implements IMessageHandler<SimpleMessage, IMessage>
    {
    
    Minecraft mc;
    @Override
    public IMessage onMessage(SimpleMessage message, MessageContext ctx)
    {
    // just to make sure that the side is correct
    if (ctx.side.isClient())
    {
    mc.thePlayer.inventory.addItemStackToInventory(new ItemStack(FinancialMod.Wallet));
    int integer = message.simpleInt;
    boolean bool = message.simpleBool;
    }
    return message;
    }
    public static class SimpleMessage implements IMessage
    {
    	private int simpleInt;
    	private boolean simpleBool;
    		// this constructor is required otherwise you'll get errors (used somewhere in fml through reflection)
    	public SimpleMessage() {}
    	public SimpleMessage(int simpleInt, boolean simpleBool)
    	{
    		this.simpleInt = simpleInt;
    		this.simpleBool = simpleBool;
    	}
    	@Override
    	public void fromBytes(ByteBuf buf)
    	{
    		// the order is important
    		this.simpleInt = buf.readInt();
    		this.simpleBool = buf.readBoolean();
    	}
    	@Override
    		public void toBytes(ByteBuf buf)
    	{
    		buf.writeInt(simpleInt);
    		buf.writeBoolean(simpleBool);
    }
    }
    }

     

     

  6.   On 11/11/2014 at 6:59 PM, diesieben07 said:

    "You have"? I assume you mean the player. If not, please elaborate.

    For storing additional data about a player use IExtendedEntityProperties.

     

    Yea, I mean the player. Do you have any examples on how to do this?

     

  7.   On 11/2/2014 at 6:27 PM, jabelar said:

    I don't think it makes sense that "the packet opens a gui" based on a button press.  The buttons are already pressed on the client side where the GUI is open.  So you can open guis however you want without packets.  But if you need information from the server, or if you need gui to cause an effect on the server, that's when you would send a packet.

     

    I cant open a gui from with the actionPerformed() method because it doesn't have the right perameters

  8.   On 11/2/2014 at 5:48 PM, Ernio said:

    And what exacly you want to do? Send packet on GUI open? With button? On closed? on tick? Packet to who? All players or just server?

    You have to be more specific.

     

    I want it to send a packet when I press a button and the packet opens a gui

  9.   On 11/2/2014 at 3:34 PM, RaxiCax said:

    Okay, it's rendering in the game now!

     

    Great! Now, I've another problem .. The texture isn't showing!

     

    Try using this

    private static final ResourceLocation texture = new ResourceLocation(MODID + ":" + "textures/model/modelalchemycauldron.png");

×
×
  • Create New...

Important Information

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