Jump to content

Problems between server-client, client-server talk[unsolved but i don't care]


Recommended Posts

Posted

Yeah same problem as before but now with that i do not click on the block i just put a item in like a furnace here 2 pics that explains more then 1000 words.

 

 

Exp in a bottle (51000 Exp):

 

https://www.dropbox.com/s/p05ftkf8waoee0g/No%20Exp%20in%20the%20storage.bmp

 

Exp now in my Storage (51000 Exp):

 

https://www.dropbox.com/s/d9mwxpi59up5nrs/Exp%20in%20the%20storage.bmp

 

 

here my full code of the Exp Bottles:

 

package speiger.src.api.common.items;

import java.util.List;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import speiger.src.api.SpmodAPI;
import speiger.src.api.api.IExpBottle;
import speiger.src.api.common.lib.APITextures;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ItemEXPBottles extends ItemSpmod implements IExpBottle
{

private int transferlimit;
private int texture;
private String name;
private int storedExp;

public ItemEXPBottles(int par1, int storedEXP, int transportlimit, int itemTexture, String itemname, boolean beta) 
{
	super(par1, beta);
	this.setNoRepair();
	setMaxDamage(4);
	storedExp = storedEXP;
	setMaxStackSize(1);
	transferlimit = transportlimit;
	texture = itemTexture;
	name = itemname;
	setCreativeTab(SpmodAPI.spmodAPI);
}

    @Override
    public String getTextureFile()
    {
    	return APITextures.apiTexturePath;
    }

public int getIconFromDamage(int par1)
{
	return texture;
}

@Override
public void charge(int i, ItemStack par1)
{
	NBTTagCompound par2 = par1.getTagCompound().getCompoundTag("ExpBottle");
	int b = par2.getInteger("StoredExp");
	par2.setInteger("StoredExp", b+i);
	int d = b+i;
	if(d > 0)
	{
		if(d > (storedExp / 4))
		{
			if(d > (storedExp / 2))
			{
				if(d > ((storedExp / 4) * 3))
				{
					if(d >= storedExp)
					{
						par1.setItemDamage(0);
					}
					else
					{
						par1.setItemDamage(1);
					}
				}
				else
				{
					par1.setItemDamage(2);
				}
			}
			else
			{
				par1.setItemDamage(3);
			}
		}
		else
		{
			par1.setItemDamage(4);
		}
	}
}

@Override
public void discharge(int i, ItemStack par1)
{
	NBTTagCompound par2 = par1.getTagCompound().getCompoundTag("ExpBottle");
	int d = par2.getInteger("StoredExp");
	par2.setInteger("StoredExp", d-i);
	int b = d-i;
	if(b > 0)
	{
		if(b > (storedExp / 4))
		{
			if(b > (storedExp / 2))
			{
				if(b > ((storedExp / 4) * 3))
				{
					if(b >= storedExp)
					{
						par1.setItemDamage(0);
					}
					else
					{
						par1.setItemDamage(1);
					}
				}
				else
				{
					par1.setItemDamage(2);
				}
			}
			else
			{
				par1.setItemDamage(3);
			}
		}
		else
		{
			par1.setItemDamage(4);
		}
	}
}

@Override
public int getTransferlimit(ItemStack par1)
{
	return this.transferlimit;
}

@Override
public int getMaxCharge(ItemStack par1)
{
	return this.storedExp;
}

@Override
public int getStoredExp(ItemStack par1)
{
	NBTTagCompound par2 = par1.getTagCompound().getCompoundTag("ExpBottle");
	return par2.getInteger("StoredExp");
}

@Override
public boolean hasExp(ItemStack par1)
{
	NBTTagCompound par2 = par1.getTagCompound().getCompoundTag("ExpBottle");
	if(par2.getInteger("StoredExp") > 0)
	{
		return true;
	}
	return false;
}

@Override
public boolean needsExp(ItemStack par1)
{
	NBTTagCompound par2 = par1.getTagCompound().getCompoundTag("ExpBottle");
	if(par2.getInteger("StoredExp")< this.storedExp)
	{
		return true;
	}

	return false;
}

@Override
@SideOnly(Side.CLIENT)
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3)
{
	NBTTagCompound nbtEmpty = new NBTTagCompound();
	nbtEmpty.setCompoundTag("ExpBottle", new NBTTagCompound());
	nbtEmpty.getCompoundTag("ExpBottle").setInteger("StoredExp", 0);
	ItemStack empty = new ItemStack(par1, 1, 4);
	empty.setTagCompound(nbtEmpty);
	par3.add(empty);

	NBTTagCompound nbtFull = new NBTTagCompound();
	nbtFull.setCompoundTag("ExpBottle", new NBTTagCompound());
	nbtFull.getCompoundTag("ExpBottle").setInteger("StoredExp", this.storedExp);
	ItemStack full = new ItemStack(par1, 1, 0);
	full.setTagCompound(nbtFull);
	par3.add(full);
}

@Override
public String getItemDisplayName(ItemStack par1ItemStack)
{
	return this.name;
}

@Override
@SideOnly(Side.CLIENT)
public boolean hasEffect(ItemStack par1ItemStack)
{
	return this.hasExp(par1ItemStack);
}

@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack par1, EntityPlayer par2, List par3, boolean par4)
{
	if(par1.hasTagCompound())
	{
		if(par1.getTagCompound().getCompoundTag("ExpBottle")!= null)
		{
			par3.add("Stored EXP: "+par1.getTagCompound().getCompoundTag("ExpBottle").getInteger("StoredExp"));
		}
	}
	par3.add("Can Store: "+this.storedExp+" EXP");

	this.getInformation(par1, par2, par3, par4);
}






}

 

