Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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

???????

Is this on purpose?

Edited by Afroman

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.