Jump to content

[1.7] sometimes TileEntity doesn't sync with server


Recommended Posts

Posted

hey,

I made a TE which processes 2 items into 2 other items.

 

Sometimes, only while the processing is true, when I took an itemstack from a TE slot, on the client the itemstack is still in the machine.

 

normal behaviour:

 

[00:03:36] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:40]: read_before: 59xtile.blockRedstone@0
[00:03:36] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:51]: read_after: 59xtile.blockRedstone@0
[00:03:36] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:63]: write_before: 59xtile.blockRedstone@0
[00:03:36] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:86]: write_after: 59xtile.blockRedstone@0
[00:03:36] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:40]: read_before: 59xtile.blockRedstone@0
[00:03:36] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:51]: read_after: 59xtile.blockRedstone@0
[00:03:36] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:63]: write_before: 59xtile.blockRedstone@0
[00:03:36] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:86]: write_after: 59xtile.blockRedstone@0
[00:03:36] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:40]: read_before: 59xtile.blockRedstone@0
[00:03:36] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:51]: read_after: 59xtile.blockRedstone@0
[00:03:36] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:63]: write_before: null
[00:03:36] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:86]: write_after: null
[00:03:36] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:40]: read_before: null
[00:03:36] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:51]: read_after: null
[00:03:37] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:63]: write_before: null
[00:03:37] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:86]: write_after: null

 

 

bad behaviour:

 

[00:09:49] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:40]: read_before: 59xtile.blockRedstone@0
[00:09:49] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:51]: read_after: 59xtile.blockRedstone@0
[00:09:49] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:63]: write_before: 59xtile.blockRedstone@0
[00:09:49] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:86]: write_after: 59xtile.blockRedstone@0
[00:09:49] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:40]: read_before: 59xtile.blockRedstone@0
[00:09:49] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:51]: read_after: 59xtile.blockRedstone@0
[00:09:49] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:63]: write_before: 59xtile.blockRedstone@0
[00:09:49] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:86]: write_after: 59xtile.blockRedstone@0
[00:09:49] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:40]: read_before: null
[00:09:49] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:51]: read_after: 59xtile.blockRedstone@0
[00:09:49] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:63]: write_before: null
[00:09:49] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:86]: write_after: null
[00:09:49] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:40]: read_before: 59xtile.blockRedstone@0
[00:09:49] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:51]: read_after: 59xtile.blockRedstone@0
[00:09:50] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:63]: write_before: null
[00:09:50] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:86]: write_after: null
[00:09:50] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:40]: read_before: 59xtile.blockRedstone@0
[00:09:50] [Client thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:readFromNBT:51]: read_after: 59xtile.blockRedstone@0
[00:09:50] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:63]: write_before: null
[00:09:50] [server thread/INFO] [sTDOUT]: [mrriegel.alpre.tile.TileElectrolyzer:writeToNBT:86]: write_after: null

 

 

TE:

public class TileElectrolyzer extends TileEntity implements ISidedInventory {

public static final int INV_SIZE = 5;
public static String tagName = "TileEle";
private ItemStack[] inv;
private int puffer, process;
private boolean processing;
ItemStack o1, o2;

public TileElectrolyzer() {
	super();
	inv = new ItemStack[iNV_SIZE];
}

@Override
public void readFromNBT(NBTTagCompound tag) {
	super.readFromNBT(tag);
	System.out.println("read_before: " + inv[4]);
	NBTTagList invList = tag
			.getTagList(tagName, Constants.NBT.TAG_COMPOUND);
	for (int i = 0; i < invList.tagCount(); i++) {
		NBTTagCompound stackTag = invList.getCompoundTagAt(i);
		int slot = stackTag.getByte("Slot");

		if (slot >= 0 && slot < inv.length) {
			inv[slot] = ItemStack.loadItemStackFromNBT(stackTag);
		}
	}
	System.out.println("read_after: " + inv[4]);
	puffer = tag.getInteger("puffer");
	processing = tag.getBoolean("processing");
	NBTTagCompound st1 = (NBTTagCompound) tag.getTag("o1");
	o1 = ItemStack.loadItemStackFromNBT(st1);
	NBTTagCompound st2 = (NBTTagCompound) tag.getTag("o2");
	o2 = ItemStack.loadItemStackFromNBT(st2);
}

@Override
public void writeToNBT(NBTTagCompound tag) {
	super.writeToNBT(tag);
	System.out.println("write_before: " + inv[4]);
	NBTTagList invList = new NBTTagList();
	for (int i = 0; i < inv.length; i++) {
		if (inv[i] != null) {
			NBTTagCompound stackTag = new NBTTagCompound();
			stackTag.setByte("Slot", (byte) i);
			inv[i].writeToNBT(stackTag);
			invList.appendTag(stackTag);
		}
	}

	tag.setInteger("puffer", puffer);
	tag.setBoolean("processing", processing);
	NBTTagCompound st1 = new NBTTagCompound();
	if (o1 != null)
		o1.writeToNBT(st1);
	tag.setTag("o1", st1);
	NBTTagCompound st2 = new NBTTagCompound();
	if (o2 != null)
		o2.writeToNBT(st2);

	tag.setTag("o2", st2);
	tag.setTag(tagName, invList);
	System.out.println("write_after: " + inv[4]);

}

@Override
public Packet getDescriptionPacket() {
	NBTTagCompound syncData = new NBTTagCompound();
	this.writeToNBT(syncData);
	return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord,
			this.zCoord, 1, syncData);
}

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
	readFromNBT(pkt.func_148857_g());
}

