Jump to content

Recommended Posts

Posted

hello. I did create a machine with that you can create Modules.

Now i have a bug i saw at EE3 (Direwolf20MPLP), that you can not use the transmuationcrafting.

Now i have the same problem. I want to create a new Item in the same slot (in this case a diamond) and it transforms back into my Item^^ i have no idea how that happends^^.

 

Here My ModulMaker source! I am not on 1.6/1.5. I still work on 1.4. But the code is the same.

 

package speiger.src.tinychest.common.tileentity.machines.machine;

import cpw.mods.fml.common.FMLLog;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.liquids.LiquidStack;
import speiger.src.api.api.ICable;
import speiger.src.api.api.IMachine;
import speiger.src.api.api.modules.advanced.ModulMakerRecipeRegister;
import speiger.src.api.common.functions.WorldReading;
import speiger.src.api.common.tile.TileFacing;
import speiger.src.tinychest.common.config.TinyItems;
import speiger.src.tinychest.common.items.module.ItemEmptyModul;
import speiger.src.tinychest.common.items.module.ModulCore;

public class ModuleMaker extends TileFacing implements IInventory, IMachine
{
public int[] button = new int[3];
public int[] progressButton = new int[6];
public ItemStack[] modulStack = new ItemStack[8];
public int progress = 0;
public int maxProgress = 7200;
public int mode = 0;
public int progressmode = 0;
public int energy = 0;
public int maxEnergy = 100000;

private void updateButtons() 
{
	if(button[0] > 0)
	{
		mode = 1;
	}
	if(button[1] > 0)
	{
		mode = 2;
	}
	if(button[2] > 0)
	{
		mode = 3;
	}

	if(progressButton[0] > 0)
	{
		progressmode = 1;
	}
	if(progressButton[1] > 0)
	{
		progressmode = 2;
	}
	if(progressButton[2] > 0)
	{
		progressmode = 3;
	}
	if(progressButton[3] > 0)
	{
		progressmode = 4;
	}
	if(progressButton[4] > 0)
	{
		progressmode = 5;
	}
	if(progressButton[5] > 0)
	{
		progressmode = 6;
	}

}

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

    public ItemStack getStackInSlot(int par1)
    {
        return this.modulStack[par1];
    }

    public ItemStack decrStackSize(int par1, int par2)
    {
        if (this.modulStack[par1] != null)
        {
            ItemStack var3;

            if (this.modulStack[par1].stackSize <= par2)
            {
                var3 = this.modulStack[par1];
                this.modulStack[par1] = null;
                return var3;
            }
            else
            {
                var3 = this.modulStack[par1].splitStack(par2);

                if (this.modulStack[par1].stackSize == 0)
                {
                    this.modulStack[par1] = null;
                }

                return var3;
            }
        }
        else
        {
            return null;
        }
    }
   
    public ItemStack getStackInSlotOnClosing(int par1)
    {
        if (this.modulStack[par1] != null)
        {
            ItemStack var2 = this.modulStack[par1];
            this.modulStack[par1] = null;
            return var2;
        }
        else
        {
            return null;
        }
    }

    public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
    {
        this.modulStack[par1] = par2ItemStack;

        if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
        {
            par2ItemStack.stackSize = this.getInventoryStackLimit();
        }
    }

    public String getInvName()
    {
        return "Module Maker";
    }

public int getInventoryStackLimit() 
{
	return 1;
}

public boolean isUseableByPlayer(EntityPlayer var1) 
{
	return true;
}

public void openChest() 
{
}

@Override
public void closeChest() 
{
}

@Override
public void updateEntity() 
{
	super.updateEntity();
	updateButtons();
	updateCable();
	createModul();
}

public void createModul()
{
	if(progressmode == 1)
	{
		createCleanModul();
	}
	if(progressmode == 2)
	{
		setModulKind();
	}


}

public void setModulKind() 
{

}

public void createCleanModul() 
{

	if(modulStack[0] != null && modulStack[0].getItem() instanceof ModulCore)
	{
		progress+= 10;
		FMLLog.getLogger().info("Progress: "+progress);
		if(progress >= getProgressFromMode())
		{
			progress = 0;
			ItemStack par1 = new ItemStack(Item.diamond, 1);
			modulStack[0] = null;
			modulStack[0] = par1.copy();




		}
	}

}

public int getProgressFromMode() 
{
	if(mode == 1)return maxProgress / 2;
	else if(mode == 2)return maxProgress;
	else return maxProgress*2;
}

public void updateCable()
{
	for(int i = 0;i<6;i++)
	{
		TileEntity tile = WorldReading.getTileEntity(worldObj, xCoord, yCoord, zCoord, i);
		if(tile != null && tile instanceof ICable)
		{
			ICable ic = (ICable) tile;
			ic.setPriorty(0);
		}
	}
}

@Override
public boolean needEnergie() 
{
	return energy < maxEnergy;
}

@Override
public int getMaxStoredEnergy() 
{
	return maxEnergy;
}

@Override
public int getStoredEnergy() 
{
	return energy;
}

@Override
public void sendEnergyToMachine(int i) 
{
	energy += i;
}

@Override
public int getTransferlimit() 
{
	return 128;
}

@Override
public int getEnergyOutOfMachine(int i)
{
	return 0;
}

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

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

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

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

@Override
public LiquidStack getLiquidID() 
{
	return null;
}

@Override
public int getStoredLiquid() 
{
	return 0;
}

@Override
public int getMaxLiquidLevel() 
{
	return 0;
}

@Override
public void setLiquidID(LiquidStack par1) 
{
}

@Override
public void sendLiquid(int i)
{
}

@Override
public int suckLiquidOutOfMachine(int i) 
{
	return 0;
}





}

 

