Add LDC constant helper methods#51
Merged
LexManos merged 2 commits intoOct 13, 2024
Merged
Conversation
Member
Author
|
I have tested this PR in Forge and it is ready for a proper review. Here's what I used to test this: CoreMod: var ASMAPI = Java.type('net.minecraftforge.coremod.api.ASMAPI');
var Opcodes = Java.type('org.objectweb.asm.Opcodes');
function initializeCoreMod() {
return {
'thunderHit_ldc_test': {
'target': {
'type': 'METHOD',
'class': 'net.minecraft.world.entity.Entity',
'methodName': 'thunderHit',
'methodDesc': '(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/LightningBolt;)V'
},
'transformer': thunderHit
}
};
}
function thunderHit(method) {
ASMAPI.log('INFO', 'HELLO! ENTERING LDC TEST');
var insn = ASMAPI.findFirstInstruction(method, Opcodes.LDC);
ASMAPI.log('INFO', 'LDC instruction object class: {}', ASMAPI.ldcInsnClassToString(insn));
ASMAPI.log('INFO', 'LDC instruction object value: {}', insn.cst);
ASMAPI.log('INFO', 'SETTING NEW LDC! SETTING VALUE TO 12.0F');
var newInsn = ASMAPI.buildNumberLdcInsnNode(12.0, ASMAPI.LdcNumberType.FLOAT);
method.instructions.set(insn, newInsn);
ASMAPI.log('INFO', 'NEW LDC instruction object class: {}', ASMAPI.ldcInsnClassToString(newInsn));
ASMAPI.log('INFO', 'NEW LDC instruction object value: {}', newInsn.cst);
return method;
}RESULTING LOG MESSAGES: This example changes the time set in fire from thunder hit from 8 to 12. |
PaintNinja
approved these changes
Oct 13, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR aims to address the pains of dealing with LDC constant instructions.
buildLdcInsnNode()method uses aLdcNumberTypeto ensure that the exact type of number is fed into theLdcInsnNodeconstructor. Fixes Would like a way to create LDC with a float value #42.ldcInsnClassToStringmethod gets the class name of the constant stored in the givenLdcInsnNode, making it easier to debug existing LDC constant instructions. Fixes No way to check type of LDC? #30.Will remain as draft until I test these additions myself.