diff --git a/README.MD b/README.MD index e9bf194..c38bdbe 100644 --- a/README.MD +++ b/README.MD @@ -8,16 +8,16 @@ new limits. Comparison of the known limits: -| | Vanilla | NotEnoughIDs | EndlessIDs | -|-----------------|----------------------------------------------------|--------------|----------------------------------| -| Block IDs | 4,096 | 32,000 | 16,777,216 since 1.3 | -| Block Metadata | 16 | 16 | 65,536 since 1.5 | -| Item IDs | 32,000 | 32,000 | 16,777,216 since 1.3 | -| Biome IDs | 256 | 256 | 65,536 since 1.4 | -| Entity IDs | 256 | 256 | 256 right now, extension planned | -| Potion IDs | 32 | 32 | 65,536 since 1.5 | -| Enchantment IDs | 256 | 256 | 32,768 since 1.5 | -| Dimension IDs | Theoretically unlimited, 4,294,967,295 in practice | Same | Same | +| | Vanilla | NotEnoughIDs | EndlessIDs | +|-----------------|----------------------------------------------------|--------------|----------------------| +| Block IDs | 4,096 | 32,000 | 16,777,216 since 1.3 | +| Block Metadata | 16 | 16 | 65,536 since 1.5 | +| Item IDs | 32,000 | 32,000 | 16,777,216 since 1.3 | +| Biome IDs | 256 | 256 | 65,536 since 1.4 | +| Entity IDs | 256 | 256 | 32,768 since 1.5 | +| Potion IDs | 32 | 32 | 65,536 since 1.5 | +| Enchantment IDs | 256 | 256 | 32,768 since 1.5 | +| Dimension IDs | Theoretically unlimited, 4,294,967,295 in practice | Same | Same | This mod also contains patches for the following mods: diff --git a/src/main/java/com/falsepattern/endlessids/config/GeneralConfig.java b/src/main/java/com/falsepattern/endlessids/config/GeneralConfig.java index 684557f..29425e1 100644 --- a/src/main/java/com/falsepattern/endlessids/config/GeneralConfig.java +++ b/src/main/java/com/falsepattern/endlessids/config/GeneralConfig.java @@ -38,6 +38,9 @@ public class GeneralConfig { @Config.Comment("Extend Potion IDs. Vanilla limit is 32, new limit is 65536.") @Config.DefaultBoolean(true) public static boolean extendPotion; + @Config.Comment("Extend Entity IDs. Vanilla limit is 256, new limit is 32768.") + @Config.DefaultBoolean(true) + public static boolean extendEntity; @Config.Comment("Improves the speed of the block registry by multiple orders of magnitudes. (not thoroughly tested yet)\n" + "It's highly recommended to leave this enabled, especially when using a lot of IDs.\n" + diff --git a/src/main/java/com/falsepattern/endlessids/constants/ExtendedConstants.java b/src/main/java/com/falsepattern/endlessids/constants/ExtendedConstants.java index 01019c8..1c73c80 100644 --- a/src/main/java/com/falsepattern/endlessids/constants/ExtendedConstants.java +++ b/src/main/java/com/falsepattern/endlessids/constants/ExtendedConstants.java @@ -16,6 +16,9 @@ public class ExtendedConstants { public static final int maximumPotionIDs = 65536; public static final int maximumEnchantmentIDs = 32768; + //Align with max item metadata for spawn eggs. Will be treated as short in netcode + public static final int bitsPerEntity = 15; + //BlockItemIDs public static final int nibblesPerID = bitsPerID / 4; public static final int bytesPerID = (nibblesPerID + 1) / 2; @@ -44,4 +47,9 @@ public class ExtendedConstants { public static final int watchableCount = 1 << watchableBits; public static final int maxWatchableID = watchableCount - 1; public static final int watchableMask = (0x7 << watchableBits) | maxWatchableID; + + //EntityIDs + public static final int entityIDCount = 1 << bitsPerEntity; + public static final int entityIDMask = entityIDCount - 1; + public static final int maxEntityID = entityIDMask; } diff --git a/src/main/java/com/falsepattern/endlessids/constants/VanillaConstants.java b/src/main/java/com/falsepattern/endlessids/constants/VanillaConstants.java index d6ee2cd..0a05622 100644 --- a/src/main/java/com/falsepattern/endlessids/constants/VanillaConstants.java +++ b/src/main/java/com/falsepattern/endlessids/constants/VanillaConstants.java @@ -10,6 +10,8 @@ public class VanillaConstants { public static final int watchableBits = 5; public static final int bitsPerBiome = 8; + public static final int bitsPerEntity = 8; + //BlockItemIDs public static final int nibblesPerID = bitsPerID / 4; public static final int bytesPerID = (nibblesPerID + 1) / 2; @@ -38,4 +40,8 @@ public class VanillaConstants { public static final int watchableCount = 1 << watchableBits; public static final int maxWatchableID = watchableCount - 1; public static final int watchableMask = (0x7 << watchableBits) | maxWatchableID; + + //EntityIDs + public static final int entityIDCount = 1 << bitsPerEntity; + public static final int maxEntityID = entityIDCount - 1; } 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 new file mode 100644 index 0000000..abe100e --- /dev/null +++ b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/entity/vanilla/EntityListMixin.java @@ -0,0 +1,49 @@ +package com.falsepattern.endlessids.mixin.mixins.common.entity.vanilla; + +import com.falsepattern.endlessids.constants.ExtendedConstants; +import com.falsepattern.endlessids.constants.VanillaConstants; +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.ModifyConstant; +import org.spongepowered.asm.mixin.injection.Redirect; + +import net.minecraft.entity.EntityList; + + +@Mixin(EntityList.class) +public abstract class EntityListMixin { + @Shadow + public static void addMapping(Class p_75618_0_, String p_75618_1_, int p_75618_2_) { + } + + @Shadow + public static void addMapping(Class p_75614_0_, String p_75614_1_, int p_75614_2_, int p_75614_3_, int p_75614_4_) { + + } + + @ModifyConstant(method = "addMapping(Ljava/lang/Class;Ljava/lang/String;I)V", + constant = @Constant(intValue = VanillaConstants.maxEntityID), + require = 1) + private static int extendRange(int constant) { + return ExtendedConstants.maxEntityID; + } + + @Redirect(method = "", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/entity/EntityList;addMapping(Ljava/lang/Class;Ljava/lang/String;I)V"), + require = 1) + private static void messUpMappings1(Class p_75618_0_, String p_75618_1_, int p_75618_2_) { + addMapping(p_75618_0_, p_75618_1_, p_75618_2_ * 100); + } + + + @Redirect(method = "", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/entity/EntityList;addMapping(Ljava/lang/Class;Ljava/lang/String;III)V"), + require = 1) + private static void messUpMappings2(Class p_75614_0_, String p_75614_1_, int p_75614_2_, int p_75614_3_, int p_75614_4_) { + addMapping(p_75614_0_, p_75614_1_, p_75614_2_ * 100, p_75614_3_, p_75614_4_); + } +} diff --git a/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/entity/vanilla/EntityRegistryMixin.java b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/entity/vanilla/EntityRegistryMixin.java new file mode 100644 index 0000000..4f7e646 --- /dev/null +++ b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/entity/vanilla/EntityRegistryMixin.java @@ -0,0 +1,66 @@ +package com.falsepattern.endlessids.mixin.mixins.common.entity.vanilla; + +import com.falsepattern.endlessids.constants.ExtendedConstants; +import com.falsepattern.endlessids.constants.VanillaConstants; +import org.apache.logging.log4j.Level; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.Constant; +import org.spongepowered.asm.mixin.injection.ModifyConstant; + +import cpw.mods.fml.common.FMLLog; +import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.registry.EntityRegistry; + +import java.util.BitSet; + +@Mixin(value = EntityRegistry.class, + remap = false) +public abstract class EntityRegistryMixin { + @Shadow private BitSet availableIndicies; + + @ModifyConstant(method = "", + constant = @Constant(intValue = VanillaConstants.entityIDCount), + require = 1) + private int extendIDs1(int constant) { + return ExtendedConstants.entityIDCount; + } + + @ModifyConstant(method = "", + constant = @Constant(intValue = VanillaConstants.maxEntityID), + require = 1) + private int extendIDs2(int constant) { + return ExtendedConstants.maxEntityID; + } + + /** + * @author FalsePattern + * @reason Extended IDs + */ + @Overwrite + private int validateAndClaimId(int id) { + //Keeping the legacy sub-0 id workaround here... + + // workaround for broken ML + int realId = id; + if (id < Byte.MIN_VALUE) { + realId += 3000; + FMLLog.warning("Compensating for modloader out of range compensation by mod : entityId %d for mod %s is now %d", id, Loader.instance().activeModContainer().getModId(), realId); + } + + if (realId < 0) { + realId += Byte.MAX_VALUE; + } + + if ((realId & ~ExtendedConstants.entityIDMask) != 0) { + FMLLog.log(Level.ERROR, "The entity ID %d for mod %s is not in the range 1-" + ExtendedConstants.entityIDMask + " and may not work", id, Loader.instance().activeModContainer().getModId()); + } + + if (!availableIndicies.get(realId)) { + FMLLog.severe("The mod %s has attempted to register an entity ID %d which is already reserved. This could cause severe problems", Loader.instance().activeModContainer().getModId(), id); + } + availableIndicies.clear(realId); + return realId; + } +} diff --git a/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/entity/vanilla/S0FPacketSpawnMobMixin.java b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/entity/vanilla/S0FPacketSpawnMobMixin.java new file mode 100644 index 0000000..e714791 --- /dev/null +++ b/src/main/java/com/falsepattern/endlessids/mixin/mixins/common/entity/vanilla/S0FPacketSpawnMobMixin.java @@ -0,0 +1,63 @@ +package com.falsepattern.endlessids.mixin.mixins.common.entity.vanilla; + +import com.falsepattern.endlessids.constants.ExtendedConstants; +import io.netty.buffer.ByteBuf; +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.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.minecraft.entity.EntityList; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.network.PacketBuffer; +import net.minecraft.network.play.server.S0FPacketSpawnMob; + +@Mixin(S0FPacketSpawnMob.class) +public abstract class S0FPacketSpawnMobMixin { + @Shadow private int field_149040_b; + + @Inject(method = "(Lnet/minecraft/entity/EntityLivingBase;)V", + at = @At("RETURN"), + require = 1) + private void unClampType(EntityLivingBase entity, CallbackInfo ci) { + field_149040_b = EntityList.getEntityID(entity); + } + + @Redirect(method = "readPacketData", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/network/PacketBuffer;readByte()B", + ordinal = 0), + require = 1) + private byte noReadByte(PacketBuffer data) { + return 0; + } + + @Inject(method = "readPacketData", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/network/PacketBuffer;readByte()B", + ordinal = 0), + require = 1) + private void readType(PacketBuffer data, CallbackInfo ci) { + field_149040_b = data.readShort() & ExtendedConstants.entityIDMask; + } + + @Redirect(method = "writePacketData", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/network/PacketBuffer;writeByte(I)Lio/netty/buffer/ByteBuf;", + ordinal = 0), + require = 1) + private ByteBuf noWriteByte(PacketBuffer data, int theByte) { + return null; + } + + @Inject(method = "writePacketData", + at = @At(value = "INVOKE", + target = "Lnet/minecraft/network/PacketBuffer;writeByte(I)Lio/netty/buffer/ByteBuf;", + ordinal = 0), + require = 1) + private void writeType(PacketBuffer data, CallbackInfo ci) { + data.writeShort(field_149040_b & ExtendedConstants.entityIDMask); + } +} diff --git a/src/main/java/com/falsepattern/endlessids/mixin/plugin/Mixin.java b/src/main/java/com/falsepattern/endlessids/mixin/plugin/Mixin.java index 6255b84..421fa54 100644 --- a/src/main/java/com/falsepattern/endlessids/mixin/plugin/Mixin.java +++ b/src/main/java/com/falsepattern/endlessids/mixin/plugin/Mixin.java @@ -215,6 +215,13 @@ public enum Mixin implements IMixin { S1EPacketRemoveEntityEffectMixin(Side.COMMON, condition(() -> GeneralConfig.extendPotion), "potion.vanilla.network.S1EPacketRemoveEntityEffectMixin"), //endregion vanilla //endregion potion + //region entity + //region vanilla + EntityListMixin(Side.COMMON, condition(() -> GeneralConfig.extendEntity), "entity.vanilla.EntityListMixin"), + EntityRegistryMixin(Side.COMMON, condition(() -> GeneralConfig.extendEntity), "entity.vanilla.EntityRegistryMixin"), + S0FPacketSpawnMobMixin(Side.COMMON, condition(() -> GeneralConfig.extendEntity), "entity.vanilla.S0FPacketSpawnMobMixin"), + //endregion vanilla + //endregion entity //endregion common //region client