Can you help me with that bug?

 

Posted

If you don't want to help me then tell it and don't let me wait hours for an answer!

And if you do not know how to fix it tell it me too.

Posted

Man, this is a forum, anyone can chose to answer or not.

 

                                progress = 0;
			ItemStack par1 = new ItemStack(Item.diamond, 1);
			modulStack[0] = null;
			modulStack[0] = par1.copy();

can't you just do instead:

setInventorySlotContents(0, new ItemStack(Item.diamond));

 

Posted

Man, this is a forum, anyone can chose to answer or not.

 

                                progress = 0;
			ItemStack par1 = new ItemStack(Item.diamond, 1);
			modulStack[0] = null;
			modulStack[0] = par1.copy();

can't you just do instead:

setInventorySlotContents(0, new ItemStack(Item.diamond));

 

 

i already tried this way^^ The item still Transform back to the old Item!

 

Posted

Ok i did find out what the problem is!

My buttoncode is the problem! Without that i can make the items without problems.

Now my Problem is i can not work without my Buttons^^.

I mean the RecipeList ist to complex to do it without buttons.

So the question is how do i fix it?

Do you need more source to find the error?

 

Posted

Here is my Whole source.

 

Gui ModuleMaker


package speiger.src.tinychest.client.gui.machines.machine;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.StatCollector;

import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;

import cpw.mods.fml.common.FMLLog;

import speiger.src.tinychest.common.container.machines.machine.ContainerModulMaker;
import speiger.src.tinychest.common.tileentity.machines.machine.ModuleMaker;

public class GuiModuleMaker extends GuiContainer 
{
private ModuleMaker tile;

public GuiModuleMaker(InventoryPlayer par1, ModuleMaker par2) 
{
	super(new ContainerModulMaker(par1, par2));
	tile = par2;
	this.ySize = 232;
	this.xSize = 211;
}


protected void drawGuiContainerForegroundLayer(int par1, int par2)
    {
	this.fontRenderer.drawString("Fast", 38, 128, 0xffffff);
	this.fontRenderer.drawString("Med", 80, 128, 0xffffff);
	this.fontRenderer.drawString("Slow", 118, 128, 0xffffff);
        this.fontRenderer.drawString("Module Maker", 65, 6, 4210752);
        this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 5, 4210752);
        this.fontRenderer.drawString("Clearing", 153, 10, 0xffffff);
        this.fontRenderer.drawString("Specify", 155, 30, 0xffffff);
        this.fontRenderer.drawString("Production", 146, 50, 0xffffff);
        this.fontRenderer.drawString("AdvProduct", 144, 70, 0xffffff);
        this.fontRenderer.drawString("Upgrade", 153, 90, 0xffffff);
        this.fontRenderer.drawString("Fuel", 164, 110, 0xffffff);
    }

    protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
    {
        int var4 = this.mc.renderEngine.getTexture("/speiger/src/tinychest/textures/ModuleMaker.png");
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.renderEngine.bindTexture(var4);
        int var5 = (this.width - this.xSize) / 2;
        int var6 = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize);
        int var7;
        


  
        if(tile.button[0] == 1)
        {
        	this.drawTexturedModalRect(32 + var5, 81 + var6 + 44, 222, 41, 35, 15);
       	}
       	if(tile.button[1] == 1)
       	{
       		this.drawTexturedModalRect(72 + var5, 81 + var6 + 44, 222, 41, 35, 15);
       	}
       	if(tile.button[2] == 1)
       	{
       		this.drawTexturedModalRect(112 + var5, 81 + var6 + 44, 222, 41, 35, 15);
        }
        
       	if(tile.progressButton[0] == 1)
       	{
       		this.drawTexturedModalRect(141 + var5, 6 + var6, 138, 234, 64, 15);
       	}
       	
       	if(tile.progressButton[1] == 1)
       	{
       		this.drawTexturedModalRect(141 + var5, 26 + var6, 138, 234, 64, 15);
       	}
        
       	if(tile.progressButton[2] == 1)
       	{
       		this.drawTexturedModalRect(141 + var5, 46 + var6, 138, 234, 64, 15);
       	}
       	
       	if(tile.progressButton[3] == 1)
       	{
       		this.drawTexturedModalRect(141 + var5, 66 + var6, 138, 234, 64, 15);
       	}
       	
       	if(tile.progressButton[4] == 1)
       	{
       		this.drawTexturedModalRect(141 + var5, 86 + var6, 138, 234, 64, 15);
       	}
       	
       	if(tile.progressButton[5] == 1)
       	{
       		this.drawTexturedModalRect(141 + var5, 106 + var6, 138, 234, 64, 15);
       	}
       	
       	
       	
       	
       	
        
    }

    
    public int getButtonprosition(int x, int y) 
    {
    	if(x>=33 && x<=64 && y>=125 && y<=139)return 1;
    	else if(x>=73 && x<=104 && y>=125 && y<=139)return 2;
    	else if(x>=113 && x<=144 && y>=125 && y<=139)return 3;
    	
    	else if(x>=141 && x<=204 && y>=6 && y<=20)return 4;
    	else if(x>=141 && x<=204 && y>=26 && y<=40)return 5;
    	else if(x>=141 && x<=204 && y>=46 && y<=60)return 6;
//    	else if(x>=141 && x<=204 && y>=66 && y<=80)return 7;
//    	else if(x>=141 && x<=204 && y>=86 && y<=100)return 8;
//    	else if(x>=141 && x<=204 && y>=106 && y<=120)return 9;
    	else return 0;
    }
    

    


