Fix modded EntityClassifications not being useable in the codec. (#7337)

This commit is contained in:
Max Becker 2020-10-03 00:06:48 +02:00 committed by GitHub
parent 248d207dbc
commit 9177ac1b2e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 2 deletions

View file

@ -9,13 +9,28 @@
MONSTER("monster", 70, false, false, 128),
CREATURE("creature", 10, true, true, 128),
AMBIENT("ambient", 15, true, false, 128),
@@ -57,6 +57,10 @@
@@ -14,7 +14,7 @@
WATER_AMBIENT("water_ambient", 20, true, false, 64),
MISC("misc", -1, true, true, 128);
- public static final Codec<EntityClassification> field_233667_g_ = IStringSerializable.func_233023_a_(EntityClassification::values, EntityClassification::func_233670_a_);
+ public static final Codec<EntityClassification> field_233667_g_ = net.minecraftforge.common.IExtensibleEnum.createCodecForExtensibleEnum(EntityClassification::values, EntityClassification::func_233670_a_);
private static final Map<String, EntityClassification> field_220364_f = Arrays.stream(values()).collect(Collectors.toMap(EntityClassification::func_220363_a, (p_220362_0_) -> {
return p_220362_0_;
}));
@@ -57,6 +57,16 @@
return this.field_82707_i;
}
+ public static EntityClassification create(String name, String id, int maxNumberOfCreatureIn, boolean isPeacefulCreatureIn, boolean isAnimalIn, int despawnDistance) {
+ throw new IllegalStateException("Enum not extended");
+ }
+
+ @Override
+ @Deprecated
+ public void init() {
+ field_220364_f.put(this.func_220363_a(), this);
+ }
+
public int func_233671_f_() {
return this.field_233669_n_;

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/world/gen/feature/jigsaw/JigsawPattern.java
+++ b/net/minecraft/world/gen/feature/jigsaw/JigsawPattern.java
@@ -104,7 +104,7 @@
@@ -104,11 +104,11 @@
return this.field_214953_e.size();
}
@ -9,6 +9,11 @@
TERRAIN_MATCHING("terrain_matching", ImmutableList.of(new GravityStructureProcessor(Heightmap.Type.WORLD_SURFACE_WG, -1))),
RIGID("rigid", ImmutableList.of());
- public static final Codec<JigsawPattern.PlacementBehaviour> field_236858_c_ = IStringSerializable.func_233023_a_(JigsawPattern.PlacementBehaviour::values, JigsawPattern.PlacementBehaviour::func_214938_a);
+ public static final Codec<JigsawPattern.PlacementBehaviour> field_236858_c_ = net.minecraftforge.common.IExtensibleEnum.createCodecForExtensibleEnum(JigsawPattern.PlacementBehaviour::values, JigsawPattern.PlacementBehaviour::func_214938_a);
private static final Map<String, JigsawPattern.PlacementBehaviour> field_214939_c = Arrays.stream(values()).collect(Collectors.toMap(JigsawPattern.PlacementBehaviour::func_214936_a, (p_214935_0_) -> {
return p_214935_0_;
}));
@@ -135,5 +135,15 @@
public String func_176610_l() {
return this.field_214940_d;

View file

@ -19,6 +19,12 @@
package net.minecraftforge.common;
import com.mojang.serialization.Codec;
import net.minecraft.util.IStringSerializable;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* To be implemented on vanilla enums that should be enhanced with ASM to be
* extensible. If this is implemented on a class, the class must define a static
@ -47,4 +53,11 @@ public interface IExtensibleEnum
*/
@Deprecated
default void init() {}
/**
* Use this instead of {@link IStringSerializable#func_233023_a_(Supplier, Function)} for extensible enums because this not cache the enum values on construction
*/
static <E extends Enum<E> & IStringSerializable> Codec<E> createCodecForExtensibleEnum(Supplier<E[]> valuesSupplier, Function<? super String, ? extends E> enumValueFromNameFunction) {
return IStringSerializable.func_233024_a_(Enum::ordinal, (id) -> valuesSupplier.get()[id], enumValueFromNameFunction);
}
}