From 441ece67bd67af2927fe480fb2204c41764c568f Mon Sep 17 00:00:00 2001 From: kashike Date: Sat, 16 Dec 2017 18:01:58 -0800 Subject: [PATCH] Delay egg creation to avoid null statistics (#4508) --- .../minecraft/entity/EntityList.java.patch | 17 +++++++++++++ .../common/registry/EntityEntryBuilder.java | 24 +++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/patches/minecraft/net/minecraft/entity/EntityList.java.patch b/patches/minecraft/net/minecraft/entity/EntityList.java.patch index 05ba260c4d..a3d820b6f8 100644 --- a/patches/minecraft/net/minecraft/entity/EntityList.java.patch +++ b/patches/minecraft/net/minecraft/entity/EntityList.java.patch @@ -164,3 +164,20 @@ } public static class EntityEggInfo +@@ -428,5 +449,16 @@ + this.field_151512_d = StatList.func_151182_a(this); + this.field_151513_e = StatList.func_151176_b(this); + } ++ ++ // Forge start ++ public EntityEggInfo(ResourceLocation id, int primaryColor, int secondaryColor, StatBase killEntityStatistic, StatBase entityKilledByStatistic) ++ { ++ this.field_75613_a = id; ++ this.field_75611_b = primaryColor; ++ this.field_75612_c = secondaryColor; ++ this.field_151512_d = killEntityStatistic; ++ this.field_151513_e = entityKilledByStatistic; ++ } ++ // Forge end + } + } diff --git a/src/main/java/net/minecraftforge/fml/common/registry/EntityEntryBuilder.java b/src/main/java/net/minecraftforge/fml/common/registry/EntityEntryBuilder.java index 0ddb90e20c..7e736a90d2 100644 --- a/src/main/java/net/minecraftforge/fml/common/registry/EntityEntryBuilder.java +++ b/src/main/java/net/minecraftforge/fml/common/registry/EntityEntryBuilder.java @@ -22,7 +22,9 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EnumCreatureType; +import net.minecraft.stats.StatBase; import net.minecraft.util.ResourceLocation; +import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; import net.minecraftforge.fml.common.FMLLog; @@ -64,6 +66,9 @@ public final class EntityEntryBuilder private boolean eggProvided; private int primaryEggColor; private int secondaryEggColor; + private boolean statisticsRegistered; + @Nullable private StatBase killEntityStatistic; + @Nullable private StatBase entityKilledByStatistic; @Nullable private Collection spawns; /** @@ -262,7 +267,12 @@ public final class EntityEntryBuilder } }; entry.setRegistryName(this.id); - if (this.eggProvided) entry.setEgg(new EntityList.EntityEggInfo(this.id, this.primaryEggColor, this.secondaryEggColor)); + if (this.eggProvided) + { + this.killEntityStatistic = new StatBase("stat.killEntity." + this.name, new TextComponentTranslation("stat.entityKill", new TextComponentTranslation("entity." + this.name + ".name"))); + this.entityKilledByStatistic = new StatBase("stat.entityKilledBy." + this.name, new TextComponentTranslation("stat.entityKilledBy", new TextComponentTranslation("entity." + this.name + ".name"))); + entry.setEgg(new EntityList.EntityEggInfo(this.id, this.primaryEggColor, this.secondaryEggColor, this.killEntityStatistic, this.entityKilledByStatistic)); + } return entry; } @@ -275,6 +285,16 @@ public final class EntityEntryBuilder ); } + private void registerStatistics() + { + if (!this.statisticsRegistered && (this.killEntityStatistic != null && this.entityKilledByStatistic != null)) + { + this.killEntityStatistic.registerStat(); + this.entityKilledByStatistic.registerStat(); + this.statisticsRegistered = true; + } + } + static abstract class ConstructorFactory implements Function { private final Constructor constructor; @@ -315,11 +335,11 @@ public final class EntityEntryBuilder // NOOP - we handle this in build } - @SuppressWarnings("ConstantConditions") public final void addedToRegistry() { if (this.added) return; this.added = true; + EntityEntryBuilder.this.registerStatistics(); EntityRegistry.instance().insert(EntityEntryBuilder.this.entity, EntityEntryBuilder.this.createRegistration()); if (EntityEntryBuilder.this.spawns != null) {