Skip to content

Commit

Permalink
fix garlic diffuser sync and rednering issues
Browse files Browse the repository at this point in the history
- fix activation rendering issues with garlic diffusers
- fix fuel status not saved
  • Loading branch information
Cheaterpaul committed Aug 26, 2023
1 parent dee97f0 commit 4b97a27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void load(@NotNull CompoundTag compound) {
r = compound.getInt("radius");
defaultStrength = EnumStrength.getFromStrength(compound.getInt("strength"));
bootTimer = compound.getInt("boot_timer");
maxBootTimer = compound.contains("max_boot_timer") ? compound.getInt("max_boot_timer") : 1;
setFueledTime(compound.getInt("fueled"));
}

Expand All @@ -114,7 +115,7 @@ public void onTouched(@NotNull Player player) {

public void onFueled() {
setFueledTime(FUEL_DURATION);
this.setChanged();
this.updateLevel();
}

@Override
Expand All @@ -125,6 +126,7 @@ public void saveAdditional(@NotNull CompoundTag compound) {
compound.putInt("fueled", fueled);
if (bootTimer != 0) {
compound.putInt("boot_timer", bootTimer);
compound.putInt("max_boot_timer", maxBootTimer);
}
}

Expand Down Expand Up @@ -155,9 +157,8 @@ public void setType(GarlicDiffuserBlock.@NotNull Type type) {
strength = defaultStrength;
}

@Override
public void setChanged() {
super.setChanged();
public void updateLevel() {
this.setChanged();
if (hasLevel()) {
BlockState state = level.getBlockState(worldPosition);
this.level.sendBlockUpdated(worldPosition, state, state, 3);
Expand All @@ -173,7 +174,7 @@ public void setRemoved() {


public static void tick(Level level, BlockPos pos, BlockState state, @NotNull GarlicDiffuserBlockEntity blockEntity) {
if (blockEntity.initiateBootTimer) {
if (blockEntity.initiateBootTimer && !level.isClientSide) {
blockEntity.initiateBootTimer = false;
int bootTime = VampirismConfig.BALANCE.garlicDiffuserStartupTime.get() * 20;
if (level instanceof ServerLevel serverLevel) {
Expand All @@ -183,19 +184,20 @@ public static void tick(Level level, BlockPos pos, BlockState state, @NotNull Ga
}
blockEntity.bootTimer = bootTime;
blockEntity.maxBootTimer = bootTime;

blockEntity.updateLevel();
}
if (blockEntity.bootTimer > 0) {
if (--blockEntity.bootTimer == 0) {
blockEntity.setChanged();
blockEntity.updateLevel();
blockEntity.register();
}
} else if (blockEntity.fueled > 0) {
if (blockEntity.fueled == 1) {
blockEntity.setFueledTime(0);
blockEntity.setChanged();
blockEntity.updateLevel();
} else {
blockEntity.fueled--;
blockEntity.setChanged();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ public void render(@NotNull GuiGraphics graphics, int mouseX, int mouseY, float

}

@Override
public void tick() {
private void updateProgress() {
startupBar.setProgress(tile.getBootProgress());
float f = tile.getFueledState();
if (f == 0) {
Expand All @@ -55,7 +54,11 @@ public void tick() {
fueledTimer.active = true;
fueledTimer.setProgress(f);
}
}

@Override
public void tick() {
updateProgress();
}

@Override
Expand All @@ -70,6 +73,8 @@ protected void init() {
fueledTimer = this.addRenderableWidget(new ProgressBar(this.guiLeft + (xSize - 170) / 2, this.guiTop + 60, 170, Component.translatable("gui.vampirism.garlic_diffuser.fueled")));
fueledTimer.setColor(0xD0FFD0);
fueledTimer.setFGColor(0xFFFFFF);

updateProgress();
}

protected void renderGuiBackground(@NotNull GuiGraphics graphics) {
Expand Down

0 comments on commit 4b97a27

Please sign in to comment.