@Override
protected void mouseClicked(int par1, int par2, int par3) 
{
	super.mouseClicked(par1, par2, par3);


	int cornerX = (width - xSize) / 2;
	int cornerY = (height - ySize) / 2;
	int prosition = getButtonprosition(par1 - cornerX, par2 - cornerY);
	if(prosition != 0)
	{
		tile.progress = 0;
		if(prosition == 1)
		{
			tile.button[0] = 1;
			tile.button[1] = 0;
			tile.button[2] = 0;
		}
		if(prosition == 2)
		{
			tile.button[0] = 0;
			tile.button[1] = 1;
			tile.button[2] = 0;
		}
		if(prosition == 3)
		{
			tile.button[0] = 0;
			tile.button[1] = 0;
			tile.button[2] = 1;
		}

		if(prosition == 4)
		{
			tile.progressButton[0] = 1;
			tile.progressButton[1] = 0;
			tile.progressButton[2] = 0;
			tile.progressButton[3] = 0;
			tile.progressButton[4] = 0;
			tile.progressButton[5] = 0;
		}
		if(prosition == 5)
		{
			tile.progressButton[0] = 0;
			tile.progressButton[1] = 1;
			tile.progressButton[2] = 0;
			tile.progressButton[3] = 0;
			tile.progressButton[4] = 0;
			tile.progressButton[5] = 0;
		}
		if(prosition == 6)
		{
			tile.progressButton[0] = 0;
			tile.progressButton[1] = 0;
			tile.progressButton[2] = 1;
			tile.progressButton[3] = 0;
			tile.progressButton[4] = 0;
			tile.progressButton[5] = 0;
		}
		if(prosition == 7)
		{
			tile.progressButton[0] = 0;
			tile.progressButton[1] = 0;
			tile.progressButton[2] = 0;
			tile.progressButton[3] = 1;
			tile.progressButton[4] = 0;
			tile.progressButton[5] = 0;
		}
		if(prosition == 
		{
			tile.progressButton[0] = 0;
			tile.progressButton[1] = 0;
			tile.progressButton[2] = 0;
			tile.progressButton[3] = 0;
			tile.progressButton[4] = 1;
			tile.progressButton[5] = 0;
		}

		if(prosition == 9)
		{
			tile.progressButton[0] = 0;
			tile.progressButton[1] = 0;
			tile.progressButton[2] = 0;
			tile.progressButton[3] = 0;
			tile.progressButton[4] = 0;
			tile.progressButton[5] = 1;
		}
	}
}

}

 

ContainerModuleMaker:

package speiger.src.tinychest.common.container.machines.machine;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import speiger.src.tinychest.common.tileentity.machines.machine.ModuleMaker;

public class ContainerModulMaker extends Container 
{

public ContainerModulMaker(InventoryPlayer par1, ModuleMaker par2) 
{
	this.addSlotToContainer(new Slot(par2, 0, 79, 21));//Circuit Slot
	this.addSlotToContainer(new Slot(par2, 1, 79, 54)); //Modul Input
	this.addSlotToContainer(new Slot(par2, 2, 112, 54)); //OutputSlot
	this.addSlotToContainer(new Slot(par2, 3, 36, 10)); //Input Slot 1
	this.addSlotToContainer(new Slot(par2, 4, 36, 32)); //Input Slot 2
	this.addSlotToContainer(new Slot(par2, 5, 36, 54)); //Input Slot 3
	this.addSlotToContainer(new Slot(par2, 6, 36, 76)); //Input Slot 4
	this.addSlotToContainer(new Slot(par2, 7, 36, 98)); //Input Slot 5


        int var3;

        for (var3 = 0; var3 < 3; ++var3)
        {
            for (int var4 = 0; var4 < 9; ++var4)
            {
                this.addSlotToContainer(new Slot(par1, var4 + var3 * 9 + 9, 9 + var4 * 18, 151 + var3 * 18));
            }
        }

        for (var3 = 0; var3 < 9; ++var3)
        {
            this.addSlotToContainer(new Slot(par1, var3, 9 + var3 * 18, 209));
        }
}

@Override
public boolean canInteractWith(EntityPlayer var1)
{
	return true;
}

@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) 
{
	return null;
}



}

 

TileEntity ModuleMaker

package speiger.src.tinychest.common.tileentity.machines.machine;

