Skip to content

Commit

Permalink
Move init() functions into static blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Aug 16, 2024
1 parent 0c6b92b commit 93eb934
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@

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;
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@
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;
Expand Down Expand Up @@ -69,6 +71,10 @@ public static void init() {
});
}

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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@
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;
Expand All @@ -62,6 +64,10 @@ public static void init() {
});
}

public static void init() {
// Calls the static block
}

private static void sendArmorUpdate(final UserConnection userConnection) {
// Calculate the armor points.
int armor = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,23 @@
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);

Expand Down Expand Up @@ -79,12 +90,7 @@ public void buildGeometry(VertexConsumer vertexConsumer, Camera camera, float ti
}

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<SimpleParticleType> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand All @@ -52,6 +52,10 @@ public static void init() {
});
}

public static void init() {
// Calls the static block
}

public static void updateUnicodeFontOverride(final ProtocolVersion version) {
final SimpleOption<Boolean> option = MinecraftClient.getInstance().options.getForceUnicodeFont();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public abstract class VFPListEntry extends AlwaysSelectedEntryListWidget.Entry<V
private int entryHeight;

public void mappedRender(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
// To be overridden
}

public void mappedMouseClicked(double mouseX, double mouseY, int button) {
// To be overridden
}

/**
Expand Down

0 comments on commit 93eb934

Please sign in to comment.