Skip to content

Commit

Permalink
Be more sparing with block updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Rushmead committed Feb 10, 2025
1 parent cbd322a commit 9cf07ee
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,31 @@ public void consume(byte[] dmxValues) {
if(this.storePrev()){
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
}
intensity = convertByteToInt(ourValues[0]);
red = convertByteToInt(ourValues[1]);
green = convertByteToInt(ourValues[2]);
blue = convertByteToInt(ourValues[3]);
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
setChanged();
boolean hasUpdated = false;
int newIntensity = convertByteToInt(ourValues[0]);
if(intensity != newIntensity){
intensity = newIntensity;
hasUpdated = true;
}
int newRed = convertByteToInt(ourValues[1]);
if(red != newRed) {
red = newRed;
hasUpdated = true;
}
int newGreen = convertByteToInt(ourValues[2]);
if(green != newGreen){
green = newGreen;
hasUpdated = true;
}
int newBlue = convertByteToInt(ourValues[3]);
if(blue != newBlue){
blue = newBlue;
hasUpdated = true;
}
if(hasUpdated) {
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
setChanged();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,31 @@ public void consume(byte[] dmxValues) {
if(this.storePrev()){
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
}
intensity = convertByteToInt(ourValues[0]);
red = convertByteToInt(ourValues[1]);
green = convertByteToInt(ourValues[2]);
blue = convertByteToInt(ourValues[3]);
setChanged();
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
boolean hasUpdated = false;
int newIntensity = convertByteToInt(ourValues[0]);
if(intensity != newIntensity){
intensity = newIntensity;
hasUpdated = true;
}
int newRed = convertByteToInt(ourValues[1]);
if(red != newRed) {
red = newRed;
hasUpdated = true;
}
int newGreen = convertByteToInt(ourValues[2]);
if(green != newGreen){
green = newGreen;
hasUpdated = true;
}
int newBlue = convertByteToInt(ourValues[3]);
if(blue != newBlue){
blue = newBlue;
hasUpdated = true;
}
if(hasUpdated) {
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
setChanged();
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,46 @@ public void consume(byte[] dmxValues) {
if(this.storePrev()){
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
}
intensity = convertByteToInt(ourValues[0]);
red = convertByteToInt(ourValues[1]);
green = convertByteToInt(ourValues[2]);
blue = convertByteToInt(ourValues[3]);
focus = convertByteToInt(ourValues[4]);
pan = (int) ((convertByteToInt(ourValues[5]) * 360) / 255f) - 180;
tilt = (int) ((convertByteToInt(ourValues[6]) * 180) / 255F) - 180;
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
setChanged();
boolean hasUpdated = false;
int newIntensity = convertByteToInt(ourValues[0]);
if(intensity != newIntensity){
intensity = newIntensity;
hasUpdated = true;
}
int newRed = convertByteToInt(ourValues[1]);
if(red != newRed) {
red = newRed;
hasUpdated = true;
}
int newGreen = convertByteToInt(ourValues[2]);
if(green != newGreen){
green = newGreen;
hasUpdated = true;
}
int newBlue = convertByteToInt(ourValues[3]);
if(blue != newBlue){
blue = newBlue;
hasUpdated = true;
}
int newFocus = convertByteToInt(ourValues[4]);
if(focus != newFocus){
focus = newFocus;
hasUpdated = true;
}
int newPan = (int) ((convertByteToInt(ourValues[5]) * 360) / 255f) - 180;
if(pan != newPan){
pan = newPan;
hasUpdated = true;
}
int newTilt = (int) ((convertByteToInt(ourValues[6]) * 180) / 255F) - 180;
if(tilt != newTilt){
tilt = newTilt;
hasUpdated = true;
}
if(hasUpdated) {
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
setChanged();
}
}

@Override
Expand Down

0 comments on commit 9cf07ee

Please sign in to comment.