Container of the Basic Exp Storage:

 


package speiger.src.api.common.container;

import java.util.Iterator;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import speiger.src.api.api.IExpBottle;
import speiger.src.api.common.tile.BasicExpBench;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ContainerBasicExpBench extends Container {

private int expnow = 0;
private BasicExpBench tile;

public ContainerBasicExpBench(InventoryPlayer par1, BasicExpBench par2) 
{
	addSlotToContainer(new Slot(par2, 0, 43, 35)); //Import Slot
	addSlotToContainer(new Slot(par2, 1, 116, 35)); //Output Slot
	tile = par2;
        int var3;

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

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

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

@Override
    public void detectAndSendChanges()
    {
        super.detectAndSendChanges();

        for (int var1 = 0; var1 < this.crafters.size(); ++var1)
        {
            ICrafting var2 = (ICrafting)this.crafters.get(var1);

            if (this.expnow != this.tile.exp)
            {
                var2.sendProgressBarUpdate(this, 0, this.tile.exp);
            }
        }
        expnow = tile.exp;
    }

    @SideOnly(Side.CLIENT)
    public void updateProgressBar(int par1, int par2)
    {
        if (par1 == 0)
        {
            this.tile.exp = par2;
        }
    }
    
    public void addCraftingToCrafters(ICrafting par1ICrafting)
    {
        super.addCraftingToCrafters(par1ICrafting);
        par1ICrafting.sendProgressBarUpdate(this, 0, tile.exp);
    }

    public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    {
        ItemStack var3 = null;
        Slot var4 = (Slot)this.inventorySlots.get(par2);

        if (var4 != null && var4.getHasStack())
        {
            ItemStack var5 = var4.getStack();
            var3 = var5.copy();

            if (par2 != 1 && par2 != 0)
            {
                if (var5.getItem() instanceof IExpBottle)
                {
                    if (!this.mergeItemStack(var5, 0, 1, false))
                    {
                        return null;
                    }
                }
                else if (var5.getItem() instanceof IExpBottle)
                {
                    if (!this.mergeItemStack(var5, 1, 2, false))
                    {
                        return null;
                    }
                }
                else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(var5, 3, 30, false))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(var5, 3, 39, false))
            {
                return null;
            }

            if (var5.stackSize == 0)
            {
                var4.putStack((ItemStack)null);
            }
            else
            {
                var4.onSlotChanged();
            }

            if (var5.stackSize == var3.stackSize)
            {
                return null;
            }

            var4.onPickupFromSlot(par1EntityPlayer, var5);
        }

        return var3;
    }
}


 

Code of the gui Basic Exp Storage:

 


package speiger.src.api.client.gui;

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

import org.lwjgl.opengl.GL11;

import speiger.src.api.common.container.ContainerBasicExpBench;
import speiger.src.api.common.tile.BasicExpBench;

public class GuiBasicExpBench extends GuiContainer {

private BasicExpBench bench;

public GuiBasicExpBench(InventoryPlayer par1, BasicExpBench par2) 
{
	super(new ContainerBasicExpBench(par1, par2));
	bench = par2;
}

