Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Laser Pipe Client Desync + Small Rework #2245

Merged
merged 2 commits into from
Dec 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -156,32 +156,29 @@ public boolean isActive() {
* @param duration how long the pipe should be active for
*/
public void setActive(boolean active, int duration) {
boolean stateChanged = false;
if (this.isActive && !active) {
this.isActive = false;
stateChanged = true;
} else if (!this.isActive && active) {
this.isActive = true;
stateChanged = true;
activeDuration = duration;
TaskScheduler.scheduleTask(getWorld(), () -> {
if (++this.ticksActive % activeDuration == 0) {
this.ticksActive = 0;
setActive(false, -1);
return false;
}
return true;
});
} else if (this.isActive) {
if (this.isActive != active) {
this.isActive = active;
notifyBlockUpdate();
markDirty();
writeCustomData(GregtechDataCodes.PIPE_LASER_ACTIVE, buf -> buf.writeBoolean(this.isActive));
if (active && duration != this.activeDuration) {
TaskScheduler.scheduleTask(getWorld(), this::queueDisconnect);
}
}

this.activeDuration = duration;
if (duration > 0 && active) {
this.ticksActive = 0;
this.activeDuration = duration;
}
}

if (stateChanged) {
writeCustomData(GregtechDataCodes.PIPE_LASER_ACTIVE, buf -> buf.writeBoolean(this.isActive));
notifyBlockUpdate();
markDirty();
public boolean queueDisconnect() {
if (++this.ticksActive % activeDuration == 0) {
this.ticksActive = 0;
setActive(false, -1);
return false;
}
return true;
}

@Override
Expand All @@ -193,6 +190,25 @@ public void receiveCustomData(int discriminator, PacketBuffer buf) {
}
}

@Override
public void writeInitialSyncData(PacketBuffer buf) {
super.writeInitialSyncData(buf);
buf.writeBoolean(this.isActive);

// schedule a disconnect on world load, gotta set the duration to something
if (isActive) {
activeDuration = 100;
TaskScheduler.scheduleTask(getWorld(), this::queueDisconnect);
}
}

@Override
public void receiveInitialSyncData(PacketBuffer buf) {
super.receiveInitialSyncData(buf);
this.isActive = buf.readBoolean();
scheduleChunkForRenderUpdate();
}

@NotNull
@Override
public NBTTagCompound writeToNBT(@NotNull NBTTagCompound compound) {
Expand Down