From 93eb9344a351dce3c7643d7ee436f68684e03763 Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Fri, 16 Aug 2024 21:02:11 +0200 Subject: [PATCH] Move init() functions into static blocks --- .../fixes/data/EntityDimensionDiff.java | 2 -- .../EnchantmentAttributesEmulation1_20_6.java | 8 +++++++- .../versioned/visual/ArmorHudEmulation1_8.java | 8 +++++++- .../visual/FootStepParticle1_12_2.java | 18 ++++++++++++------ .../versioned/visual/UnicodeFontFix1_12_2.java | 6 +++++- .../viafabricplus/screen/VFPListEntry.java | 2 ++ 6 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/fixes/data/EntityDimensionDiff.java b/src/main/java/de/florianmichael/viafabricplus/fixes/data/EntityDimensionDiff.java index b2cef6b7..85de5b3b 100644 --- a/src/main/java/de/florianmichael/viafabricplus/fixes/data/EntityDimensionDiff.java +++ b/src/main/java/de/florianmichael/viafabricplus/fixes/data/EntityDimensionDiff.java @@ -21,7 +21,6 @@ package de.florianmichael.viafabricplus.fixes.data; import com.viaversion.viaversion.api.protocol.version.ProtocolVersion; import de.florianmichael.viafabricplus.event.ChangeProtocolVersionCallback; -import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator; import net.minecraft.client.MinecraftClient; import net.minecraft.entity.EntityAttachmentType; import net.minecraft.entity.EntityAttachments; @@ -29,7 +28,6 @@ import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityType; import net.raphimc.vialegacy.api.LegacyProtocolVersion; -import java.util.Collections; import java.util.Map; import static de.florianmichael.viafabricplus.util.MapUtil.linkedHashMap; diff --git a/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/EnchantmentAttributesEmulation1_20_6.java b/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/EnchantmentAttributesEmulation1_20_6.java index 3e62321f..ed4b7f2a 100644 --- a/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/EnchantmentAttributesEmulation1_20_6.java +++ b/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/EnchantmentAttributesEmulation1_20_6.java @@ -33,12 +33,14 @@ import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.registry.tag.BlockTags; +import org.jetbrains.annotations.ApiStatus; import java.util.Optional; +@ApiStatus.Internal public class EnchantmentAttributesEmulation1_20_6 { - public static void init() { + static { ClientTickEvents.START_WORLD_TICK.register(world -> { if (ProtocolTranslator.getTargetVersion().newerThan(ProtocolVersion.v1_20_5)) { return; @@ -69,6 +71,10 @@ public class EnchantmentAttributesEmulation1_20_6 { }); } + public static void init() { + // Calls the static block + } + /** * Called from MixinLivingEntity as well to ensure the attribute value is set at the correct place in the entity tick logic. * Called above just as a fallback if a mod accesses the raw attribute value directly. diff --git a/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/visual/ArmorHudEmulation1_8.java b/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/visual/ArmorHudEmulation1_8.java index 1e8d4ca4..59052ad7 100644 --- a/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/visual/ArmorHudEmulation1_8.java +++ b/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/visual/ArmorHudEmulation1_8.java @@ -32,16 +32,18 @@ import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; import net.minecraft.client.MinecraftClient; import net.minecraft.item.ItemStack; import net.minecraft.registry.Registries; +import org.jetbrains.annotations.ApiStatus; import java.util.UUID; +@ApiStatus.Internal public class ArmorHudEmulation1_8 { private static final UUID ARMOR_POINTS_UUID = UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150"); private static double previousArmorPoints = 0; - public static void init() { + static { ClientTickEvents.START_WORLD_TICK.register(world -> { if (!VisualSettings.global().emulateArmorHud.isEnabled()) { return; @@ -62,6 +64,10 @@ public class ArmorHudEmulation1_8 { }); } + public static void init() { + // Calls the static block + } + private static void sendArmorUpdate(final UserConnection userConnection) { // Calculate the armor points. int armor = 0; diff --git a/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/visual/FootStepParticle1_12_2.java b/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/visual/FootStepParticle1_12_2.java index 42c546dc..68620182 100644 --- a/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/visual/FootStepParticle1_12_2.java +++ b/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/visual/FootStepParticle1_12_2.java @@ -33,12 +33,23 @@ import net.minecraft.registry.Registry; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; +import org.jetbrains.annotations.ApiStatus; +@ApiStatus.Internal public class FootStepParticle1_12_2 extends SpriteBillboardParticle { public static final Identifier ID = Identifier.of("viafabricplus", "footstep"); public static int RAW_ID; + static { + final SimpleParticleType footStepType = FabricParticleTypes.simple(true); + + Registry.register(Registries.PARTICLE_TYPE, ID, footStepType); + ParticleFactoryRegistry.getInstance().register(footStepType, FootStepParticle1_12_2.Factory::new); + + RAW_ID = Registries.PARTICLE_TYPE.getRawId(footStepType); + } + protected FootStepParticle1_12_2(ClientWorld clientWorld, double x, double y, double z) { super(clientWorld, x, y, z); @@ -79,12 +90,7 @@ public class FootStepParticle1_12_2 extends SpriteBillboardParticle { } public static void init() { - final SimpleParticleType footStepType = FabricParticleTypes.simple(true); - - Registry.register(Registries.PARTICLE_TYPE, ID, footStepType); - ParticleFactoryRegistry.getInstance().register(footStepType, FootStepParticle1_12_2.Factory::new); - - RAW_ID = Registries.PARTICLE_TYPE.getRawId(footStepType); + // Calls the static block } public static class Factory implements ParticleFactory { diff --git a/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/visual/UnicodeFontFix1_12_2.java b/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/visual/UnicodeFontFix1_12_2.java index f82bdcdf..67b5dec5 100644 --- a/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/visual/UnicodeFontFix1_12_2.java +++ b/src/main/java/de/florianmichael/viafabricplus/fixes/versioned/visual/UnicodeFontFix1_12_2.java @@ -40,7 +40,7 @@ public class UnicodeFontFix1_12_2 { private static boolean enabled = false; private static Runnable task = null; - public static void init() { + static { ChangeProtocolVersionCallback.EVENT.register((oldVersion, newVersion) -> updateUnicodeFontOverride(newVersion)); ClientTickEvents.START_CLIENT_TICK.register(client -> { @@ -52,6 +52,10 @@ public class UnicodeFontFix1_12_2 { }); } + public static void init() { + // Calls the static block + } + public static void updateUnicodeFontOverride(final ProtocolVersion version) { final SimpleOption option = MinecraftClient.getInstance().options.getForceUnicodeFont(); diff --git a/src/main/java/de/florianmichael/viafabricplus/screen/VFPListEntry.java b/src/main/java/de/florianmichael/viafabricplus/screen/VFPListEntry.java index 59b813de..b389c009 100644 --- a/src/main/java/de/florianmichael/viafabricplus/screen/VFPListEntry.java +++ b/src/main/java/de/florianmichael/viafabricplus/screen/VFPListEntry.java @@ -45,9 +45,11 @@ public abstract class VFPListEntry extends AlwaysSelectedEntryListWidget.Entry