fix: Extract inner class from EntityListMixin

Closes: https://github.com/GTMEGA/EndlessIDs/issues/264
This commit is contained in:
FalsePattern committed 2025-09-25 19:14:07 +02:00
1 parent 860f2fb467
commit cb302ea1fa
2 files changed
+56 -18

No files matched your search

@@ -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<Integer, Class<? extends Entity>>(IDtoClassMapping) {
@Override
public Class<? extends Entity> put(Integer key, Class<? extends Entity> value) {
val availableIndicies = ((EntityRegistryAccessor) EntityRegistry.instance()).eids$availableIndicies();
availableIndicies.clear(key);
return super.put(key, value);
}
@Override
public void putAll(Map<? extends Integer, ? extends Class<? extends Entity>> 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",
@@ -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 <https://www.gnu.org/licenses/>.
*/
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<Integer, Class<? extends Entity>> {
public RemappingEntityIDMap(Map<Integer, Class<? extends Entity>> idToClassMapping) {
super(idToClassMapping);
}
@Override
public Class<? extends Entity> put(Integer key, Class<? extends Entity> value) {
val availableIndicies = ((EntityRegistryAccessor) EntityRegistry.instance()).eids$availableIndicies();
availableIndicies.clear(key);
return super.put(key, value);
}
@Override
public void putAll(Map<? extends Integer, ? extends Class<? extends Entity>> m) {
val availableIndicies = ((EntityRegistryAccessor) EntityRegistry.instance()).eids$availableIndicies();
for (val entry : m.entrySet()) {
availableIndicies.clear(entry.getKey());
}
super.putAll(m);
}
}