Skip to content

Commit

Permalink
change: Use Skybox for SkyboxType
Browse files Browse the repository at this point in the history
  • Loading branch information
FlashyReese committed Nov 17, 2023
1 parent 9e53e51 commit be9326a
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.github.amerebagatelle.fabricskyboxes.api.FabricSkyBoxesApi;
import io.github.amerebagatelle.fabricskyboxes.api.skyboxes.Skybox;
import io.github.amerebagatelle.fabricskyboxes.mixin.skybox.WorldRendererAccess;
import io.github.amerebagatelle.fabricskyboxes.skyboxes.AbstractSkybox;
import io.github.amerebagatelle.fabricskyboxes.skyboxes.SkyboxType;
import io.github.amerebagatelle.fabricskyboxes.util.JsonObjectWrapper;
import io.github.amerebagatelle.fabricskyboxes.util.object.internal.Metadata;
Expand Down Expand Up @@ -42,8 +41,8 @@ public class SkyboxManager implements FabricSkyBoxesApi, ClientTickEvents.EndWor
private Skybox currentSkybox = null;
private boolean enabled = true;

public static AbstractSkybox parseSkyboxJson(Identifier id, JsonObjectWrapper objectWrapper) {
AbstractSkybox skybox;
public static Skybox parseSkyboxJson(Identifier id, JsonObjectWrapper objectWrapper) {
Skybox skybox;
Metadata metadata;

try {
Expand All @@ -54,7 +53,7 @@ public static AbstractSkybox parseSkyboxJson(Identifier id, JsonObjectWrapper ob
return null;
}

SkyboxType<? extends AbstractSkybox> type = SkyboxType.REGISTRY.get(metadata.getType());
SkyboxType<? extends Skybox> type = SkyboxType.REGISTRY.get(metadata.getType());
Preconditions.checkNotNull(type, "Unknown skybox type: " + metadata.getType().getPath().replace('_', '-'));
if (metadata.getSchemaVersion() == 1) {
Preconditions.checkArgument(type.isLegacySupported(), "Unsupported schema version '1' for skybox type " + type.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static class KeyBindingImpl implements ClientTickEvents.EndTick {

public KeyBindingImpl() {
this.toggleFabricSkyBoxes = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.fabricskyboxes.toggle", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, "category.fabricskyboxes"));
this.toggleSkyboxDebugHud = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.fabricskyboxes.toggle.debug_hud", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_F12, "category.fabricskyboxes"));
this.toggleSkyboxDebugHud = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.fabricskyboxes.toggle.debug_hud", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, "category.fabricskyboxes"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import io.github.amerebagatelle.fabricskyboxes.FabricSkyBoxesClient;
import io.github.amerebagatelle.fabricskyboxes.api.skyboxes.FSBSkybox;
import io.github.amerebagatelle.fabricskyboxes.api.skyboxes.Skybox;
import io.github.amerebagatelle.fabricskyboxes.mixin.skybox.WorldRendererAccess;
import io.github.amerebagatelle.fabricskyboxes.util.Utils;
import io.github.amerebagatelle.fabricskyboxes.util.object.Conditions;
Expand Down Expand Up @@ -208,7 +209,7 @@ protected boolean checkWeather() {
ClientWorld world = Objects.requireNonNull(MinecraftClient.getInstance().world);
ClientPlayerEntity player = Objects.requireNonNull(MinecraftClient.getInstance().player);
Biome.Precipitation precipitation = world.getBiome(player.getBlockPos()).value().getPrecipitation(player.getBlockPos());
if (this.conditions.getWeathers().size() > 0) {
if (!this.conditions.getWeathers().isEmpty()) {
if (this.conditions.getWeathers().contains(Weather.THUNDER) && world.isThundering()) {
return true;
}
Expand All @@ -227,7 +228,7 @@ protected boolean checkWeather() {
}
}

public abstract SkyboxType<? extends AbstractSkybox> getType();
public abstract SkyboxType<? extends Skybox> getType();

public void renderDecorations(WorldRendererAccess worldRendererAccess, MatrixStack matrices, Matrix4f matrix4f, float tickDelta, BufferBuilder bufferBuilder, float alpha) {
RenderSystem.enableBlend();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.amerebagatelle.fabricskyboxes.api.skyboxes.Skybox;
import io.github.amerebagatelle.fabricskyboxes.mixin.skybox.WorldRendererAccess;
import io.github.amerebagatelle.fabricskyboxes.util.object.Conditions;
import io.github.amerebagatelle.fabricskyboxes.util.object.Decorations;
Expand All @@ -25,7 +26,7 @@ public EndSkybox(Properties properties, Conditions conditions, Decorations decor
}

@Override
public SkyboxType<? extends AbstractSkybox> getType() {
public SkyboxType<? extends Skybox> getType() {
return SkyboxType.END_SKYBOX;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.google.gson.JsonElement;
import com.mojang.serialization.Lifecycle;
import io.github.amerebagatelle.fabricskyboxes.FabricSkyBoxesClient;
import io.github.amerebagatelle.fabricskyboxes.api.skyboxes.Skybox;
import io.github.amerebagatelle.fabricskyboxes.skyboxes.textured.SquareTexturedSkybox;
import io.github.amerebagatelle.fabricskyboxes.util.JsonObjectWrapper;
import io.github.amerebagatelle.fabricskyboxes.util.object.*;
Expand All @@ -19,17 +20,17 @@
import java.util.List;
import java.util.function.BiConsumer;

public class LegacyDeserializer<T extends AbstractSkybox> {
public static final Registry<LegacyDeserializer<? extends AbstractSkybox>> REGISTRY = FabricRegistryBuilder.<LegacyDeserializer<? extends AbstractSkybox>, SimpleRegistry<LegacyDeserializer<? extends AbstractSkybox>>>from(new SimpleRegistry<>(RegistryKey.ofRegistry(new Identifier(FabricSkyBoxesClient.MODID, "legacy_skybox_deserializer")), Lifecycle.stable())).buildAndRegister();
public class LegacyDeserializer<T extends Skybox> {
public static final Registry<LegacyDeserializer<? extends Skybox>> REGISTRY = FabricRegistryBuilder.<LegacyDeserializer<? extends Skybox>, SimpleRegistry<LegacyDeserializer<? extends Skybox>>>from(new SimpleRegistry<>(RegistryKey.ofRegistry(new Identifier(FabricSkyBoxesClient.MODID, "legacy_skybox_deserializer")), Lifecycle.stable())).buildAndRegister();
public static final LegacyDeserializer<MonoColorSkybox> MONO_COLOR_SKYBOX_DESERIALIZER = register(new LegacyDeserializer<>(LegacyDeserializer::decodeMonoColor, MonoColorSkybox.class), "mono_color_skybox_legacy_deserializer");
public static final LegacyDeserializer<SquareTexturedSkybox> SQUARE_TEXTURED_SKYBOX_DESERIALIZER = register(new LegacyDeserializer<>(LegacyDeserializer::decodeSquareTextured, SquareTexturedSkybox.class), "square_textured_skybox_legacy_deserializer");
private final BiConsumer<JsonObjectWrapper, AbstractSkybox> deserializer;
private final BiConsumer<JsonObjectWrapper, Skybox> deserializer;

private LegacyDeserializer(BiConsumer<JsonObjectWrapper, AbstractSkybox> deserializer, Class<T> clazz) {
private LegacyDeserializer(BiConsumer<JsonObjectWrapper, Skybox> deserializer, Class<T> clazz) {
this.deserializer = deserializer;
}

private static void decodeSquareTextured(JsonObjectWrapper wrapper, AbstractSkybox skybox) {
private static void decodeSquareTextured(JsonObjectWrapper wrapper, Skybox skybox) {
decodeSharedData(wrapper, skybox);
((SquareTexturedSkybox) skybox).rotation = new Rotation(true, new Vector3f(0f, 0f, 0f), new Vector3f(wrapper.getOptionalArrayFloat("axis", 0, 0), wrapper.getOptionalArrayFloat("axis", 1, 0), wrapper.getOptionalArrayFloat("axis", 2, 0)), new Vector3i(0, 0, 0), 0, 1, 0);
((SquareTexturedSkybox) skybox).blend = new Blend(wrapper.getOptionalBoolean("shouldBlend", false) ? "add" : "", Blender.DEFAULT);
Expand All @@ -43,14 +44,14 @@ private static void decodeSquareTextured(JsonObjectWrapper wrapper, AbstractSkyb
);
}

private static void decodeMonoColor(JsonObjectWrapper wrapper, AbstractSkybox skybox) {
private static void decodeMonoColor(JsonObjectWrapper wrapper, Skybox skybox) {
decodeSharedData(wrapper, skybox);
((MonoColorSkybox) skybox).color = new RGBA(wrapper.get("red").getAsFloat(), wrapper.get("green").getAsFloat(), wrapper.get("blue").getAsFloat());
}

private static void decodeSharedData(JsonObjectWrapper wrapper, AbstractSkybox skybox) {
private static void decodeSharedData(JsonObjectWrapper wrapper, Skybox skybox) {
float maxAlpha = wrapper.getOptionalFloat("maxAlpha", 1f);
skybox.properties = new Properties.Builder()
((AbstractSkybox) skybox).properties = new Properties.Builder()
.fade(new Fade(
wrapper.get("startFadeIn").getAsInt(),
wrapper.get("endFadeIn").getAsInt(),
Expand All @@ -69,31 +70,31 @@ private static void decodeSharedData(JsonObjectWrapper wrapper, AbstractSkybox s
))
.build();
// decorations
skybox.decorations = Decorations.DEFAULT;
((AbstractSkybox) skybox).decorations = Decorations.DEFAULT;
// environment specifications
JsonElement element;
element = wrapper.getOptionalValue("weather").orElse(null);
if (element != null) {
if (element.isJsonArray()) {
for (JsonElement jsonElement : element.getAsJsonArray()) {
skybox.conditions.getWeathers().add(Weather.fromString(jsonElement.getAsString()));
((AbstractSkybox) skybox).conditions.getWeathers().add(Weather.fromString(jsonElement.getAsString()));
}
} else if (JsonHelper.isString(element)) {
skybox.conditions.getWeathers().add(Weather.fromString(element.getAsString()));
((AbstractSkybox) skybox).conditions.getWeathers().add(Weather.fromString(element.getAsString()));
}
}
element = wrapper.getOptionalValue("biomes").orElse(null);
processIds(element, skybox.conditions.getBiomes());
processIds(element, ((AbstractSkybox) skybox).conditions.getBiomes());
element = wrapper.getOptionalValue("dimensions").orElse(null);
processIds(element, skybox.conditions.getWorlds());
processIds(element, ((AbstractSkybox) skybox).conditions.getWorlds());
element = wrapper.getOptionalValue("heightRanges").orElse(null);
if (element != null) {
JsonArray array = element.getAsJsonArray();
for (JsonElement jsonElement : array) {
JsonArray insideArray = jsonElement.getAsJsonArray();
float low = insideArray.get(0).getAsFloat();
float high = insideArray.get(1).getAsFloat();
skybox.conditions.getYRanges().add(new MinMaxEntry(low, high));
((AbstractSkybox) skybox).conditions.getYRanges().add(new MinMaxEntry(low, high));
}
}
}
Expand All @@ -110,11 +111,11 @@ private static void processIds(JsonElement element, List<Identifier> list) {
}
}

private static <T extends AbstractSkybox> LegacyDeserializer<T> register(LegacyDeserializer<T> deserializer, String name) {
private static <T extends Skybox> LegacyDeserializer<T> register(LegacyDeserializer<T> deserializer, String name) {
return Registry.register(LegacyDeserializer.REGISTRY, new Identifier(FabricSkyBoxesClient.MODID, name), deserializer);
}

public BiConsumer<JsonObjectWrapper, AbstractSkybox> getDeserializer() {
public BiConsumer<JsonObjectWrapper, Skybox> getDeserializer() {
return this.deserializer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.amerebagatelle.fabricskyboxes.api.skyboxes.Skybox;
import io.github.amerebagatelle.fabricskyboxes.mixin.skybox.WorldRendererAccess;
import io.github.amerebagatelle.fabricskyboxes.util.object.*;
import net.minecraft.client.render.*;
Expand Down Expand Up @@ -31,7 +32,7 @@ public MonoColorSkybox(Properties properties, Conditions conditions, Decorations
}

@Override
public SkyboxType<? extends AbstractSkybox> getType() {
public SkyboxType<? extends Skybox> getType() {
return SkyboxType.MONO_COLOR_SKYBOX;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.amerebagatelle.fabricskyboxes.SkyboxManager;
import io.github.amerebagatelle.fabricskyboxes.api.skyboxes.Skybox;
import io.github.amerebagatelle.fabricskyboxes.mixin.skybox.WorldRendererAccess;
import io.github.amerebagatelle.fabricskyboxes.util.object.Conditions;
import io.github.amerebagatelle.fabricskyboxes.util.object.Decorations;
Expand Down Expand Up @@ -31,7 +32,7 @@ public OverworldSkybox(Properties properties, Conditions conditions, Decorations
}

@Override
public SkyboxType<? extends AbstractSkybox> getType() {
public SkyboxType<? extends Skybox> getType() {
return SkyboxType.OVERWORLD_SKYBOX;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.Lifecycle;
import io.github.amerebagatelle.fabricskyboxes.FabricSkyBoxesClient;
import io.github.amerebagatelle.fabricskyboxes.api.skyboxes.Skybox;
import io.github.amerebagatelle.fabricskyboxes.skyboxes.textured.*;
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.minecraft.registry.Registry;
Expand All @@ -19,8 +20,8 @@
import java.util.function.Function;
import java.util.function.Supplier;

public class SkyboxType<T extends AbstractSkybox> {
public static final Registry<SkyboxType<? extends AbstractSkybox>> REGISTRY;
public class SkyboxType<T extends Skybox> {
public static final Registry<SkyboxType<? extends Skybox>> REGISTRY;
public static final SkyboxType<MonoColorSkybox> MONO_COLOR_SKYBOX;
public static final SkyboxType<OverworldSkybox> OVERWORLD_SKYBOX;
public static final SkyboxType<EndSkybox> END_SKYBOX;
Expand All @@ -32,7 +33,7 @@ public class SkyboxType<T extends AbstractSkybox> {
public static final Codec<Identifier> SKYBOX_ID_CODEC;

static {
REGISTRY = FabricRegistryBuilder.<SkyboxType<? extends AbstractSkybox>, SimpleRegistry<SkyboxType<? extends AbstractSkybox>>>from(new SimpleRegistry<>(RegistryKey.ofRegistry(new Identifier(FabricSkyBoxesClient.MODID, "skybox_type")), Lifecycle.stable())).buildAndRegister();
REGISTRY = FabricRegistryBuilder.<SkyboxType<? extends Skybox>, SimpleRegistry<SkyboxType<? extends Skybox>>>from(new SimpleRegistry<>(RegistryKey.ofRegistry(new Identifier(FabricSkyBoxesClient.MODID, "skybox_type")), Lifecycle.stable())).buildAndRegister();
MONO_COLOR_SKYBOX = register(SkyboxType.Builder.create(MonoColorSkybox.class, "monocolor").legacySupported().deserializer(LegacyDeserializer.MONO_COLOR_SKYBOX_DESERIALIZER).factory(MonoColorSkybox::new).add(2, MonoColorSkybox.CODEC).build());
OVERWORLD_SKYBOX = register(SkyboxType.Builder.create(OverworldSkybox.class, "overworld").add(2, OverworldSkybox.CODEC).build());
END_SKYBOX = register(SkyboxType.Builder.create(EndSkybox.class, "end").add(2, EndSkybox.CODEC).build());
Expand Down Expand Up @@ -75,7 +76,7 @@ public static void initRegistry() {
}
}

private static <T extends AbstractSkybox> SkyboxType<T> register(SkyboxType<T> type) {
private static <T extends Skybox> SkyboxType<T> register(SkyboxType<T> type) {
return Registry.register(SkyboxType.REGISTRY, type.createId(FabricSkyBoxesClient.MODID), type);
}

Expand Down Expand Up @@ -109,7 +110,7 @@ public Codec<T> getCodec(int schemaVersion) {
return Objects.requireNonNull(this.codecBiMap.get(schemaVersion), String.format("Unsupported schema version '%d' for skybox type %s", schemaVersion, this.name));
}

public static class Builder<T extends AbstractSkybox> {
public static class Builder<T extends Skybox> {
private final ImmutableBiMap.Builder<Integer, Codec<T>> builder = ImmutableBiMap.builder();
private String name;
private boolean legacySupported = false;
Expand All @@ -119,13 +120,13 @@ public static class Builder<T extends AbstractSkybox> {
private Builder() {
}

public static <S extends AbstractSkybox> Builder<S> create(@SuppressWarnings("unused") Class<S> clazz, String name) {
public static <S extends Skybox> Builder<S> create(@SuppressWarnings("unused") Class<S> clazz, String name) {
Builder<S> builder = new Builder<>();
builder.name = name;
return builder;
}

public static <S extends AbstractSkybox> Builder<S> create(String name) {
public static <S extends Skybox> Builder<S> create(String name) {
Builder<S> builder = new Builder<>();
builder.name = name;
return builder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.amerebagatelle.fabricskyboxes.api.skyboxes.Skybox;
import io.github.amerebagatelle.fabricskyboxes.mixin.skybox.WorldRendererAccess;
import io.github.amerebagatelle.fabricskyboxes.skyboxes.AbstractSkybox;
import io.github.amerebagatelle.fabricskyboxes.skyboxes.SkyboxType;
Expand Down Expand Up @@ -38,7 +39,7 @@ public AnimatedSquareTexturedSkybox(Properties properties, Conditions conditions
}

@Override
public SkyboxType<? extends AbstractSkybox> getType() {
public SkyboxType<? extends Skybox> getType() {
return SkyboxType.ANIMATED_SQUARE_TEXTURED_SKYBOX;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.amerebagatelle.fabricskyboxes.api.skyboxes.Skybox;
import io.github.amerebagatelle.fabricskyboxes.mixin.skybox.WorldRendererAccess;
import io.github.amerebagatelle.fabricskyboxes.skyboxes.AbstractSkybox;
import io.github.amerebagatelle.fabricskyboxes.skyboxes.SkyboxType;
Expand Down Expand Up @@ -45,7 +46,7 @@ public MultiTextureSkybox(Properties properties, Conditions conditions, Decorati
}

@Override
public SkyboxType<? extends AbstractSkybox> getType() {
public SkyboxType<? extends Skybox> getType() {
return SkyboxType.MULTI_TEXTURE_SKYBOX;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.amerebagatelle.fabricskyboxes.api.skyboxes.Skybox;
import io.github.amerebagatelle.fabricskyboxes.skyboxes.AbstractSkybox;
import io.github.amerebagatelle.fabricskyboxes.skyboxes.SkyboxType;
import io.github.amerebagatelle.fabricskyboxes.util.object.*;
Expand Down Expand Up @@ -38,7 +39,7 @@ public SingleSpriteAnimatedSquareTexturedSkybox(Properties properties, Condition
}

@Override
public SkyboxType<? extends AbstractSkybox> getType() {
public SkyboxType<? extends Skybox> getType() {
return SkyboxType.SINGLE_SPRITE_ANIMATED_SQUARE_TEXTURED_SKYBOX;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import io.github.amerebagatelle.fabricskyboxes.api.skyboxes.Skybox;
import io.github.amerebagatelle.fabricskyboxes.mixin.skybox.WorldRendererAccess;
import io.github.amerebagatelle.fabricskyboxes.skyboxes.AbstractSkybox;
import io.github.amerebagatelle.fabricskyboxes.skyboxes.SkyboxType;
Expand Down Expand Up @@ -38,7 +39,7 @@ public SingleSpriteSquareTexturedSkybox(Properties properties, Conditions condit
}

@Override
public SkyboxType<? extends AbstractSkybox> getType() {
public SkyboxType<? extends Skybox> getType() {
return SkyboxType.SINGLE_SPRITE_SQUARE_TEXTURED_SKYBOX;
}

Expand Down
Loading

0 comments on commit be9326a

Please sign in to comment.