Jump to content

Recommended Posts

Posted

I need to synchronize the angle in TE, the angle changes to the server, but not in the client. I don't need to save it in NBT. I used packets to send data from GUI to TE. But I need TE to send the packet to the TE client, how do I do that?

Posted
@Nullable
    @Override
    public SUpdateTileEntityPacket getUpdatePacket() {
        CompoundNBT tag = new CompoundNBT();
        write(tag);
        return new SUpdateTileEntityPacket(this.pos,0,tag);
    }

    @Override
    public CompoundNBT getUpdateTag() {
        return write(new CompoundNBT());
    }

    @Override
    public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
        super.onDataPacket(net, pkt);
        readFromNBT(pkt.getNbtCompound());

        BlockState state = this.world.getBlockState(this.pos);
        this.world.notifyBlockUpdate(this.pos, state, state, 3);
    }

I used it, but nothing worked.

Posted

World#notifyBlockUpdate you can not call that in onDataPacket or getUpdatePacket

 I will make fun of you if you are not able to look into the (vanilla-) code.

Posted
    @Override
    public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
        super.onDataPacket(net, pkt);
        readFromNBT(pkt.getNbtCompound());

        BlockState state = this.world.getBlockState(this.pos);
        this.world.notifyBlockUpdate(this.pos, state, state, 3);
    }

World#notifyBlockUpdate is used to notify a block update, not actually update the block on the client side. All you have to do is to read data packet in onDataPacket.

Some tips:

  Reveal hidden contents

 

Posted

I understand it, I thought it only synchronized what's in the read and write. 

    @Nullable
    @Override
    public SUpdateTileEntityPacket getUpdatePacket() {
        CompoundNBT tag = new CompoundNBT();
        tag.putInt(ANGLE_TAG,this.angle);
        return new SUpdateTileEntityPacket(this.pos,0,tag);
    }

    @Override
    public CompoundNBT getUpdateTag() {
        return write(new CompoundNBT());
    }

    @Override
    public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) {
        super.onDataPacket(net, pkt);
        BlockState state = this.world.getBlockState(this.pos);
        this.angle = pkt.getNbtCompound().getInt(ANGLE_TAG);
        this.world.notifyBlockUpdate(this.pos, state, state, 3);
    }

 

Posted (edited)

but the animation in the renderer is kind of jerky.

matrixStackIn.rotate(Vector3f.YP.rotationDegrees(angle+partialTicks*2));

there's gotta be a smooth rotation, and it feels like the animation has 20 fps.

 

public void updateAnimation() { this.angle += 2; if (this.angle > 358) { this.angle = 0; } spawnWaterParticles(this.world, pos, 0, this.angle); }

 

public int getAngle(){ return this.angle; }

Edited by AlexInCube
Posted (edited)

that is so because of the tick-rate in your tile entity

(if you update it in ITickableTileEntity#tick)

you could change it in Block#tickRate (maybe)

Edited by Niprow
how to change tick rate

 I will make fun of you if you are not able to look into the (vanilla-) code.

Posted
  On 4/29/2020 at 3:04 PM, AlexInCube said:

this.world.notifyBlockUpdate(this.pos, state, state, 3);

Expand  

You are still doing this. Don't do this on the client, as it does nothing (well it might do something, but definitely not what you are expecting).

 

Only send a packet to update your tile entity if the angle changes. Don't do it every tick.

If the angle is not unpredictable and only change as part of an animation, send a packet to the client when the animation starts and handle the animation on the client side.

Some tips:

  Reveal hidden contents

 

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.