@Override
public ItemStack decrStackSize(int slot, int size) {
	ItemStack stack = getStackInSlot(slot);
	if (stack != null) {
		if (stack.stackSize <= size) {
			setInventorySlotContents(slot, null);
			worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
			return stack;
		} else {
			stack = stack.splitStack(size);
			if (stack.stackSize == 0) {
				setInventorySlotContents(slot, null);
			}
			worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
			return stack;
		}
	} else {
		worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
		return null;
	}

}

@Override
public ItemStack getStackInSlotOnClosing(int slot) {
	ItemStack stack = getStackInSlot(slot);
	if (stack != null) {
		setInventorySlotContents(slot, null);
	}
	return stack;
}

@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
	inv[slot] = stack;
	if (stack != null && stack.stackSize > getInventoryStackLimit()) {
		stack.stackSize = getInventoryStackLimit();
	}
	worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return worldObj.getTileEntity(xCoord, yCoord, zCoord) == this
			&& player.getDistanceSq(xCoord + 0.5, yCoord + 0.5,
					zCoord + 0.5) < 64;
}

@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
	if (slot == 2 || slot == 3)
		return false;
	if (slot == 4)
		if (stack.getItem().equals(Items.redstone)
				|| stack.getItem().equals(
						Item.getItemFromBlock(Blocks.redstone_block)))
			return true;
		else
			return false;
	return true;
}

@Override
public int[] getAccessibleSlotsFromSide(int side) {
	return side == 1 ? new int[] { 0, 1 } : side != 0 ? new int[] { 4 }
			: new int[] { 2, 3 };
}

@Override
public boolean canInsertItem(int slot, ItemStack stack, int side) {
	if ((slot == 0 || slot == 1) && side == 1)
		return true;
	if (slot == 4 && side != 0 && side != 1)
		return true;
	return false;
}

@Override
public boolean canExtractItem(int slot, ItemStack stack, int side) {
	if (side == 0 && (slot == 2 || slot == 3))
		return true;
	else
		return false;
}

@Override
public void updateEntity() {
	super.updateEntity();
	if (worldObj.isRemote)
		return;

	//fill fuel
	ItemStack fuel = getStackInSlot(4);
	if (fuel != null && worldObj.getTotalWorldTime() % 6 == 0) {
		if (fuel.getItem().equals(Items.redstone) && puffer <= 45 - 3) {
			puffer += 3;
			--fuel.stackSize;
			if (fuel.stackSize <= 0)
				setInventorySlotContents(4, null);
			else
				setInventorySlotContents(4, fuel.copy());
		} else if (fuel.getItem().equals(
				Item.getItemFromBlock(Blocks.redstone_block))
				&& puffer <= 45 - 36) {
			puffer += 36;
			--fuel.stackSize;
			if (fuel.stackSize <= 0)
				setInventorySlotContents(4, null);
			else
				setInventorySlotContents(4, fuel.copy());
		}
	}
	//check for recipe
	if (!processing && getStackInSlot(0) != null
			&& getStackInSlot(1) != null && puffer >= 6) {
		boolean match = false;
		for (ElectrolyzerRecipe r : ElectrolyzerRecipes.lis) {
			if (r.matches(worldObj, this)
					&& !RiegelUtils.isStackEqual(getStackInSlot(0),
							getStackInSlot(1))) {
				boolean zwei = getStackInSlot(2) == null
						&& getStackInSlot(3) == null;
				boolean eins;
				try {
					eins = RiegelUtils.isStackEqual(r.getOutput1(),
							getStackInSlot(2))
							&& RiegelUtils.isStackEqual(r.getOutput2(),
									getStackInSlot(3))
							&& getStackInSlot(2).stackSize < getStackInSlot(
									2).getMaxStackSize()
							&& getStackInSlot(3).stackSize < getStackInSlot(
									3).getMaxStackSize();
				} catch (NullPointerException e) {
					System.out.println(e.getMessage());
					eins = false;
				}
				if (eins || zwei) {
					match = true;
					o1 = r.getOutput1().copy();
					o2 = r.getOutput2().copy();
					break;
				}
			}
		}
		if (match) {
			RiegelUtils.decr(this, 0);
			RiegelUtils.decr(this, 1);
			puffer -= 6;
			processing = true;
		}
	}

	//process
	if (processing && worldObj.getTotalWorldTime() % 20 / 3 == 0) {
		if (process < 24)
			process++;
		else {
			process = 0;
			processing = false;
			RiegelUtils.incr(this, 2, o1);
			RiegelUtils.incr(this, 3, o2);
			o1 = null;
			o2 = null;

		}
		worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);

		//updating progressbar
		PacketHandler.INSTANCE.sendToDimension(new PacketUpdate(xCoord,
				yCoord, zCoord, process, getStackInSlot(0) == null,
				getStackInSlot(1) == null, getStackInSlot(4) == null),
				worldObj.provider.dimensionId);
	}
}
}

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.

×
×
  • Create New...

Important Information

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