Skip to content

Commit

Permalink
Adds some changes for mixins, revises a bit of the caching, and provi…
Browse files Browse the repository at this point in the history
…des some context for clickable widgets. Tested with continuity as well to ensure compatibility
  • Loading branch information
AluTheCrow committed Sep 19, 2023
1 parent 7d7ffd1 commit 6389dd9
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 66 deletions.
38 changes: 0 additions & 38 deletions .github/build.yml

This file was deleted.

4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ org.gradle.parallel=true
loader_version=0.14.22
parchment_version=2023.06.26
# Mod Properties
mod_version = 0.1.5
mod_version = 0.1.65
maven_group = com.theomenden
archives_base_name = bismuth

Expand All @@ -17,4 +17,4 @@ org.gradle.parallel=true
sodium_version=mc1.19.4-0.4.10
cloth_version=10.1.105
modmenu_version=6.3.1
indium_version=1.0.25+mc1.20.1
indium_version=1.0.19+mc1.19.4
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

public class BismuthColorAdapter extends TypeAdapter<BismuthColor> {
@Override
public void write(JsonWriter jsonWriter, BismuthColor vanadiumColor) throws IOException {
if(vanadiumColor == null) {
public void write(JsonWriter jsonWriter, BismuthColor bismuthColor) throws IOException {
if(bismuthColor == null) {
jsonWriter.nullValue();
} else {
String hexValue = ColorConverter.rgbToHex(vanadiumColor.rgb());
String hexValue = ColorConverter.rgbToHex(bismuthColor.rgb());
jsonWriter.value(hexValue);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,13 @@ private static Map<EntityType<?>, int[]> collateSpawnEggColors(Settings settings
});
}

settings.spawnEgg.forEach((key, vanadiumColors) -> {
settings.spawnEgg.forEach((key, bismuthColors) -> {
EntityType<?> type = entityTypeRegistry.get(ResourceLocation.tryParse(key));
int[] colors = result.computeIfAbsent(type, t -> new int[2]);

IntStream
.range(0, Math.min(2, vanadiumColors.length))
.forEach(i -> colors[i] = vanadiumColors[i]
.range(0, Math.min(2, bismuthColors.length))
.forEach(i -> colors[i] = bismuthColors[i]
.rgb());
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.theomenden.bismuth.mixin.client;

import com.theomenden.bismuth.utils.BismuthColormaticResolution;
import net.minecraft.client.gui.components.AbstractButton;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.network.chat.Component;
import org.apache.commons.lang3.ObjectUtils;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

@Mixin(AbstractButton.class)
public abstract class ClickableWidgetMixin extends AbstractWidget{

public ClickableWidgetMixin(int x, int y, int width, int height, Component message) {
super(x, y, width, height, message);
}

@ModifyConstant(method="renderWidget", constant = @Constant(intValue = 16777215))
private int hoverColorProxy(int original) {
var hoverColors = ObjectUtils.firstNonNull(
BismuthColormaticResolution.COLORMATIC_COLOR_PROPERTIES,
BismuthColormaticResolution.COLOR_PROPERTIES
);

int hoverColor = hoverColors.getProperties().getHoveredButtonText();
return hoverColor != 0
&& this.isActive()
? hoverColor
: original;
}

@ModifyConstant(method="renderWidget", constant = @Constant(intValue = 10526880))
private int disabledColorProxy(int original) {
var hoverColors = ObjectUtils.firstNonNull(
BismuthColormaticResolution.COLORMATIC_COLOR_PROPERTIES,
BismuthColormaticResolution.COLOR_PROPERTIES
);

int disabledColor = hoverColors.getProperties().getDisabledButtonText();
return disabledColor != 0 ? disabledColor : original;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;

Expand All @@ -24,8 +25,14 @@ public abstract class SodiumGameOptionsPageMixin {
private static MinecraftOptionsStorage vanillaOpts;

@Inject(method = "quality",
at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/gui/options/OptionGroup;createBuilder()Lme/jellysquid/mods/sodium/client/gui/options/OptionGroup$Builder;", ordinal = 2, shift = At.Shift.AFTER),
locals = LocalCapture.CAPTURE_FAILSOFT, remap = false)
at = @At(
value = "INVOKE",
target = "Lme/jellysquid/mods/sodium/client/gui/options/OptionImpl;createBuilder(Ljava/lang/Class;Lme/jellysquid/mods/sodium/client/gui/options/storage/OptionStorage;)Lme/jellysquid/mods/sodium/client/gui/options/OptionImpl$Builder;",
ordinal = 2,
shift = At.Shift.AFTER
),
locals = LocalCapture.CAPTURE_FAILSOFT,
remap = false)
private static void quality(CallbackInfoReturnable<OptionPage> cir, List<OptionGroup> groups) {
groups.add(OptionGroup.createBuilder()
.add(OptionImpl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,97 @@
import com.google.common.collect.Lists;
import com.mojang.serialization.Lifecycle;
import lombok.Getter;
import net.fabricmc.fabric.impl.biome.modification.BuiltInRegistryKeys;
import net.minecraft.core.Holder;
import net.minecraft.core.MappedRegistry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.registries.VanillaRegistries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;

import java.util.List;
import java.util.Optional;

@Getter
public final class SimpleBiomeRegistryUtils {
@Getter
private static final List<ResourceKey<Biome>> BIOME_KEYS;
private static final List<ResourceKey<Biome>> BIOME_KEYS = Lists.newArrayList(
Biomes.OCEAN, Biomes.PLAINS, Biomes.DESERT, Biomes.WINDSWEPT_HILLS,
Biomes.FOREST, Biomes.TAIGA, Biomes.SWAMP, Biomes.RIVER,
Biomes.NETHER_WASTES, Biomes.THE_END, Biomes.FROZEN_OCEAN, Biomes.FROZEN_RIVER,
Biomes.SNOWY_PLAINS, Biomes.MUSHROOM_FIELDS, Biomes.BEACH, Biomes.JUNGLE,
Biomes.SPARSE_JUNGLE, Biomes.DEEP_OCEAN, Biomes.STONY_SHORE, Biomes.SNOWY_BEACH,
Biomes.BIRCH_FOREST, Biomes.DARK_FOREST, Biomes.SNOWY_TAIGA, Biomes.OLD_GROWTH_PINE_TAIGA,
Biomes.WINDSWEPT_FOREST, Biomes.SAVANNA, Biomes.SAVANNA_PLATEAU, Biomes.BADLANDS,
Biomes.WOODED_BADLANDS, Biomes.SMALL_END_ISLANDS, Biomes.END_MIDLANDS, Biomes.END_HIGHLANDS,
Biomes.END_BARRENS, Biomes.WARM_OCEAN,
Biomes.LUKEWARM_OCEAN, Biomes.COLD_OCEAN, Biomes.DEEP_LUKEWARM_OCEAN, Biomes.DEEP_COLD_OCEAN,
Biomes.DEEP_FROZEN_OCEAN, Biomes.THE_VOID, Biomes.SUNFLOWER_PLAINS, Biomes.WINDSWEPT_GRAVELLY_HILLS,
Biomes.FLOWER_FOREST, Biomes.ICE_SPIKES, Biomes.OLD_GROWTH_BIRCH_FOREST, Biomes.OLD_GROWTH_SPRUCE_TAIGA,
Biomes.WINDSWEPT_SAVANNA, Biomes.ERODED_BADLANDS, Biomes.BAMBOO_JUNGLE, Biomes.SOUL_SAND_VALLEY,
Biomes.CRIMSON_FOREST, Biomes.WARPED_FOREST, Biomes.BASALT_DELTAS, Biomes.DRIPSTONE_CAVES,
Biomes.LUSH_CAVES, Biomes.MEADOW, Biomes.GROVE, Biomes.SNOWY_SLOPES, Biomes.FROZEN_PEAKS,
Biomes.JAGGED_PEAKS, Biomes.STONY_PEAKS, Biomes.MANGROVE_SWAMP, Biomes.DEEP_DARK);

@Getter
private static final MappedRegistry<Biome> BUILT_IN_BIOMES;
private static final MappedRegistry<Biome> BUILT_IN_BIOMES = createBiomeMappedRegistry();

static {
BIOME_KEYS = Lists.newArrayList(
Biomes.OCEAN, Biomes.PLAINS, Biomes.DESERT, Biomes.WINDSWEPT_HILLS, Biomes.FOREST, Biomes.TAIGA, Biomes.SWAMP, Biomes.RIVER, Biomes.NETHER_WASTES, Biomes.THE_END, Biomes.FROZEN_OCEAN, Biomes.FROZEN_RIVER, Biomes.SNOWY_PLAINS, Biomes.MUSHROOM_FIELDS, Biomes.BEACH, Biomes.JUNGLE, Biomes.SPARSE_JUNGLE, Biomes.DEEP_OCEAN, Biomes.STONY_SHORE, Biomes.SNOWY_BEACH, Biomes.BIRCH_FOREST, Biomes.DARK_FOREST, Biomes.SNOWY_TAIGA, Biomes.OLD_GROWTH_PINE_TAIGA, Biomes.WINDSWEPT_FOREST, Biomes.SAVANNA, Biomes.SAVANNA_PLATEAU, Biomes.BADLANDS, Biomes.WOODED_BADLANDS, Biomes.SMALL_END_ISLANDS, Biomes.END_MIDLANDS, Biomes.END_HIGHLANDS, Biomes.END_BARRENS, Biomes.WARM_OCEAN, Biomes.LUKEWARM_OCEAN, Biomes.COLD_OCEAN, Biomes.DEEP_LUKEWARM_OCEAN, Biomes.DEEP_COLD_OCEAN, Biomes.DEEP_FROZEN_OCEAN, Biomes.THE_VOID, Biomes.SUNFLOWER_PLAINS, Biomes.WINDSWEPT_GRAVELLY_HILLS, Biomes.FLOWER_FOREST, Biomes.ICE_SPIKES, Biomes.OLD_GROWTH_BIRCH_FOREST, Biomes.OLD_GROWTH_SPRUCE_TAIGA, Biomes.WINDSWEPT_SAVANNA, Biomes.ERODED_BADLANDS, Biomes.BAMBOO_JUNGLE, Biomes.SOUL_SAND_VALLEY, Biomes.CRIMSON_FOREST, Biomes.WARPED_FOREST, Biomes.BASALT_DELTAS, Biomes.DRIPSTONE_CAVES, Biomes.LUSH_CAVES, Biomes.MEADOW, Biomes.GROVE, Biomes.SNOWY_SLOPES, Biomes.FROZEN_PEAKS, Biomes.JAGGED_PEAKS, Biomes.STONY_PEAKS, Biomes.MANGROVE_SWAMP, Biomes.DEEP_DARK);
}
private static MappedRegistry<Biome> createBiomeMappedRegistry() {
var result = new MappedRegistry<>(Registries.BIOME, Lifecycle.stable());

static {
var builtIn = VanillaRegistries
.createLookup()
.asGetterLookup()
.lookupOrThrow(Registries.BIOME);

var builtInBiomeRegistry = new MappedRegistry<>(Registries.BIOME, Lifecycle.stable());
var external = RegistryAccess
.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY)
.lookup(Registries.BIOME);

for (var biome: BIOME_KEYS) {
var biomeReference = builtIn.get(biome);
biomeReference.ifPresent(reference -> result.register(biome, reference
.value(), Lifecycle.stable()));
}

BIOME_KEYS
.forEach(
b -> builtInBiomeRegistry.register(b, builtIn.getOrThrow(b).value(), Lifecycle.stable())
);
if(external.isPresent()) {
for (var externalBiomeReference :
external.get().listElements().toList()) {
var externalBiome = externalBiomeReference.value();

BUILT_IN_BIOMES = builtInBiomeRegistry;
if(!result.containsKey(externalBiomeReference.key())) {
result.register(externalBiomeReference.key(), externalBiome, Lifecycle.stable());
}
}
}
return result;
}

private SimpleBiomeRegistryUtils(){}

public static int getBiomeRawId(ResourceKey<Biome> biomeRegistryKey) {

Biome lookedUpBiome =BUILT_IN_BIOMES
var lookedUpBiome = BUILT_IN_BIOMES
.createRegistrationLookup()
.getOrThrow(biomeRegistryKey)
.value();
.get(biomeRegistryKey);

if(lookedUpBiome.isEmpty()) {
lookedUpBiome = getBiome(biomeRegistryKey);
}

return getBiomeRawId(lookedUpBiome.orElseThrow()
.value());
}

private static Optional<Holder.Reference<Biome>> getBiome(ResourceKey<Biome> biomeResourceKey) {

return getBiomeRawId(lookedUpBiome);
return RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY)
.asGetterLookup()
.lookup(Registries.BIOME)
.orElseThrow()
.get(biomeResourceKey);
}

private static int getBiomeRawId(Biome biome) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/bismuth.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"client.ResourceLocationMixin",
"client.ChatStyleMixin",
"client.VideoSettingsScreenMixin",
"client.ClickableWidgetMixin",
"coloring.dye.DyeColorMixin",
"coloring.dye.SheepEntityMixin",
"coloring.TextureManagerMixin",
Expand Down

0 comments on commit 6389dd9

Please sign in to comment.