import cpw.mods.fml.common.FMLLog;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.liquids.LiquidStack;
import speiger.src.api.api.ICable;
import speiger.src.api.api.IMachine;
import speiger.src.api.api.modules.advanced.ModulMakerRecipeRegister;
import speiger.src.api.common.functions.WorldReading;
import speiger.src.api.common.tile.TileFacing;
import speiger.src.tinychest.common.config.TinyItems;
import speiger.src.tinychest.common.items.module.ItemEmptyModul;
import speiger.src.tinychest.common.items.module.ModulCore;

public class ModuleMaker extends TileFacing implements IInventory, IMachine
{
public int[] button = new int[3];
public int[] progressButton = new int[6];
public ItemStack[] modulStack = new ItemStack[8];
public int progress = 0;
public int maxProgress = 7200;
public int mode = 0;
public int progressmode = 0;
public int energy = 0;
public int maxEnergy = 100000;

private void updateButtons() 
{
	if(button[0] > 0)
	{
		mode = 1;
	}
	if(button[1] > 0)
	{
		mode = 2;
	}
	if(button[2] > 0)
	{
		mode = 3;
	}

	if(progressButton[0] > 0)
	{
		progressmode = 1;
	}
	if(progressButton[1] > 0)
	{
		progressmode = 2;
	}
	if(progressButton[2] > 0)
	{
		progressmode = 3;
	}
	if(progressButton[3] > 0)
	{
		progressmode = 4;
	}
	if(progressButton[4] > 0)
	{
		progressmode = 5;
	}
	if(progressButton[5] > 0)
	{
		progressmode = 6;
	}

}

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

    public ItemStack getStackInSlot(int par1)
    {
        return this.modulStack[par1];
    }

    public ItemStack decrStackSize(int par1, int par2)
    {
        if (this.modulStack[par1] != null)
        {
            ItemStack var3;

            if (this.modulStack[par1].stackSize <= par2)
            {
                var3 = this.modulStack[par1];
                this.modulStack[par1] = null;
                return var3;
            }
            else
            {
                var3 = this.modulStack[par1].splitStack(par2);

                if (this.modulStack[par1].stackSize == 0)
                {
                    this.modulStack[par1] = null;
                }

                return var3;
            }
        }
        else
        {
            return null;
        }
    }
   
    public ItemStack getStackInSlotOnClosing(int par1)
    {
        if (this.modulStack[par1] != null)
        {
            ItemStack var2 = this.modulStack[par1];
            this.modulStack[par1] = null;
            return var2;
        }
        else
        {
            return null;
        }
    }

    public void setInventorySlotContents(int par1, ItemStack par2ItemStack)
    {
        this.modulStack[par1] = par2ItemStack;

        if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
        {
            par2ItemStack.stackSize = this.getInventoryStackLimit();
        }
    }

    public String getInvName()
    {
        return "Module Maker";
    }

public int getInventoryStackLimit() 
{
	return 1;
}

public boolean isUseableByPlayer(EntityPlayer var1) 
{
	return true;
}

public void openChest() 
{
}

@Override
public void closeChest() 
{
}

@Override
public void updateEntity() 
{
	super.updateEntity();
	if(!worldObj.isRemote || worldObj.getWorldTime() % 10 == 0)return;

	updateButtons();
	updateCable();
	ItemStack par1 = new ItemStack(Item.diamond);
	if(modulStack[0] != null && canProgress())
	{
		modulStack[2] = par1.copy();
		modulStack[0] = null;


	}
}



public boolean canProgress() 
{
        if (this.modulStack[0] == null)
        {
            return false;
        }
        else
        {
            ItemStack var1 = new ItemStack(Item.diamond);
            if (this.modulStack[2] == null) return true;
            if (!this.modulStack[2].isItemEqual(var1)) return false;
            int result = modulStack[2].stackSize + var1.stackSize;
            return (result <= getInventoryStackLimit() && result <= var1.getMaxStackSize());
        }
}

public int getProgressFromMode() 
{
	if(mode == 1)return maxProgress / 2;
	else if(mode == 2)return maxProgress;
	else return maxProgress*2;
}

public void updateCable()
{
	for(int i = 0;i<6;i++)
	{
		TileEntity tile = WorldReading.getTileEntity(worldObj, xCoord, yCoord, zCoord, i);
		if(tile != null && tile instanceof ICable)
		{
			ICable ic = (ICable) tile;
			ic.setPriorty(0);
		}
	}
}

@Override
public boolean needEnergie() 
{
	return energy < maxEnergy;
}

@Override
public int getMaxStoredEnergy() 
{
	return maxEnergy;
}

@Override
public int getStoredEnergy() 
{
	return energy;
}

@Override
public void sendEnergyToMachine(int i) 
{
	energy += i;
}

@Override
public int getTransferlimit() 
{
	return 128;
}

@Override
public int getEnergyOutOfMachine(int i)
{
	return 0;
}

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

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

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

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

@Override
public LiquidStack getLiquidID() 
{
	return null;
}

@Override
public int getStoredLiquid() 
{
	return 0;
}

@Override
public int getMaxLiquidLevel() 
{
	return 0;
}

@Override
public void setLiquidID(LiquidStack par1) 
{
}

@Override
public void sendLiquid(int i)
{
}

@Override
public int suckLiquidOutOfMachine(int i) 
{
	return 0;
}





}

 

