Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Solved]Help with packets


Recommended Posts

Time for what's probably a noob question!

I've never worked with multiplayer modding before, and have no idea how I'm supposed to get packets working. I noticed there's a packets and channels section in the wiki page for updating to 1.3, but there's nothing in there. Any idea when that's going to be done?

In the mean time, I'm trying to set up a gui that handles a custom crafting thing for my mod. When a button is pushed in the gui, the container looks at what's in the two core slots and writes some NBT stuff to the itemstack in the wand slot. How should I make this work? Should the button send off a packet to the server, where all the crafting stuff is done, and then send a packet back with the finished product? if so, how would I go about doing this with what I currently have?

 

If any of my code is needed, here:

(Just a warning, I'm a messy coder, so prepare your eyeholes)

 

GuiWandCrafting.java

 

 

package net.minecraft.src.sorcery;

import org.lwjgl.opengl.GL11;

import net.minecraft.src.*;

public class GuiWandCrafting extends GuiContainer
{
public GuiButtonWandCrafting Button;

    public GuiWandCrafting(InventoryPlayer player, World world, int i, int j, int k)
    {
        super(new ContainerWandCrafting(player, world, i, j, k));
    }
    
    public void initGui()
    {
    	super.initGui();
    	controlList.clear();
    	controlList.add(Button = new GuiButtonWandCrafting(1, width / 2 - 10, height / 2 - 41, true));
    }

    protected void drawGuiContainerForegroundLayer()
    {
        this.fontRenderer.drawString(StatCollector.translateToLocal("container.wandcrafting"), 40, 4, 0);
        this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 0);
    }

    protected void drawGuiContainerBackgroundLayer(float i, int j, int k)
    {
        int background = this.mc.renderEngine.getTexture("/sorcery/guis/wandcrafting.png");
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.renderEngine.bindTexture(background);
        int x = (this.width - this.xSize) / 2;
        int y = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(x, y, 0, 0, this.xSize, this.ySize);
    }
    
    protected void actionPerformed(GuiButton button)
    {
        if(button instanceof GuiButtonWandCrafting && this.Button.canUse)
        {
        	ContainerWandCrafting.craftWand();
        }
    }
}

 

 

 

ContainerWandCrafting.java

 

 

package net.minecraft.src.sorcery;

import net.minecraft.src.*;

public class ContainerWandCrafting extends Container
{
    public InventoryWandCrafting craftSlots = new InventoryWandCrafting(this);
    private World worldObj;
    private int posX;
    private int posY;
    private int posZ;
    public static Slot wandSlot;
    public static Slot crystalSlot;
    public static Slot coreSlot1;
    public static Slot coreSlot2;
    public boolean canRun;

    public ContainerWandCrafting(InventoryPlayer player, World world, int x, int y, int z)
    {
        this.worldObj = world;
        this.posX = x;
        this.posY = y;
        this.posZ = z;
        
        //Core Containers
        coreSlot1 = this.addSlotToContainer(new Slot(this.craftSlots, 0,  44, 17));
        coreSlot2 = this.addSlotToContainer(new Slot(this.craftSlots, 1, 116, 17));
        
        //Crystal Container
        crystalSlot = this.addSlotToContainer(new Slot(this.craftSlots, 2, 80, 56));
        
        //Wand Container
        wandSlot = this.addSlotToContainer(new Slot(this.craftSlots, 3, 80, 17));   
        
        for (int i = 0; i < 3; ++i)
        {
            for (int j = 0; j < 9; ++j)
            {
                this.addSlotToContainer(new Slot(player, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
            }
        }

        for (int i = 0; i < 9; ++i)
        {
            this.addSlotToContainer(new Slot(player, i, 8 + i * 18, 142));
        }
    }
    
    public static void craftWand()
    {
    	EnumWandMods[] wandMods = new EnumWandMods[3];
    	ItemStack wand = wandSlot.getStack();
    	ItemStack crystal = crystalSlot.getStack();
    	ItemStack core1 = coreSlot1.getStack();
    	ItemStack core2 = coreSlot2.getStack();
    	
    	if(wandSlot.getHasStack() && crystalSlot.getHasStack())
    	{
    		if(wand.itemID == (new ItemStack(Sorcery.wand)).itemID && crystal.itemID == (new ItemStack(Sorcery.battery, 1, 0)).itemID && crystal.getItemDamage() == 0)
    		{
    			System.out.println("There's a " + wand + " in the wand slot and a " + crystal + " in the crystal slot.");
    			System.out.println("Core 1: " + core1 + ". Core 2: " + core2 + ".");
    			System.out.println("There are " + EnumWandMods.values().length + " Wand Modifiers;");
    			int j = 0;
    			
    			for(EnumWandMods mods : EnumWandMods.values())
    			{
        			System.out.println(EnumWandMods.values()[j].item);
    				if(coreSlot1.getHasStack())
    				{
    					if(core1.itemID == EnumWandMods.values()[j].item.itemID)
    					{
    						wandMods[0] = SorceryHelper.getInstance().addWandMod(EnumWandMods.values()[j].item);
    						coreSlot1.decrStackSize(1);
    						System.out.println(wandMods[0]);
    					}
    				}
    				
    				if(coreSlot2.getHasStack())
    				{
    					if(core2.itemID == EnumWandMods.values()[j].item.itemID)
    					{
    						wandMods[1] = SorceryHelper.getInstance().addWandMod(EnumWandMods.values()[j].item);
    	        	    	coreSlot2.decrStackSize(1);
    						System.out.println(wandMods[1]);
    					}
    				}
    				j = j+1;
    			}	
    			
    			crystalSlot.decrStackSize(1);
    			
    			wand.setTagCompound(new NBTTagCompound());
    			wand.stackTagCompound.setTag("mods", new NBTTagList("mods"));
    			NBTTagList list = (NBTTagList)wand.stackTagCompound.getTag("mods");
    			
    			for(int i = 0; i > wandMods.length; i++)
    			{
    				NBTTagCompound tag = new NBTTagCompound();
    				tag.setInteger("ID", wandMods[i].modID);
    				tag.setBoolean("Positive", wandMods[i].pos);
    				list.appendTag(tag);
    			}
    		}
    	}
    }

    public void onCraftGuiClosed(EntityPlayer player)
    {
        super.onCraftGuiClosed(player);

        if (!this.worldObj.isRemote)
        {
            for (int var2 = 0; var2 < 4; ++var2)
            {
                ItemStack var3 = this.craftSlots.getStackInSlotOnClosing(var2);

                if (var3 != null)
                {
                    player.dropPlayerItem(var3);
                }
            }
        }
    }

    public boolean canInteractWith(EntityPlayer player)
    {
        return this.worldObj.getBlockId(this.posX, this.posY, this.posZ) != Sorcery.machine.blockID ? false : player.getDistanceSq((double)this.posX + 0.5D, (double)this.posY + 0.5D, (double)this.posZ + 0.5D) <= 64.0D;
    }
}

 

 

 

The addWandMod method from SorceryHelper

 

 

public EnumWandMods addWandMod(ItemStack item)
{
	int i = 0;
	for(EnumWandMods mods: EnumWandMods.values())
	{
		if(EnumWandMods.values()[i].item.itemID == item.itemID)
		{
			return EnumWandMods.values()[i];
		}
		i++;
	}
return EnumWandMods.empty;
}

 

 

 

Tell me if there's any more information you need.

 

Thanks

 

EDIT: Changed the question a bit.

Link to post
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.

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



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.