Jump to content

Weird behaviour when syncing TE [1.12.2]


ZigTheHedge

Recommended Posts

Hello!

 

I ran into very strange issue while trying to sync TE from server to client AGAIN. But this time it's really magic. When I call tsTE.activate() everything is in sync and works fine, but when tsTE.deactivate() is called - value on server side is changing, but it doesn't on client side, although received packet is fine. So, the client thinks "isMoving" equals "true" no matter what.

Here's some code:

Method from which I call my update method:

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if(!worldIn.isRemote)
    {
        ...
        TileEntity te = worldIn.getTileEntity(pos);
        if(te instanceof PistonVesselTE) {
            TimeSymbolTE tsTE = (TimeSymbolTE) worldIn.getTileEntity(((PistonVesselTE) te).getMainBlockPos());
            if (tsTE.isStructureComplete())
            {
                tsTE.activate();
            } else {
                if(tsTE.isMoving)
                    tsTE.deactivate();
            }
        }
    }
    return true;
}

 

TileEntity's methods:

public void activate()
{
    if(isMoving)return;
    if(world.isRemote)return;
    isMoving = true;

    ...
    markDirty();
    world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 3);
}

public void deactivate()
{
    if(!isMoving)return;
    if(world.isRemote)return;
    isMoving = false;
    
    ...
    markDirty();
    world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 3);
}

 

TileEntity's NBT methods:

@Override
public void readFromNBT(NBTTagCompound compound) {
    super.readFromNBT(compound);
    if(compound.hasKey("isMoving")) isMoving = compound.getBoolean("isMoving");
    if(compound.hasKey("structureChecked")) isMoving = compound.getBoolean("structureChecked");
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    compound = super.writeToNBT(compound);
    compound.setBoolean("isMoving", isMoving);
    compound.setBoolean("structureChecked", structureChecked);
    return compound;
}

 

TileEntity's Sync stuff:

@Override
public NBTTagCompound getUpdateTag() {
    return writeToNBT(new NBTTagCompound());
}

@Override
public SPacketUpdateTileEntity getUpdatePacket() {
    NBTTagCompound nbtTag = new NBTTagCompound();
    this.writeToNBT(nbtTag);
    return new SPacketUpdateTileEntity(getPos(), 1, nbtTag);
}

@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
    super.onDataPacket(net, packet);
    this.readFromNBT(packet.getNbtCompound());
    ModMain.logger.info("Received packet: "+packet.getNbtCompound().toString()+", side: "+world.isRemote);
    world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 3);
}

 

In debug info, everything is fine. I get the correct isMoving=0b in NBT with world.isRemote=true

 

Edited by ZigTheHedge
Link to comment
Share on other sites

if(compound.hasKey("isMoving")) isMoving = compound.getBoolean("isMoving");
if(compound.hasKey("structureChecked")) isMoving = compound.getBoolean("structureChecked");

???????

Is this on purpose?

Edited by Afroman
  • Like 1
Link to comment
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.
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.