so my problem is that he creates ghost items.

I know from where the problem comes but i do not know how to fix it.

The problem activate every time when i asking is this button pressed or is it not (in form of the variable mode, progressmode, work) if i implement these variables he start to create Ghost items. so how can i fix it?

Posted

From the Gui, send a packet to server when mouseClicked() is called, with enough data to change the tileentity state on the server side.

I would recommend using

this.mc.getNetHandler().addToSendQueue(packet);

With packet being constructed with your "prosition" data.

 

Then in a class implementing IPacketHandler, read the data and change the tileentity state.

You'll need to register channel and packet handling class in your @NetworkMod annotation.

Posted

Cool but 1 little problem i do not know anything about packet handling!

And my coding knowledge go with this over everything i know. Short i reach my limit^^ At the moment!

Posted

Without a tutorial i am lost xD (on this way)

Can you explain me how i can do this?

xD i know there is a tutorial on forge. But i do not understand it^^. It does confuse me.

Posted

Well, this is going to be long.

Let's start from the beginning, shall we ?

 

For the server to know what the client is doing, (and vice-versa) information needs to be sent. You need to remember that client part is distinct from server part, because they can be, like, 1000 kilometres apart.

On your case, you have a client input (a click). You need to send this info to the server.

But rough info can't travel through the internet (which is the commonly used communicating system), as it would be slow and insecure.

You send packets containing the info.

How it is done:

You (as client here) write info into a DataOutputStream in a sequence (of Byte arrays), then put it into a new Packet.

You send the packet. (from your client, to the server, in your case)

*packet travels safely through the internet*

You receive the packet in your (server here) packet handler class. (IPacketHandler is our common backbone for receiving packets, so you get a call by onPacketData)

You (as server here) read info with a DataInputStream, in same sequence as it was written.

You (as server here) do the changes the data tells.

 

Do you understand till here ?

[You don't really need to understand what DataOutputStream and DataInputStream are doing to the packet, though you need to use them]

Posted

Ok. I did read your text and i can see the differens between datainput/outputstream^^

Now a very important thing. I am still on 1.4.7 so do not forget that.

And i tried to implement a packethandler (i do not know if its working but the code is there)

But now is the problem how do i sync the Infos between my gui and my tile. Because the SyncTileEntities tutorial on forge is like: yeah you do need to sync sometimes manually but a specail explaining is not there.

 

Sry for saying it like that but i always say what i think! ^^

Posted

i actually made that tutorial btw, and its intended for people who have experience with java,but if you need help i will explain in more details if you want

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

you might want to take a look at http://www.minecraftforge.net/wiki/Organising_packet_handlers, another tutorial i made

 

basicly make a class that implements IPacketHandling

 

register that class using

NetworkRegistry.instance().registerChannel(new ServerPacketHandler(), "channelName", Side.SERVER);

or for client:

NetworkRegistry.instance().registerChannel(new ClientPacketHandler(), "channelName", Side.CLIENT);

 

also, GotoLink said use this.mc.getNetHandler().addToSendQueue(packet);

its not bad, but i recommend PacketDispatcher.sendPacketToServer(packet);

its the same, except if you ever send a packet from somewhere else then a gui you wont have access to a Minecraft reference

and using PacketDispatcher server side has some convinient methods

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

Yeah that would maybe work but i do not get Anything done with it.

I tried to register a packetHandler and if i trie that then the game crashes and the game says Invalid Channel name. My Channel name is: "TinyModularThings"

 

Here are the classes^^.

 

xD if the forge forum would not block my PrimäryBrowserIP then i could read the answers better xD but that is not interessting now!

Posted

have you researched into WHY thsi channel name is invalid ? anythign in the log ? try changing the channel name?

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

Classes:

 

ModClass:

package speiger.src.tinychest;

import java.io.File;
import java.util.logging.Logger;

import net.minecraft.creativetab.CreativeTabs;
import speiger.src.api.api.modules.advanced.ModulRecipeRegister;
import speiger.src.tinychest.addons.AddonHelper;
import speiger.src.tinychest.common.config.TinyConfig;
import speiger.src.tinychest.common.config.TinyTileRegistry;
import speiger.src.tinychest.common.core.CreativeTapTinyChest;
import speiger.src.tinychest.common.core.TinyChestCore;
import speiger.src.tinychest.common.core.helpers.RecipeHelper;
import speiger.src.tinychest.common.lib.TinyChestRecipes;
import speiger.src.tinychest.common.lib.TinyChestReference;
import speiger.src.tinychest.common.packet.SpmodPackets;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
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.network.NetworkRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;


@Mod(modid = TinyChestReference.TinyID, name = TinyChestReference.TinyName, version = TinyChestReference.TinyVersion, dependencies = "required-after:SpmodAPI")
@NetworkMod(clientSideRequired = true, serverSideRequired = false, channels = "TinyModularThings", packetHandler = SpmodPackets.class)
public class TinyChest 
{
@SidedProxy(clientSide = TinyChestReference.TinyClient, serverSide = TinyChestReference.TinyCore)
public static TinyChestCore core;

@Instance(TinyChestReference.TinyID)
public static TinyChest instance;

public static Logger tinyLogger = Logger.getLogger("TinyChestReference.TinyName");

public static CreativeTabs tinyChest = new CreativeTapTinyChest(CreativeTabs.getNextID(), TinyChestReference.TinyID);


@PreInit
    public void preInit(FMLPreInitializationEvent par1)
{

	NetworkRegistry.instance().registerGuiHandler(this, core);
	NetworkRegistry.instance().registerChannel(new SpmodPackets(), "TinyModularThings");
	instance = this;

	TinyConfig.loadTinyChests(new File(par1.getModConfigurationDirectory(), "Spmod/TinyChest.cfg"));
	LanguageRegistry.instance().addStringLocalization("itemGroup."+TinyChestReference.TinyID, "Tiny Chest");
    }



@Init
public void load(FMLInitializationEvent evt)
{

	ModulRecipeRegister.RegisterModulReicpeOutput(new RecipeHelper());
	TinyChestRecipes.loadTinyChests();
	TinyTileRegistry.registerTiles();
	core.registerTileRenders();
	core.preloadTexture();
}


@PostInit
public void modsLoaded(FMLPostInitializationEvent evt) 
{
	AddonHelper.loadAddons();
}

}

 

PacketClass:

package speiger.src.tinychest.common.packet;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;

import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;

public class SpmodPackets implements IPacketHandler {

@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) 
{

}



}

