Skip to content

Commit

Permalink
Move all extensible enums and their usages to data-driven enum extension
Browse files Browse the repository at this point in the history
  • Loading branch information
XFactHD committed Jun 12, 2024
1 parent f9eb6d9 commit 0e84d40
Show file tree
Hide file tree
Showing 34 changed files with 647 additions and 424 deletions.
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ jetbrains_annotations_version=24.0.1
slf4j_api_version=2.0.7
apache_maven_artifact_version=3.8.5
jarjar_version=0.4.1
fancy_mod_loader_version=3.0.45
fancy_mod_loader_version=4.0.2
mojang_logging_version=1.1.1
log4j_version=2.22.1
guava_version=31.1.2-jre
gson_version=2.10.1
apache_commons_lang3_version=3.13.0
jopt_simple_version=5.0.4
commons_io_version=2.13.0
unsafe_version=0.2.+
typetools_version=0.6.3
nashorn_core_version=15.3
lwjgl_glfw_version=3.3.2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
@OnlyIn(Dist.CLIENT)
public static enum Type {
FLOAT(4, "Float", 5126),
@@ -113,7 +_,7 @@
@@ -113,7 +_,8 @@
}

@OnlyIn(Dist.CLIENT)
- public static enum Usage {
+ public static enum Usage implements net.neoforged.neoforge.common.IExtensibleEnum {
+ @net.neoforged.fml.common.asm.enumextension.NamedEnum
+ public static enum Usage implements net.neoforged.fml.common.asm.enumextension.IExtensibleEnum {
POSITION(
"Position",
(p_349733_, p_349734_, p_349735_, p_349736_, p_349737_) -> GlStateManager._vertexAttribPointer(
Expand All @@ -31,8 +32,8 @@
void setupBufferState(int p_167053_, int p_167054_, int p_167055_, long p_167056_, int p_167057_);
+ }
+
+ public static Usage create(String name, String usageName, SetupState setupState) {
+ throw new IllegalArgumentException("Enum not extended");
+ public static net.neoforged.fml.common.asm.enumextension.ExtensionInfo getExtensionInfo() {
+ return net.neoforged.fml.common.asm.enumextension.ExtensionInfo.nonExtended(VertexFormatElement.Usage.class);
}
}
}
24 changes: 19 additions & 5 deletions patches/net/minecraft/client/RecipeBookCategories.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

@OnlyIn(Dist.CLIENT)
-public enum RecipeBookCategories {
+public enum RecipeBookCategories implements net.neoforged.neoforge.common.IExtensibleEnum {
+public enum RecipeBookCategories implements net.neoforged.fml.common.asm.enumextension.IExtensibleEnum {
CRAFTING_SEARCH(new ItemStack(Items.COMPASS)),
CRAFTING_BUILDING_BLOCKS(new ItemStack(Blocks.BRICKS)),
CRAFTING_REDSTONE(new ItemStack(Items.REDSTONE)),
@@ -38,16 +_,7 @@
@@ -38,20 +_,20 @@
public static final List<RecipeBookCategories> CRAFTING_CATEGORIES = ImmutableList.of(
CRAFTING_SEARCH, CRAFTING_EQUIPMENT, CRAFTING_BUILDING_BLOCKS, CRAFTING_MISC, CRAFTING_REDSTONE
);
Expand All @@ -24,9 +24,22 @@
- ImmutableList.of(SMOKER_FOOD)
- );
+ public static final Map<RecipeBookCategories, List<RecipeBookCategories>> AGGREGATE_CATEGORIES = net.neoforged.neoforge.client.RecipeBookManager.getAggregateCategories();
+ @Deprecated // Neo: Empty for custom categories. Use the getter.
private final List<ItemStack> itemIcons;
+ private final java.util.function.Supplier<List<ItemStack>> itemIconsSupplier;

+ @net.neoforged.fml.common.asm.enumextension.ReservedConstructor
private RecipeBookCategories(ItemStack... p_92267_) {
this.itemIcons = ImmutableList.copyOf(p_92267_);
+ this.itemIconsSupplier = () -> this.itemIcons;
+ }
+
+ private RecipeBookCategories(java.util.function.Supplier<List<ItemStack>> itemIconsSupplier) {
+ this.itemIcons = List.of();
+ this.itemIconsSupplier = itemIconsSupplier;
}

public static List<RecipeBookCategories> getCategories(RecipeBookType p_92270_) {
@@ -60,10 +_,15 @@
case FURNACE -> FURNACE_CATEGORIES;
case BLAST_FURNACE -> BLAST_FURNACE_CATEGORIES;
Expand All @@ -36,10 +49,11 @@
}

public List<ItemStack> getIconItems() {
return this.itemIcons;
- return this.itemIcons;
+ return this.itemIconsSupplier.get();
+ }
+
+ public static RecipeBookCategories create(String name, ItemStack... icons) {
+ throw new IllegalStateException("Enum not extended");
+ public static net.neoforged.fml.common.asm.enumextension.ExtensionInfo getExtensionInfo() {
+ return net.neoforged.fml.common.asm.enumextension.ExtensionInfo.nonExtended(RecipeBookCategories.class);
}
}
18 changes: 4 additions & 14 deletions patches/net/minecraft/client/gui/Gui.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,11 @@
+
@OnlyIn(Dist.CLIENT)
- public static enum HeartType {
+ public static enum HeartType implements net.neoforged.neoforge.common.IExtensibleEnum {
+ public static enum HeartType implements net.neoforged.fml.common.asm.enumextension.IExtensibleEnum {
CONTAINER(
ResourceLocation.withDefaultNamespace("hud/heart/container"),
ResourceLocation.withDefaultNamespace("hud/heart/container_blinking"),
@@ -1409,8 +_,23 @@
@@ -1409,8 +_,13 @@
} else {
gui$hearttype = NORMAL;
}
Expand All @@ -394,18 +394,8 @@
return gui$hearttype;
+ }
+
+ public static HeartType create(
+ String name,
+ ResourceLocation full,
+ ResourceLocation fullBlinking,
+ ResourceLocation half,
+ ResourceLocation halfBlinking,
+ ResourceLocation hardcoreFull,
+ ResourceLocation hardcoreFullBlinking,
+ ResourceLocation hardcoreHalf,
+ ResourceLocation hardcoreHalfBlinking
+ ) {
+ throw new IllegalStateException("Enum not extended");
+ public static net.neoforged.fml.common.asm.enumextension.ExtensionInfo getExtensionInfo() {
+ return net.neoforged.fml.common.asm.enumextension.ExtensionInfo.nonExtended(Gui.HeartType.class);
}
}
}
34 changes: 18 additions & 16 deletions patches/net/minecraft/client/model/HumanoidModel.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,39 @@

@OnlyIn(Dist.CLIENT)
- public static enum ArmPose {
+ public static enum ArmPose implements net.neoforged.neoforge.common.IExtensibleEnum {
+ public static enum ArmPose implements net.neoforged.fml.common.asm.enumextension.IExtensibleEnum {
EMPTY(false),
ITEM(false),
BLOCK(false),
@@ -462,10 +_,29 @@
@@ -459,13 +_,31 @@
BRUSH(false);

private final boolean twoHanded;
+ @org.jetbrains.annotations.Nullable
+ private final net.neoforged.neoforge.client.IArmPoseTransformer forgeArmPose;

+ @net.neoforged.fml.common.asm.enumextension.ReservedConstructor
private ArmPose(boolean p_102896_) {
this.twoHanded = p_102896_;
+ this.forgeArmPose = null;
}

public boolean isTwoHanded() {
return this.twoHanded;
}
+ // FORGE START
+ @org.jetbrains.annotations.Nullable
+ private final net.neoforged.neoforge.client.IArmPoseTransformer forgeArmPose;
+ }
+
+ private ArmPose(boolean twoHanded, @javax.annotation.Nonnull net.neoforged.neoforge.client.IArmPoseTransformer forgeArmPose) {
+ private ArmPose(boolean twoHanded, net.neoforged.neoforge.client.IArmPoseTransformer forgeArmPose) {
+ this.twoHanded = twoHanded;
+ com.google.common.base.Preconditions.checkNotNull(forgeArmPose, "Cannot create new ArmPose with null transformer!");
+ this.forgeArmPose = forgeArmPose;
+ }
+
+ public static ArmPose create(String name, boolean twoHanded, @javax.annotation.Nonnull net.neoforged.neoforge.client.IArmPoseTransformer forgeArmPose) {
+ throw new IllegalStateException("Enum not extended");
}
public boolean isTwoHanded() {
return this.twoHanded;
+ }
+
+ public <T extends LivingEntity> void applyTransform(HumanoidModel<T> model, T entity, net.minecraft.world.entity.HumanoidArm arm) {
+ if (this.forgeArmPose != null) this.forgeArmPose.applyTransform(model, entity, arm);
+ }
+ // FORGE END
+
+ public static net.neoforged.fml.common.asm.enumextension.ExtensionInfo getExtensionInfo() {
+ return net.neoforged.fml.common.asm.enumextension.ExtensionInfo.nonExtended(HumanoidModel.ArmPose.class);
}
}
}
47 changes: 17 additions & 30 deletions patches/net/minecraft/world/damagesource/DamageEffects.java.patch
Original file line number Diff line number Diff line change
@@ -1,60 +1,47 @@
--- a/net/minecraft/world/damagesource/DamageEffects.java
+++ b/net/minecraft/world/damagesource/DamageEffects.java
@@ -5,7 +_,7 @@
@@ -5,7 +_,9 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.StringRepresentable;

-public enum DamageEffects implements StringRepresentable {
+public enum DamageEffects implements StringRepresentable, net.neoforged.neoforge.common.IExtensibleEnum {
+@net.neoforged.fml.common.asm.enumextension.NamedEnum
+@net.neoforged.fml.common.asm.enumextension.NetworkedEnum(net.neoforged.fml.common.asm.enumextension.NetworkedEnum.NetworkCheck.CLIENTBOUND)
+public enum DamageEffects implements StringRepresentable, net.neoforged.fml.common.asm.enumextension.IExtensibleEnum {
HURT("hurt", SoundEvents.PLAYER_HURT),
THORNS("thorns", SoundEvents.THORNS_HIT),
DROWNING("drowning", SoundEvents.PLAYER_HURT_DROWN),
@@ -13,13 +_,13 @@
POKING("poking", SoundEvents.PLAYER_HURT_SWEET_BERRY_BUSH),
FREEZING("freezing", SoundEvents.PLAYER_HURT_FREEZE);
@@ -15,11 +_,19 @@

- public static final Codec<DamageEffects> CODEC = StringRepresentable.fromEnum(DamageEffects::values);
+ public static final Codec<DamageEffects> CODEC = Codec.lazyInitialized(() -> StringRepresentable.fromEnum(DamageEffects::values));
public static final Codec<DamageEffects> CODEC = StringRepresentable.fromEnum(DamageEffects::values);
private final String id;
+ @Deprecated // Neo: Always set to null. Use the getter.
private final SoundEvent sound;
+ private final java.util.function.Supplier<SoundEvent> soundSupplier;

+ @net.neoforged.fml.common.asm.enumextension.ReservedConstructor
private DamageEffects(String p_270875_, SoundEvent p_270383_) {
- this.id = p_270875_;
- this.sound = p_270383_;
+ this(p_270875_, () -> p_270383_);
+ }
+
+ private DamageEffects(String id, java.util.function.Supplier<SoundEvent> sound) {
+ this.id = id;
+ this.soundSupplier = sound;
+ this.sound = null;
}

@Override
@@ -28,6 +_,30 @@
@@ -28,6 +_,10 @@
}

public SoundEvent sound() {
- return this.sound;
+ return this.soundSupplier.get();
+ }
+
+ private final java.util.function.Supplier<SoundEvent> soundSupplier;
+
+ private DamageEffects(String id, java.util.function.Supplier<SoundEvent> sound) {
+ this.id = id;
+ this.soundSupplier = sound;
+ this.sound = null;
+ }
+
+ /**
+ * Creates a new DamageEffects with the specified ID and sound.<br>
+ * Example usage:
+ * <code><pre>
+ * public static final DamageEffects ELECTRIFYING = DamageEffects.create("MYMOD_ELECTRIFYING", "mymod:electrifying", MySounds.ELECTRIFYING);
+ * </pre></code>
+ * @param name The {@linkplain Enum#name() true enum name}. Prefix this with your modid.
+ * @param id The {@linkplain StringRepresentable#getSerializedName() serialized name}. Prefix this with your modid and `:`
+ * @param sound The sound event that will play when a damage type with this effect deals damage to a player.
+ * @return A newly created DamageEffects. Store this result in a static final field.
+ * @apiNote This method must be called as early as possible, as if {@link #CODEC} is resolved before this is called, it will be unusable.
+ */
+ public static DamageEffects create(String name, String id, java.util.function.Supplier<SoundEvent> sound) {
+ throw new IllegalStateException("Enum not extended");
+ public static net.neoforged.fml.common.asm.enumextension.ExtensionInfo getExtensionInfo() {
+ return net.neoforged.fml.common.asm.enumextension.ExtensionInfo.nonExtended(DamageEffects.class);
}
}
39 changes: 14 additions & 25 deletions patches/net/minecraft/world/damagesource/DamageScaling.java.patch
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
--- a/net/minecraft/world/damagesource/DamageScaling.java
+++ b/net/minecraft/world/damagesource/DamageScaling.java
@@ -3,20 +_,51 @@
@@ -3,20 +_,41 @@
import com.mojang.serialization.Codec;
import net.minecraft.util.StringRepresentable;

-public enum DamageScaling implements StringRepresentable {
+public enum DamageScaling implements StringRepresentable, net.neoforged.neoforge.common.IExtensibleEnum {
+@net.neoforged.fml.common.asm.enumextension.NamedEnum
+@net.neoforged.fml.common.asm.enumextension.NetworkedEnum(net.neoforged.fml.common.asm.enumextension.NetworkedEnum.NetworkCheck.CLIENTBOUND)
+public enum DamageScaling implements StringRepresentable, net.neoforged.fml.common.asm.enumextension.IExtensibleEnum {
NEVER("never"),
WHEN_CAUSED_BY_LIVING_NON_PLAYER("when_caused_by_living_non_player"),
ALWAYS("always");

- public static final Codec<DamageScaling> CODEC = StringRepresentable.fromEnum(DamageScaling::values);
+ public static final Codec<DamageScaling> CODEC = Codec.lazyInitialized(() -> StringRepresentable.fromEnum(DamageScaling::values));
public static final Codec<DamageScaling> CODEC = StringRepresentable.fromEnum(DamageScaling::values);
private final String id;
+ private final net.neoforged.neoforge.common.damagesource.IScalingFunction scaling;

+ @net.neoforged.fml.common.asm.enumextension.ReservedConstructor
private DamageScaling(String p_270266_) {
- this.id = p_270266_;
+ this(p_270266_, net.neoforged.neoforge.common.damagesource.IScalingFunction.DEFAULT);
}

@Override
public String getSerializedName() {
return this.id;
+ }
+
+ private final net.neoforged.neoforge.common.damagesource.IScalingFunction scaling;
+
+ private DamageScaling(String id, net.neoforged.neoforge.common.damagesource.IScalingFunction scaling) {
+ this.id = id;
+ this.scaling = scaling;
}

@Override
public String getSerializedName() {
return this.id;
+ }
+
+ /**
Expand All @@ -39,19 +40,7 @@
+ return this.scaling;
+ }
+
+ /**
+ * Creates a new DamageScaling with the specified ID and scaling function.<br>
+ * Example usage:
+ * <code><pre>
+ * public static final DamageScaling CUSTOM_SCALING = DamageEffects.create("MYMOD_CUSTOM", "mymod:custom", MyMod.CUSTOM_SCALING_FUNCTION);
+ * </pre></code>
+ * @param name The {@linkplain Enum#name() true enum name}. Prefix this with your modid.
+ * @param id The {@linkplain StringRepresentable#getSerializedName() serialized name}. Prefix this with your modid and `:`
+ * @param scaling The scaling function that will be used when a player is hurt by a damage type with this type of scaling.
+ * @return A newly created DamageScaling. Store this result in a static final field.
+ * @apiNote This method must be called as early as possible, as if {@link #CODEC} is resolved before this is called, it will be unusable.
+ */
+ public static DamageScaling create(String name, String id, net.neoforged.neoforge.common.damagesource.IScalingFunction scaling) {
+ throw new IllegalStateException("Enum not extended");
+ public static net.neoforged.fml.common.asm.enumextension.ExtensionInfo getExtensionInfo() {
+ return net.neoforged.fml.common.asm.enumextension.ExtensionInfo.nonExtended(DamageScaling.class);
}
}
Loading

0 comments on commit 0e84d40

Please sign in to comment.