    protected void drawGuiContainerForegroundLayer(int par1, int par2)
    {
    	this.fontRenderer.drawString("Stored Exp: " + bench.gettingEXP(), 60, 20, 4210752);
        this.fontRenderer.drawString("Basic Exp Storage", 50, 4, 4210752);
        this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
    }

    /**
     * Draw the background layer for the GuiContainer (everything behind the items)
     */
    protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
    {
        int var4 = this.mc.renderEngine.getTexture("/speiger/src/api/textures/gui/basicEXPBench.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);
    }

}


 

 

and now the TileEntity:

package speiger.src.api.common.tile;

import java.util.List;
import java.util.Random;

import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import speiger.src.api.api.IExpBottle;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class BasicExpBench extends TileFacing implements IInventory
{
public Random rand = new Random();
public int exp = 0;
public ItemStack[] basicExp = new ItemStack[2];
public boolean update = false;
public int facing = 0;

    @SideOnly(Side.CLIENT)
public int gettingEXP()
{
	return exp;
}
    
    @Override
public int getTextureFromTile(int meta, int side) 
{
    	if(side == this.facing)return 65;
    	else if(side == 0 || side == 1)return 64;
    	else return 66;
}

    @Override
public Packet getDescriptionPacket() 
    {
    	NBTTagCompound var1 = new NBTTagCompound();
    	super.writeToNBT(var1);
    	var1.setInteger("rotation", facing);
    	var1.setInteger("Experience", exp);
        this.worldObj.markBlockForRenderUpdate(this.xCoord, this.yCoord, this.zCoord);
    	return new Packet132TileEntityData(this.xCoord, this.yCoord, this.zCoord, 1, var1);
}
    

@Override
public void onDataPacket(INetworkManager net, Packet132TileEntityData pkt) 
{
	this.readFromNBT(pkt.customParam1);
}

    public int getSizeInventory()
    {
        return this.basicExp.length;
    }
    
    public ItemStack getStackInSlot(int par1)
    {
        return this.basicExp[par1];
    }


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

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

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

                return var3;
            }
        }
        else
        {
            return null;
        }
    }

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

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

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

    
    public String getInvName()
    {
        return "Basic EXP Storage";
    }

public int getInventoryStackLimit() 
{
	return 1;
}


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


public void openChest() 
{
}

@Override
    public void readFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readFromNBT(par1NBTTagCompound);
        exp = par1NBTTagCompound.getInteger("Experience");
        facing = par1NBTTagCompound.getInteger("rotation");
        NBTTagList var2 = par1NBTTagCompound.getTagList("Items");
        this.basicExp = new ItemStack[this.getSizeInventory()];

        for (int var3 = 0; var3 < var2.tagCount(); ++var3)
        {
            NBTTagCompound var4 = (NBTTagCompound)var2.tagAt(var3);
            byte var5 = var4.getByte("Slot");

            if (var5 >= 0 && var5 < this.basicExp.length)
            {
                this.basicExp[var5] = ItemStack.loadItemStackFromNBT(var4);
            }
        }
        
    }

    /**
     * Writes a tile entity to NBT.
     */
@Override
    public void writeToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeToNBT(par1NBTTagCompound);
       
        NBTTagList var2 = new NBTTagList();

        for (int var3 = 0; var3 < this.basicExp.length; ++var3)
        {
            if (this.basicExp[var3] != null)
            {
                NBTTagCompound var4 = new NBTTagCompound();
                var4.setByte("Slot", (byte)var3);
                this.basicExp[var3].writeToNBT(var4);
                var2.appendTag(var4);
            }
        }

        par1NBTTagCompound.setTag("Items", var2);
        par1NBTTagCompound.setInteger("Experience", exp);
     	par1NBTTagCompound.setInteger("rotation", facing);
    }

public void closeChest() 
{
}

public void updateBlock()
    {
        int var1 = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord);
        this.worldObj.markBlockForRenderUpdate(this.xCoord, this.yCoord, this.zCoord);
        markBlockDirty(this.worldObj, this.xCoord, this.yCoord, this.zCoord);
    }

    public void markBlockDirty(World var0, int var1, int var2, int var3)
    {
        if (var0.blockExists(var1, var2, var3))
        {
            var0.getChunkFromBlockCoords(var1, var3).setChunkModified();
        }
    }


