mirror of
https://github.com/GTMEGA/EndlessIDs.git
synced 2026-11-24 10:34:29 +00:00
Entity ID extension fixes
This commit is contained in:
3 files changed
+86
-2
No files matched your search
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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.mixin.helpers;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
public interface EntityRegistryAccessor {
|
||||
BitSet eids$availableIndicies();
|
||||
}
|
||||
+44
-1
@@ -24,18 +24,51 @@ 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 lombok.val;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@Mixin(EntityList.class)
|
||||
public abstract class EntityListMixin {
|
||||
@Shadow
|
||||
public static Map<Integer, Class<? extends Entity>> IDtoClassMapping;
|
||||
|
||||
@Inject(method = "<clinit>",
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ModifyConstant(method = "addMapping(Ljava/lang/Class;Ljava/lang/String;I)V",
|
||||
constant = @Constant(intValue = VanillaConstants.maxEntityID),
|
||||
@@ -43,4 +76,14 @@ public abstract class EntityListMixin {
|
||||
private static int extendRange(int constant) {
|
||||
return ExtendedConstants.maxEntityID;
|
||||
}
|
||||
|
||||
@Inject(method = "addMapping(Ljava/lang/Class;Ljava/lang/String;I)V",
|
||||
at = @At(value = "INVOKE",
|
||||
target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;",
|
||||
ordinal = 0),
|
||||
require = 1)
|
||||
private static void updateForgeIDMap(Class<? extends Entity> entityClass, String entityName, int id, CallbackInfo ci) {
|
||||
val availableIndicies = ((EntityRegistryAccessor) EntityRegistry.instance()).eids$availableIndicies();
|
||||
availableIndicies.clear(id);
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -24,6 +24,8 @@ 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 lombok.val;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
@@ -31,6 +33,7 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
|
||||
import net.minecraft.entity.EntityList;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.registry.EntityRegistry;
|
||||
@@ -39,9 +42,14 @@ import java.util.BitSet;
|
||||
|
||||
@Mixin(value = EntityRegistry.class,
|
||||
remap = false)
|
||||
public abstract class EntityRegistryMixin {
|
||||
public abstract class EntityRegistryMixin implements EntityRegistryAccessor {
|
||||
@Shadow private BitSet availableIndicies;
|
||||
|
||||
@Override
|
||||
public BitSet eids$availableIndicies() {
|
||||
return availableIndicies;
|
||||
}
|
||||
|
||||
@ModifyConstant(method = "<init>",
|
||||
constant = @Constant(intValue = VanillaConstants.entityIDCount),
|
||||
require = 1)
|
||||
@@ -62,6 +70,10 @@ public abstract class EntityRegistryMixin {
|
||||
*/
|
||||
@Overwrite
|
||||
private int validateAndClaimId(int id) {
|
||||
//Refresh available indices
|
||||
for (val key: EntityList.IDtoClassMapping.keySet()) {
|
||||
availableIndicies.clear(key);
|
||||
}
|
||||
//Keeping the legacy sub-0 id workaround here...
|
||||
|
||||
// workaround for broken ML
|
||||
|
||||
Reference in new issue
Block a user