Message constructor rework (use passed args).

This commit is contained in:
Florian Nücke
2022-01-15 19:38:39 +01:00
parent 0be9994bf7
commit 6262cd9de1
8 changed files with 22 additions and 18 deletions

View File

@@ -453,7 +453,7 @@ public final class ComputerBlockEntity extends ModBlockEntity implements Termina
@Override
protected void handleBusStateChanged(final CommonDeviceBusController.BusState value) {
Network.sendToClientsTrackingChunk(new ComputerBusStateMessage(ComputerBlockEntity.this), chunk);
Network.sendToClientsTrackingChunk(new ComputerBusStateMessage(ComputerBlockEntity.this, value), chunk);
if (value == CommonDeviceBusController.BusState.READY && level != null) {
// Bus just became ready, meaning new devices may be available, meaning new
@@ -467,13 +467,13 @@ public final class ComputerBlockEntity extends ModBlockEntity implements Termina
// This method can be called from disposal logic, so if we are disposed quickly enough
// chunk may not be initialized yet. Avoid resulting NRE in network logic.
if (chunk != null) {
Network.sendToClientsTrackingChunk(new ComputerRunStateMessage(ComputerBlockEntity.this), chunk);
Network.sendToClientsTrackingChunk(new ComputerRunStateMessage(ComputerBlockEntity.this, value), chunk);
}
}
@Override
protected void handleBootErrorChanged(@Nullable final Component value) {
Network.sendToClientsTrackingChunk(new ComputerBootErrorMessage(ComputerBlockEntity.this), chunk);
Network.sendToClientsTrackingChunk(new ComputerBootErrorMessage(ComputerBlockEntity.this, value), chunk);
}
}
}

View File

@@ -823,17 +823,17 @@ public final class Robot extends Entity implements li.cil.oc2.api.capabilities.R
@Override
protected void handleBusStateChanged(final CommonDeviceBusController.BusState value) {
Network.sendToClientsTrackingEntity(new RobotBusStateMessage(Robot.this), Robot.this);
Network.sendToClientsTrackingEntity(new RobotBusStateMessage(Robot.this, value), Robot.this);
}
@Override
protected void handleRunStateChanged(final VMRunState value) {
Network.sendToClientsTrackingEntity(new RobotRunStateMessage(Robot.this), Robot.this);
Network.sendToClientsTrackingEntity(new RobotRunStateMessage(Robot.this, value), Robot.this);
}
@Override
protected void handleBootErrorChanged(@Nullable final Component value) {
Network.sendToClientsTrackingEntity(new RobotBootErrorMessage(Robot.this), Robot.this);
Network.sendToClientsTrackingEntity(new RobotBootErrorMessage(Robot.this, value), Robot.this);
}
}

View File

@@ -7,15 +7,17 @@ import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraftforge.network.NetworkEvent;
import javax.annotation.Nullable;
public final class ComputerBootErrorMessage extends AbstractMessage {
private BlockPos pos;
private Component value;
///////////////////////////////////////////////////////////////////
public ComputerBootErrorMessage(final ComputerBlockEntity computer) {
public ComputerBootErrorMessage(final ComputerBlockEntity computer, @Nullable final Component value) {
this.pos = computer.getBlockPos();
this.value = computer.getVirtualMachine().getBootError();
this.value = value;
}
public ComputerBootErrorMessage(final FriendlyByteBuf buffer) {

View File

@@ -13,9 +13,9 @@ public final class ComputerBusStateMessage extends AbstractMessage {
///////////////////////////////////////////////////////////////////
public ComputerBusStateMessage(final ComputerBlockEntity computer) {
public ComputerBusStateMessage(final ComputerBlockEntity computer, final CommonDeviceBusController.BusState value) {
this.pos = computer.getBlockPos();
this.value = computer.getVirtualMachine().getBusState();
this.value = value;
}
public ComputerBusStateMessage(final FriendlyByteBuf buffer) {

View File

@@ -13,9 +13,9 @@ public final class ComputerRunStateMessage extends AbstractMessage {
///////////////////////////////////////////////////////////////////
public ComputerRunStateMessage(final ComputerBlockEntity computer) {
public ComputerRunStateMessage(final ComputerBlockEntity computer, final VMRunState value) {
this.pos = computer.getBlockPos();
this.value = computer.getVirtualMachine().getRunState();
this.value = value;
}
public ComputerRunStateMessage(final FriendlyByteBuf buffer) {

View File

@@ -6,15 +6,17 @@ import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraftforge.network.NetworkEvent;
import javax.annotation.Nullable;
public final class RobotBootErrorMessage extends AbstractMessage {
private int entityId;
private Component value;
///////////////////////////////////////////////////////////////////
public RobotBootErrorMessage(final Robot robot) {
public RobotBootErrorMessage(final Robot robot, @Nullable final Component value) {
this.entityId = robot.getId();
this.value = robot.getVirtualMachine().getBootError();
this.value = value;
}
public RobotBootErrorMessage(final FriendlyByteBuf buffer) {

View File

@@ -12,9 +12,9 @@ public final class RobotBusStateMessage extends AbstractMessage {
///////////////////////////////////////////////////////////////////
public RobotBusStateMessage(final Robot robot) {
public RobotBusStateMessage(final Robot robot, final CommonDeviceBusController.BusState value) {
this.entityId = robot.getId();
this.value = robot.getVirtualMachine().getBusState();
this.value = value;
}
public RobotBusStateMessage(final FriendlyByteBuf buffer) {

View File

@@ -12,9 +12,9 @@ public final class RobotRunStateMessage extends AbstractMessage {
///////////////////////////////////////////////////////////////////
public RobotRunStateMessage(final Robot robot) {
public RobotRunStateMessage(final Robot robot, final VMRunState value) {
this.entityId = robot.getId();
this.value = robot.getVirtualMachine().getRunState();
this.value = value;
}
public RobotRunStateMessage(final FriendlyByteBuf buffer) {