@Override
public void updateEntity() 
{


	updateBlock();
                                if(!worldObj.isRemote)
                                {
	       getEXP();
	       transferExp();
                                }

	if(update)
	{
		update = false;
		this.onInventoryChanged();
	}
}


public void transferExp()
{
	if(basicExp[0] != null && basicExp[0].getItem() instanceof IExpBottle)
	{
		IExpBottle eb = (IExpBottle) basicExp[0].getItem();
		if(eb.hasExp(basicExp[0]))
		{
			if(eb.getStoredExp(basicExp[0]) > eb.getTransferlimit(basicExp[0]))
			{
				eb.discharge(eb.getTransferlimit(basicExp[0]),basicExp[0]);
				exp+= eb.getTransferlimit(basicExp[0]);
				update = true;
			}
			else if(eb.getStoredExp(basicExp[0]) > 1000)
			{
				eb.discharge(1000, basicExp[0]);
				exp+= 1000;
				update = true;
			}
			else if(eb.getStoredExp(basicExp[0]) > 100)
			{
				eb.discharge(100, basicExp[0]);
				exp+=100;
				update = true;
			}
			else
			{
				eb.discharge(1, basicExp[0]);
				exp+=1;
				update = true;
			}
		}


	}

	if(basicExp[1] != null && basicExp[1].getItem() instanceof IExpBottle)
	{
		IExpBottle eb = (IExpBottle) basicExp[1].getItem();
		if(exp > eb.getTransferlimit(basicExp[1]))
		{
			if(eb.needsExp(basicExp[1]))
			{
				if(eb.getStoredExp(basicExp[1]) + eb.getTransferlimit(basicExp[1]) <= eb.getMaxCharge(basicExp[1]))
				{
					eb.charge(eb.getTransferlimit(basicExp[1]), basicExp[1]);
					exp -= eb.getTransferlimit(basicExp[1]);
					update = true;
				}
				else
				{
					eb.charge(1, basicExp[1]);
					exp-=1;
					update = true;
				}
			}
		}
		else if(exp > 1000)
		{
			if((eb.getMaxCharge(basicExp[1]) - eb.getStoredExp(basicExp[1])) > 1000)
			{
				exp-= 1000;
				eb.charge(1000, basicExp[1]);
				update = true;
			}
		}
		else if(exp > 100)
		{
			if((eb.getMaxCharge(basicExp[1]) - eb.getStoredExp(basicExp[1])) > 100)
			{
				exp-= 100;
				eb.charge(100, basicExp[1]);
				update = true;
			}
		}
		else if(exp > 0)
		{
			if(eb.getStoredExp(basicExp[1]) < eb.getMaxCharge(basicExp[1]))
			{
				eb.charge(1, basicExp[1]);
				exp--;
				update = true;
			}
		}
	}
}


public void getEXP()
{
	List<EntityXPOrb> hitList = worldObj.getEntitiesWithinAABB(net.minecraft.entity.item.EntityXPOrb.class,
			AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1).expand(5.0D, 5.0D, 5.0D));

	if (hitList.size() > 0) {
		Loop:
		for (EntityXPOrb orb : hitList) {
			if (orb.isDead) {
				update = true;
				continue Loop;

			}

			int oldxp = exp;
			worldObj.playSoundAtEntity(orb, "random.orb", 0.1F, 0.5F * ((rand.nextFloat() - rand.nextFloat()) * 0.7F + 1.8F));
			exp += orb.getXpValue();
			orb.setDead();
			if (oldxp == 0 && exp > 0) {
				notifyChange();
				update = true;
			} else {
				notifyResize();
				update = true;
			}
		}
	}
	return;
}
private void notifyChange() {
	worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType().blockID);
	worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord - 1, zCoord, getBlockType().blockID);
	notifyResize();
}

private void notifyResize() {
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}






}

 

 

what is the problem?

I know server has to talk to the client but how if i never use the blockSide?

Posted

with getDiscriptionPacket?

and onPackedRecived?

 

These functions which are in the TileEntityClass?

 

if you mean that i already tested that it does not working!

Posted

Nope does not work.

 

i had to add a function to the container.

 

 

public int getExp()
{
     return expnow;
}

 

this only returns always 0. so i made it like this:

 

public int getExp()
{
   this.detectAndSendChanges();
   return expnow;
}

Now it showes the changes of the exp. But now the trouble it does not change anything else then i use the tile instead of the container.

 

Any other idea?

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.