remove magic constants, start implementing id extension to 24 bits

This commit is contained in:
FalsePattern committed 2022-03-17 20:13:02 +01:00
1 parent 6708c57d0f
commit c486782e32
23 files changed
+202 -66

No files matched your search

@@ -2,6 +2,7 @@ package com.falsepattern.endlessids.asm;
public class Constants
{
public static final int maxBlockId = 32767;
public static final int blockIdMask = 65535;
public static final int ebsIdArrayLength = 4096;
@@ -11,7 +12,11 @@ public class Constants
public static final int newEbsSize = 14336;
public static final int newSize = 229632;
public static final int maxDataWatcherId = 127;
public static final int vanillaIDCount = 4096;
public static final int newIDCount = 32768;
public static final int vanillaIDBits = 12;
public static final int newIDBits = 16;
public Constants() {
super();
}
@@ -1,5 +1,7 @@
package com.falsepattern.endlessids.asm.transformer;
import com.falsepattern.endlessids.constants.ExtendedConstants;
import com.falsepattern.endlessids.constants.VanillaConstants;
import org.objectweb.asm.tree.MethodNode;
import com.falsepattern.endlessids.asm.AsmUtil;
import org.objectweb.asm.tree.ClassNode;
@@ -14,8 +16,8 @@ public class CofhBlockHelper implements IClassNodeTransformer
@Override
public void transform(final ClassNode cn, final boolean obfuscated) {
final MethodNode method = AsmUtil.findMethod(cn, "<clinit>");
if (!AsmUtil.transformInlinedSizeMethod(cn, method, 4096, 32768, true)) {
AsmUtil.transformInlinedSizeMethod(cn, method, 1024, 32768);
if (!AsmUtil.transformInlinedSizeMethod(cn, method, VanillaConstants.blockIDCount, ExtendedConstants.blockIDCount, true)) {
AsmUtil.transformInlinedSizeMethod(cn, method, VanillaConstants.blockIDCount / 4, ExtendedConstants.blockIDCount);
}
}
}
@@ -1,5 +1,7 @@
package com.falsepattern.endlessids.asm.transformer;
import com.falsepattern.endlessids.constants.ExtendedConstants;
import com.falsepattern.endlessids.constants.VanillaConstants;
import org.objectweb.asm.tree.FieldNode;
import com.falsepattern.endlessids.asm.AsmTransformException;
import org.objectweb.asm.tree.MethodNode;
@@ -17,11 +19,11 @@ public class FmlRegistry implements IClassNodeTransformer
public void transform(final ClassNode cn, final boolean obfuscated) {
final FieldNode field = AsmUtil.findField(cn, "MAX_BLOCK_ID", true);
if (field != null) {
field.value = Integer.valueOf(32767);
field.value = ExtendedConstants.maxBlockID;
}
boolean found = false;
for (final MethodNode method : cn.methods) {
if (AsmUtil.transformInlinedSizeMethod(cn, method, 4095, 32767, true)) {
if (AsmUtil.transformInlinedSizeMethod(cn, method, VanillaConstants.maxBlockID, ExtendedConstants.maxBlockID, true)) {
found = true;
}
}
@@ -1,5 +1,7 @@
package com.falsepattern.endlessids.asm.transformer;
import com.falsepattern.endlessids.constants.ExtendedConstants;
import com.falsepattern.endlessids.constants.VanillaConstants;
import org.objectweb.asm.tree.MethodNode;
import com.falsepattern.endlessids.asm.AsmUtil;
import com.falsepattern.endlessids.asm.Name;
@@ -17,7 +19,7 @@ public class MFQM implements IClassNodeTransformer
public void transform(final ClassNode cn, final boolean obfuscated) {
if (IEConfig.extendDataWatcher) {
final MethodNode method = AsmUtil.findMethod(cn, Name.MFQM_preInit);
AsmUtil.transformInlinedSizeMethod(cn, method, 31, 127);
AsmUtil.transformInlinedSizeMethod(cn, method, VanillaConstants.watchableMask, ExtendedConstants.watchableMask);
}
}
}
@@ -1,5 +1,7 @@
package com.falsepattern.endlessids.asm.transformer;
import com.falsepattern.endlessids.constants.ExtendedConstants;
import com.falsepattern.endlessids.constants.VanillaConstants;
import org.objectweb.asm.tree.MethodNode;
import com.falsepattern.endlessids.asm.AsmUtil;
import org.objectweb.asm.tree.ClassNode;
@@ -14,6 +16,6 @@ public class UndergroundBiomesOreUBifier implements IClassNodeTransformer
@Override
public void transform(final ClassNode cn, final boolean obfuscated) {
final MethodNode method = AsmUtil.findMethod(cn, "renewBlockReplacers");
AsmUtil.transformInlinedSizeMethod(cn, method, 4096, 32768, false);
AsmUtil.transformInlinedSizeMethod(cn, method, VanillaConstants.blockIDCount, ExtendedConstants.blockIDCount, false);
}
}
@@ -1,5 +1,7 @@
package com.falsepattern.endlessids.asm.transformer;
import com.falsepattern.endlessids.constants.ExtendedConstants;
import com.falsepattern.endlessids.constants.VanillaConstants;
import lombok.val;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodNode;
@@ -20,15 +22,15 @@ public class WorldEditBaseBlock implements IClassNodeTransformer
if (method == null) {
return;
}
AsmUtil.transformInlinedSizeMethod(cn, method, 4095, 32767);
AsmUtil.transformInlinedSizeMethod(cn, method, VanillaConstants.maxBlockID, ExtendedConstants.maxBlockID);
final InsnList code = method.instructions;
val iter = code.iterator();
while (iter.hasNext()) {
val insn = iter.next();
if (insn.getType() == 9 && ((LdcInsnNode)insn).cst instanceof String) {
final String string = (String)((LdcInsnNode)insn).cst;
if (string.contains("4095")) {
((LdcInsnNode)insn).cst = string.replace("4095", Integer.toString(32767));
if (string.contains(Integer.toString(VanillaConstants.maxBlockID))) {
((LdcInsnNode)insn).cst = string.replace(Integer.toString(VanillaConstants.maxBlockID), Integer.toString(ExtendedConstants.maxBlockID));
break;
}
}