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:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

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
6 minutes ago, Niprow said:

you could change it in Block#tickRate (maybe)

 

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

Posted
9 hours ago, AlexInCube said:

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

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:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

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.