diff --git a/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/entity/vanilla/EntityListMixin.java b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/entity/vanilla/EntityListMixin.java index 34fd371..2ab65d9 100644 --- a/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/entity/vanilla/EntityListMixin.java +++ b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/entity/vanilla/EntityListMixin.java @@ -25,6 +25,7 @@ package com.falsepattern.endlessids.mixin.mixins.common.entity.vanilla; import com.falsepattern.endlessids.constants.ExtendedConstants; import com.falsepattern.endlessids.constants.VanillaConstants; import com.falsepattern.endlessids.mixin.helpers.EntityRegistryAccessor; +import com.falsepattern.endlessids.util.RemappingEntityIDMap; import lombok.val; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -38,7 +39,6 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.EntityList; import cpw.mods.fml.common.registry.EntityRegistry; -import java.util.HashMap; import java.util.Map; @@ -51,23 +51,7 @@ public abstract class EntityListMixin { at = @At(value = "RETURN"), require = 1) private static void hijackMap(CallbackInfo ci) { - IDtoClassMapping = new HashMap>(IDtoClassMapping) { - @Override - public Class put(Integer key, Class value) { - val availableIndicies = ((EntityRegistryAccessor) EntityRegistry.instance()).eids$availableIndicies(); - availableIndicies.clear(key); - return super.put(key, value); - } - - @Override - public void putAll(Map> m) { - val availableIndicies = ((EntityRegistryAccessor) EntityRegistry.instance()).eids$availableIndicies(); - for (val entry : m.entrySet()) { - availableIndicies.clear(entry.getKey()); - } - super.putAll(m); - } - }; + IDtoClassMapping = new RemappingEntityIDMap(IDtoClassMapping); } @ModifyConstant(method = "addMapping(Ljava/lang/Class;Ljava/lang/String;I)V", diff --git a/src/main/java/com/falsepattern/endlessids/util/RemappingEntityIDMap.java b/src/main/java/com/falsepattern/endlessids/util/RemappingEntityIDMap.java new file mode 100644 index 0000000..baeec60 --- /dev/null +++ b/src/main/java/com/falsepattern/endlessids/util/RemappingEntityIDMap.java @@ -0,0 +1,54 @@ +/* + * EndlessIDs + * + * Copyright (C) 2022-2025 FalsePattern, The MEGA Team + * All Rights Reserved + * + * The above copyright notice, this permission notice and the word "MEGA" + * shall be included in all copies or substantial portions of the Software. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, only version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.falsepattern.endlessids.util; + +import com.falsepattern.endlessids.mixin.helpers.EntityRegistryAccessor; +import lombok.val; + +import net.minecraft.entity.Entity; +import cpw.mods.fml.common.registry.EntityRegistry; + +import java.util.HashMap; +import java.util.Map; + +public class RemappingEntityIDMap extends HashMap> { + public RemappingEntityIDMap(Map> idToClassMapping) { + super(idToClassMapping); + } + + @Override + public Class put(Integer key, Class value) { + val availableIndicies = ((EntityRegistryAccessor) EntityRegistry.instance()).eids$availableIndicies(); + availableIndicies.clear(key); + return super.put(key, value); + } + + @Override + public void putAll(Map> m) { + val availableIndicies = ((EntityRegistryAccessor) EntityRegistry.instance()).eids$availableIndicies(); + for (val entry : m.entrySet()) { + availableIndicies.clear(entry.getKey()); + } + super.putAll(m); + } +}