Posted

ps: can i take this example of "trying a new string" and put it into my debugging 101 guide ?

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

Ok i changed my String to TinyChest (Which was my Old ModName)

xD

 

Now the thing is how can i use the packethandler to send the information to the TileEntity?

 

And yes you can^^

Posted

well basicly this is the flow of information

lets say i have a block that you can right click to open a gui, and in thsi gui there are buttons to change the values of the block (colors, meta, wtv you can think of)

 

what i want to do is in my gui, when a certain button is pressed (a button labeled "update" or wtv)

send a packet to the server containing every important information, in your case just send a integer that represent what action has been taken (btw i havnt actually read your post, just the few last one where GotoLink says:

On your case, you have a client input (a click). You need to send this info to the server.

so anyway, just feed the integer (or you could also send NOTHING if that teh only kind of packet that is send with thsi channel + the x, y, z coord of the TE (so that server side knows wtf you're talking about, but usually you want to send many different thigns with 1 channel)

on server side when you receive this packet

get the 3 coordinates, get a world ref, get that tile entity using the world ref  and apply the changes you want to the tile entity

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

I have tinkers construct installed (source) and because we have a nearly simmilar way of creating items i watched what he did^^.

 

So now i did a view changes. I Did not test really if it is write. But it does crash nothing!

 

Modfile

package speiger.src.tinychest;

import java.io.File;
import java.util.logging.Logger;

import net.minecraft.creativetab.CreativeTabs;
import speiger.src.api.api.modules.advanced.ModulRecipeRegister;
import speiger.src.tinychest.addons.AddonHelper;
import speiger.src.tinychest.common.config.TinyConfig;
import speiger.src.tinychest.common.config.TinyTileRegistry;
import speiger.src.tinychest.common.core.CreativeTapTinyChest;
import speiger.src.tinychest.common.core.TinyChestCore;
import speiger.src.tinychest.common.core.helpers.RecipeHelper;
import speiger.src.tinychest.common.lib.TinyChestRecipes;
import speiger.src.tinychest.common.lib.TinyChestReference;
import speiger.src.tinychest.common.packet.SpmodPackets;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PostInit;
import cpw.mods.fml.common.Mod.PreInit;
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.network.NetworkRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;


@Mod(modid = TinyChestReference.TinyID, name = TinyChestReference.TinyName, version = TinyChestReference.TinyVersion, dependencies = "required-after:SpmodAPI")
@NetworkMod(clientSideRequired = true, serverSideRequired = false, channels = "TinyChest", packetHandler = SpmodPackets.class)
public class TinyChest 
{
@SidedProxy(clientSide = TinyChestReference.TinyClient, serverSide = TinyChestReference.TinyCore)
public static TinyChestCore core;

@Instance(TinyChestReference.TinyID)
public static TinyChest instance;

public static Logger tinyLogger = Logger.getLogger("TinyChestReference.TinyName");

public static CreativeTabs tinyChest = new CreativeTapTinyChest(CreativeTabs.getNextID(), TinyChestReference.TinyID);


@PreInit
    public void preInit(FMLPreInitializationEvent par1)
{

	NetworkRegistry.instance().registerGuiHandler(this, core);
	NetworkRegistry.instance().registerChannel(new SpmodPackets(), "TinyChest", Side.SERVER);
	instance = this;

	TinyConfig.loadTinyChests(new File(par1.getModConfigurationDirectory(), "Spmod/TinyChest.cfg"));
	LanguageRegistry.instance().addStringLocalization("itemGroup."+TinyChestReference.TinyID, "Tiny Chest");
    }



@Init
public void load(FMLInitializationEvent evt)
{

	ModulRecipeRegister.RegisterModulReicpeOutput(new RecipeHelper());
	TinyChestRecipes.loadTinyChests();
	TinyTileRegistry.registerTiles();
	core.registerTileRenders();
	core.preloadTexture();
}


@PostInit
public void modsLoaded(FMLPostInitializationEvent evt) 
{
	AddonHelper.loadAddons();
}

}

 

Gui

package speiger.src.tinychest.client.gui.machines.machine;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.util.StatCollector;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.network.PacketDispatcher;

import speiger.src.tinychest.common.container.machines.machine.ContainerModuleMaker;
import speiger.src.tinychest.common.tileentity.machines.machine.ModuleMaker;

public class GuiModuleMaker extends GuiContainer 
{
private ModuleMaker tile;

public GuiModuleMaker(InventoryPlayer par1, ModuleMaker par2) 
{
	super(new ContainerModuleMaker(par1, par2));
	tile = par2;
	this.ySize = 232;
	this.xSize = 211;
}

protected void drawGuiContainerForegroundLayer(int par1, int par2)
    {
	this.fontRenderer.drawString("Fast", 38, 128, 0xffffff);
	this.fontRenderer.drawString("Work", 78, 106, 0xffffff);
	this.fontRenderer.drawString("Med", 80, 128, 0xffffff);
	this.fontRenderer.drawString("Slow", 118, 128, 0xffffff);
        this.fontRenderer.drawString("Module Maker", 65, 6, 4210752);
        this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 5, 4210752);
        this.fontRenderer.drawString("Clearing", 153, 10, 0xffffff);
        this.fontRenderer.drawString("Specify", 155, 30, 0xffffff);
        this.fontRenderer.drawString("Production", 146, 50, 0xffffff);
        this.fontRenderer.drawString("AdvProduct", 144, 70, 0xffffff);
        this.fontRenderer.drawString("Upgrade", 153, 90, 0xffffff);
        this.fontRenderer.drawString("Fuel", 164, 110, 0xffffff);
    }

    protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
    {
        int var4 = this.mc.renderEngine.getTexture("/speiger/src/tinychest/textures/ModuleMaker.png");
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.renderEngine.bindTexture(var4);
        int var5 = (this.width - this.xSize) / 2;
        int var6 = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize);
        int var7;
        
       	if(tile.CanWork())
       	{
       		this.drawTexturedModalRect(72 + var5, 81 + var6 + 22, 222, 24, 35, 15);
       	}
       	
       	if(tile.work == 1)
       	{
       		this.drawTexturedModalRect(72 + var5, 81 + var6 + 22, 222, 41, 35, 15);
       	}

  
        if(tile.button[0] == 1)
        {
        	this.drawTexturedModalRect(32 + var5, 81 + var6 + 44, 222, 41, 35, 15);
       	}
       	if(tile.button[1] == 1)
       	{
       		this.drawTexturedModalRect(72 + var5, 81 + var6 + 44, 222, 41, 35, 15);
       	}
       	if(tile.button[2] == 1)
       	{
       		this.drawTexturedModalRect(112 + var5, 81 + var6 + 44, 222, 41, 35, 15);
        }
        
       	if(tile.progressButton[0] == 1)
       	{
       		this.drawTexturedModalRect(141 + var5, 6 + var6, 138, 234, 64, 15);
       	}
       	
       	if(tile.progressButton[1] == 1)
       	{
       		this.drawTexturedModalRect(141 + var5, 26 + var6, 138, 234, 64, 15);
       	}
        
       	if(tile.progressButton[2] == 1)
       	{
       		this.drawTexturedModalRect(141 + var5, 46 + var6, 138, 234, 64, 15);
       	}
       	
       	if(tile.progressButton[3] == 1)
       	{
       		this.drawTexturedModalRect(141 + var5, 66 + var6, 138, 234, 64, 15);
       	}
       	
       	if(tile.progressButton[4] == 1)
       	{
       		this.drawTexturedModalRect(141 + var5, 86 + var6, 138, 234, 64, 15);
       	}
       	
       	if(tile.progressButton[5] == 1)
       	{
       		this.drawTexturedModalRect(141 + var5, 106 + var6, 138, 234, 64, 15);
       	}
       	
       	
       	
       	
       	
        
    }

    
    public int getButtonprosition(int x, int y) 
    {
    	if(x>=33 && x<=64 && y>=125 && y<=139)return 1;
    	else if(x>=73 && x<=104 && y>=125 && y<=139)return 2;
    	else if(x>=113 && x<=144 && y>=125 && y<=139)return 3;
    	
    	else if(x>=141 && x<=204 && y>=6 && y<=20)return 4;
    	else if(x>=141 && x<=204 && y>=26 && y<=40)return 5;
    	else if(x>=141 && x<=204 && y>=46 && y<=60)return 6;
//    	else if(x>=141 && x<=204 && y>=66 && y<=80)return 7;
//    	else if(x>=141 && x<=204 && y>=86 && y<=100)return 8;
//    	else if(x>=141 && x<=204 && y>=106 && y<=120)return 9;
    	else if(x>=73 && x<=104 && y>=103 && y<=117)return 10;
    	else return 0;
    }
    

    


@Override
protected void mouseClicked(int par1, int par2, int par3) 
{
	super.mouseClicked(par1, par2, par3);



	int cornerX = (width - xSize) / 2;
	int cornerY = (height - ySize) / 2;

	int prosition = getButtonprosition(par1 - cornerX, par2 - cornerY);

	if(prosition != 0)
	{
		tile.progress = 0;
		tile.canWork = false;
		tile.work = 0;
		this.sendPacket(prosition);
		if(prosition == 1)
		{
			tile.button[0] = 1;
			tile.button[1] = 0;
			tile.button[2] = 0;
		}
		if(prosition == 2)
		{
			tile.button[0] = 0;
			tile.button[1] = 1;
			tile.button[2] = 0;
		}
		if(prosition == 3)
		{
			tile.button[0] = 0;
			tile.button[1] = 0;
			tile.button[2] = 1;
		}

		if(prosition == 4)
		{
			tile.progressButton[0] = 1;
			tile.progressButton[1] = 0;
			tile.progressButton[2] = 0;
			tile.progressButton[3] = 0;
			tile.progressButton[4] = 0;
			tile.progressButton[5] = 0;
		}
		if(prosition == 5)
		{
			tile.progressButton[0] = 0;
			tile.progressButton[1] = 1;
			tile.progressButton[2] = 0;
			tile.progressButton[3] = 0;
			tile.progressButton[4] = 0;
			tile.progressButton[5] = 0;
		}
		if(prosition == 6)
		{
			tile.progressButton[0] = 0;
			tile.progressButton[1] = 0;
			tile.progressButton[2] = 1;
			tile.progressButton[3] = 0;
			tile.progressButton[4] = 0;
			tile.progressButton[5] = 0;
		}
		if(prosition == 7)
		{
			tile.progressButton[0] = 0;
			tile.progressButton[1] = 0;
			tile.progressButton[2] = 0;
			tile.progressButton[3] = 1;
			tile.progressButton[4] = 0;
			tile.progressButton[5] = 0;
		}
		if(prosition == 
		{
			tile.progressButton[0] = 0;
			tile.progressButton[1] = 0;
			tile.progressButton[2] = 0;
			tile.progressButton[3] = 0;
			tile.progressButton[4] = 1;
			tile.progressButton[5] = 0;
		}

		if(prosition == 9)
		{
			tile.progressButton[0] = 0;
			tile.progressButton[1] = 0;
			tile.progressButton[2] = 0;
			tile.progressButton[3] = 0;
			tile.progressButton[4] = 0;
			tile.progressButton[5] = 1;
		}

		if(prosition == 10)
		{
			if(tile.work == 0 && tile.canWork)
			{
				tile.work = 1;
			}
			else
			{
				if(tile.work == 1)
				{
					tile.work = 0;
				}
			}
		}
	}
}

public void sendPacket(int prosition) 
{
	ByteArrayOutputStream bitout = new ByteArrayOutputStream(;
	DataOutputStream output = new DataOutputStream(bitout);

	try 
	{
		output.writeByte(1);
		output.writeInt(tile.worldObj.provider.dimensionId);
		output.writeInt(tile.xCoord);
		output.writeInt(tile.yCoord);
		output.writeInt(tile.zCoord);
		output.writeInt(prosition);
		FMLLog.getLogger().info("Send Data");
	}
	catch (Exception e) 
	{
		FMLLog.getLogger().info("Send Data");
		e.printStackTrace();
	}

	Packet250CustomPayload packet = new Packet250CustomPayload();
	packet.channel = "TinyChests";
	packet.data = bitout.toByteArray();
	packet.length = bitout.size();
	PacketDispatcher.sendPacketToServer(packet);
}

}

 

PacketHandler

package speiger.src.tinychest.common.packet;

import java.io.ByteArrayInputStream;
import java.io.DataInputStream;

import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
import speiger.src.tinychest.common.tileentity.machines.machine.ModuleMaker;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;

public class SpmodPackets implements IPacketHandler {

@Override
public void onPacketData(INetworkManager manager, Packet250CustomPayload packet, Player player) 
{
	if(packet.channel.equals("TinyChest"))
	{
		handlePacket(packet);
	}
}

void handlePacket(Packet250CustomPayload packet) 
{
	DataInputStream input = new DataInputStream(new ByteArrayInputStream(packet.data));
	byte packetID;
	int dimID;
	try 
	{
		FMLLog.getLogger().info("Test");
		packetID = input.readByte();
		dimID = input.readInt();

		World world = DimensionManager.getWorld(dimID);

		if(packetID == 1)//ModuleMaker
		{
			FMLLog.getLogger().info("Test2");
			int x = input.readInt();
			int y = input.readInt();
			int z = input.readInt();
			int prosition = input.readInt();
			TileEntity tile = world.getBlockTileEntity(x, y, z);
			if(tile != null && tile instanceof ModuleMaker)
			{
				ModuleMaker mod = (ModuleMaker) tile;
				mod.runTest();
			}
		}


	}
	catch (Exception e) 
	{
		System.out.println("[TinyChest] Error on Sending Packet");
		e.printStackTrace();
		return;
	}
}



}

 

It does crash nothing and something does he do but what he do i do not know^^

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.