Skip to content

Commit

Permalink
Properly reload the level renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeltumn committed Jul 23, 2024
1 parent 5ee6adb commit bd938ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.noxcrew.noxesium.feature.rule.impl.OptionalEnumServerRule;
import com.noxcrew.noxesium.feature.rule.impl.QibBehaviorServerRule;
import net.minecraft.client.GraphicsStatus;
import net.minecraft.client.Minecraft;
import net.minecraft.world.item.ItemStack;

import java.util.Optional;
Expand Down Expand Up @@ -85,7 +86,12 @@ public class ServerRules {
/**
* Allows the server to override the graphics mode used by the client.
*/
public static OptionalEnumServerRule<GraphicsStatus> OVERRIDE_GRAPHICS_MODE = register(new OptionalEnumServerRule<>(ServerRuleIndices.OVERRIDE_GRAPHICS_MODE, GraphicsStatus.class, Optional.empty()));
public static OptionalEnumServerRule<GraphicsStatus> OVERRIDE_GRAPHICS_MODE = register(new OptionalEnumServerRule<>(ServerRuleIndices.OVERRIDE_GRAPHICS_MODE, GraphicsStatus.class, Optional.empty(), () -> {
// We need to call this whenever we change the display type.
if (Minecraft.getInstance().levelRenderer != null) {
Minecraft.getInstance().levelRenderer.allChanged();
}
}));

/**
* Registers a new server rule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ public class OptionalEnumServerRule<T extends Enum<T>> extends ClientServerRule<

private final Optional<T> defaultValue;
private final Class<T> clazz;
private final Runnable onChange;

public OptionalEnumServerRule(int index, Class<T> clazz, Optional<T> defaultValue) {
public OptionalEnumServerRule(int index, Class<T> clazz, Optional<T> defaultValue, Runnable onChange) {
super(index);
this.clazz = clazz;
this.defaultValue = defaultValue;
this.onChange = onChange;
setValue(defaultValue);
}

Expand All @@ -32,4 +34,10 @@ public Optional<T> read(FriendlyByteBuf buffer) {
}
return Optional.empty();
}

@Override
protected void onValueChanged(Optional<T> oldValue, Optional<T> newValue) {
super.onValueChanged(oldValue, newValue);
onChange.run();
}
}

0 comments on commit bd938ac

Please sign in to comment.