Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How to change Base Class code at runtime?


_vertig0
 Share

Recommended Posts

Ok, I will preface this by saying I know ASM and coremods should only be used when absolutely necessary. I've been trying to remove air resistance from arrows on my server, and this pesky bit of code is always eluding me:

float f2 = 0.99F;
if (this.isInWater()) {
    for(int j = 0; j < 4; ++j) {
        float f4 = 0.25F;
        this.world.addParticle(ParticleTypes.BUBBLE, d5 - d3 * 0.25D, d1 - d4 * 0.25D, d2 - d0 * 0.25D, d3, d4, d0);
    }

    f2 = this.getWaterDrag();
}

this.setMotion(vec3d.scale((double)f2));

float f2 is basically how drag is implemented in arrows. If I could simply delete the line f2 = this.getWaterDrag() and set float f2 = 1.0F, I'd have removed air resistance

 

The problem is that the f2 variable isn't defined in the class, it's defined in the method block. Instantly that completely makes reflection useless. I can't replace AbstractArrowEntity.java with my own Arrow Entity either, because it's a base class diverging out to many different Arrow subclasses. If I did that the server would crash every time a tipped arrow was shot. And I've also tried reverting the drag using LivingUpdateEvent at both end and start phases, and even both phases at once, but all that did was make arrows unusable because they'd fly around randomly after being shot. It seems ASM is my only way forward unfortunately, but Forge has switched the Coremod system and I'm not too sure how to use it

Link to comment
Share on other sites

11 minutes ago, _vertig0 said:

I know ASM and coremods should only be used when absolutely necessary

This doesn't seem like a good use case for ASM.

 

11 minutes ago, _vertig0 said:

LivingUpdateEvent

Thing about this for a second, are arrows living? Of course they aren't, arrows extend Entity and implement IProjectile.

In my opinion you should cancel one of the many events (maybe ArrowLooseEvent?) that references arrows and implement your own physics there.

Edited by Novârch

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

3 minutes ago, Novârch said:

This doesn't seem like a good use case for ASM.

 

Thing about this for a second, are arrows living? Of course they aren't, arrows extend Entity and implement IProjectile.

In my opinion you should cancel one of the many events (maybe ArrowLooseEvent?) that references arrows and implement your own physics there.

I'll try that and see if it works, but I suspect it's just going to clash with the base physics in AbstractArrowEntity anyway and go all wonky

 

 

Ah well, who else to blame but Mojang haha

Link to comment
Share on other sites

3 minutes ago, _vertig0 said:

clash with the base physics in AbstractArrowEntity anyway and go all wonky

Maybe you could replace all of the arrow entities entirely? Canceling either the usage of the bow or the spawning of the arrows.

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • What is Launcher log. Where is it located??? @Luis_ST
    • Thanks for the feedback. But it seems there is not really an easy way for this, most of the code is hard-coded and could not be accessed directly. 😞 I worked around this by using the "RenderHandEvent" and "RenderPlayerEvent" to create a dedicated render for my crossbow item.
    • I'm wondering how to go about creating a block that is essentially an Ender Chest (its contents are the same regardless of which chest you check), but where any player in that world can see the contents of the Ender Chest. I was thinking of modifying the saved data for a world, but I'm struggling to understand how that even works. Are there any tutorials out there on tools I can use to work on this sort of problem?  EDIT: I just found this post: is this about what I should be looking at for 1.16.5?    
    • Hey guys I have created a mod that assigns levels to mobs and scales them up using capabilities, everything works great but because of the recent changes to capabilities I am unable to find examples on how to save the level of my mobs so that it remains the same if I restart the server. I will upload all my files relating to the capability and hope you guys can lead me in the right direction   package com.chickenwand3.rpgmod.core.capabilities.entity; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.CapabilityInject; import net.minecraftforge.common.capabilities.CapabilityManager; @SuppressWarnings("removal") public class CapabilityMobLevel { @CapabilityInject(MobLevel.class) public static Capability<MobLevel> MOB_LEVEL_CAPABILITY = null; public static void register() { CapabilityManager.INSTANCE.register(MobLevel.class); } } package com.chickenwand3.rpgmod.core.capabilities.entity; public class DefaultMobLevel implements MobLevel { public int mobLevel; public float mobMaxHealth; public float mobCurrentHealth; public boolean crazy; public boolean isCrazy() { return crazy; } public float getMaxHealth() { return mobMaxHealth; } public float getCurrentHealth() { return mobCurrentHealth; } } package com.chickenwand3.rpgmod.core.capabilities.entity; public interface MobLevel { } package com.chickenwand3.rpgmod.core.capabilities.entity; import com.chickenwand3.rpgmod.RPGMod; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Mob; import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.monster.Zombie; import net.minecraft.world.item.enchantment.Enchantments; import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber(modid = RPGMod.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) public class MobLevelEventHandler { @SubscribeEvent public static void onAttachCapabilitiesEvent(AttachCapabilitiesEvent<Entity> event) { if (event.getObject() instanceof Mob && !event.getObject().getCommandSenderWorld().isClientSide) { MobLevelProvider providerMobLevel = new MobLevelProvider(); event.addCapability(new ResourceLocation(RPGMod.MODID, "moblevel"), providerMobLevel); event.addListener(providerMobLevel::invalidate); } } @SubscribeEvent public static void OnSpawn(final EntityJoinWorldEvent event) { if (event.getEntity()instanceof Mob target && !event.getWorld().isClientSide) { target.getCapability(CapabilityMobLevel.MOB_LEVEL_CAPABILITY).ifPresent(mobLevel -> { DefaultMobLevel actualMobLevel = (DefaultMobLevel) mobLevel; actualMobLevel.mobLevel = (randomizeMobLevel()); if (superCrazy(actualMobLevel.mobLevel)) { actualMobLevel.crazy = true; } if (actualMobLevel.crazy) { if (!target.getMainHandItem().isEmpty()) { target.getMainHandItem().enchant(Enchantments.FIRE_ASPECT, 1); } if (event.getEntity()instanceof Zombie zombie) { zombie.getAttribute(Attributes.SPAWN_REINFORCEMENTS_CHANCE).setBaseValue(0.99D); } System.out.println("Super Crazy " + target.getName() + " has spawned!"); } actualMobLevel.mobMaxHealth = (target.getMaxHealth() * actualMobLevel.mobLevel * 2); actualMobLevel.mobCurrentHealth = actualMobLevel.mobMaxHealth; target.getAttribute(Attributes.MOVEMENT_SPEED) .setBaseValue(target.getAttributeValue(Attributes.MOVEMENT_SPEED) * (1 + (actualMobLevel.mobLevel - 1.0) / 10.0)); if (target.getAttribute(Attributes.ATTACK_DAMAGE) != null) { target.getAttribute(Attributes.ATTACK_DAMAGE) .setBaseValue(target.getAttributeValue(Attributes.ATTACK_DAMAGE) * (1 + (actualMobLevel.mobLevel - 1.0) / 2.0)); } }); } } private static int randomizeMobLevel() { boolean roll = true; int level = 1; while (roll) { if (Math.random() > .5) { level += 1; roll = true; } else { roll = false; } } return level; } private static boolean superCrazy(int level) { boolean result = false; if (level >= 5) { if (Math.random() < .25) { result = true; } else result = false; } return result; } } package com.chickenwand3.rpgmod.core.capabilities.entity; import net.minecraft.core.Direction; import net.minecraft.nbt.CompoundTag; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class MobLevelProvider implements ICapabilitySerializable<CompoundTag> { private final DefaultMobLevel mobLevel = new DefaultMobLevel(); private final LazyOptional<MobLevel> mobLevelOptional = LazyOptional.of(() -> mobLevel); public void invalidate() { mobLevelOptional.invalidate(); } @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { return mobLevelOptional.cast(); } @Override public CompoundTag serializeNBT() { if (CapabilityMobLevel.MOB_LEVEL_CAPABILITY == null) { return new CompoundTag(); } else { CompoundTag compoundNBT = new CompoundTag(); compoundNBT.putInt("mobLevel", mobLevel.mobLevel); compoundNBT.putFloat("mobCurrentHealth", mobLevel.mobCurrentHealth); compoundNBT.putFloat("mobMaxHealth", mobLevel.mobMaxHealth); compoundNBT.putBoolean("crazy", mobLevel.crazy); return compoundNBT; } } @Override public void deserializeNBT(CompoundTag nbt) { if (CapabilityMobLevel.MOB_LEVEL_CAPABILITY != null) { mobLevel.mobLevel = (nbt.getInt("mobLevel")); float mobCurrentHealth = nbt.getFloat("mobCurrentHealth"); mobLevel.mobCurrentHealth = (mobCurrentHealth); float mobMaxHealth = nbt.getFloat("mobMaxHealth"); mobLevel.mobMaxHealth = (mobMaxHealth); boolean crazy = nbt.getBoolean("crazy"); mobLevel.crazy = (crazy); } } }  
    • Trying to install forge on Debian 11 (bullseye). I ran java -jar forge-1.18-38.0.4-installer.jar in the terminal, and that part seemed to work fine. I did the install client, and it was fine until the building processors step. It stopped and gave the following error message: Failed to run processor: java.lang.RuntimeException:Could not delete output file: home/[user]/.minecraft/libraries/de/oceanlabs/mcp/mcp_config/1.18-20211130.085255/mcp_config-1.18-20211130.085255-mappings.txt My dad did the same thing on his computer without complications. Any help would be much appreciated. Below is the installation log: JVM info: Debian - 17.0.1 - 17.0.1+12-Debian-1deb11u2 java.net.preferIPv4Stack=true Found java version 17.0.1 Extracting json Considering minecraft client jar Downloading libraries Found 0 additional library directories Considering library cpw.mods:securejarhandler:0.9.54 File exists: Checksum validated. Considering library org.ow2.asm:asm:9.1 File exists: Checksum validated. Considering library org.ow2.asm:asm-commons:9.1 File exists: Checksum validated. Considering library org.ow2.asm:asm-tree:9.1 File exists: Checksum validated. Considering library org.ow2.asm:asm-util:9.1 File exists: Checksum validated. Considering library org.ow2.asm:asm-analysis:9.1 File exists: Checksum validated. Considering library net.minecraftforge:accesstransformers:8.0.4 File exists: Checksum validated. Considering library org.antlr:antlr4-runtime:4.9.1 File exists: Checksum validated. Considering library net.minecraftforge:eventbus:5.0.3 File exists: Checksum validated. Considering library net.minecraftforge:forgespi:4.0.10 File exists: Checksum validated. Considering library net.minecraftforge:coremods:5.0.1 File exists: Checksum validated. Considering library cpw.mods:modlauncher:9.0.7 File exists: Checksum validated. Considering library net.minecraftforge:unsafe:0.2.0 File exists: Checksum validated. Considering library com.electronwill.night-config:core:3.6.4 File exists: Checksum validated. Considering library com.electronwill.night-config:toml:3.6.4 File exists: Checksum validated. Considering library org.apache.maven:maven-artifact:3.6.3 File exists: Checksum validated. Considering library org.apache.commons:commons-lang3:3.12.0 File exists: Checksum validated. Considering library net.jodah:typetools:0.8.3 File exists: Checksum validated. Considering library org.apache.logging.log4j:log4j-api:2.14.1 File exists: Checksum validated. Considering library org.apache.logging.log4j:log4j-core:2.14.1 File exists: Checksum validated. Considering library net.minecrell:terminalconsoleappender:1.2.0 File exists: Checksum validated. Considering library org.jline:jline-reader:3.12.1 File exists: Checksum validated. Considering library org.jline:jline-terminal:3.12.1 File exists: Checksum validated. Considering library net.sf.jopt-simple:jopt-simple:5.0.4 File exists: Checksum validated. Considering library org.openjdk.nashorn:nashorn-core:15.3 File exists: Checksum validated. Considering library com.google.guava:guava:31.0.1-jre File exists: Checksum validated. Considering library com.google.code.gson:gson:2.8.8 File exists: Checksum validated. Considering library cpw.mods:bootstraplauncher:0.1.17 File exists: Checksum validated. Considering library net.minecraftforge:fmlloader:1.18-38.0.4 File exists: Checksum validated. Considering library com.github.jponge:lzma-java:1.3 File exists: Checksum validated. Considering library com.google.code.findbugs:jsr305:3.0.2 File exists: Checksum validated. Considering library com.google.code.gson:gson:2.8.7 File exists: Checksum validated. Considering library com.google.errorprone:error_prone_annotations:2.1.3 File exists: Checksum validated. Considering library com.google.guava:guava:20.0 File exists: Checksum validated. Considering library com.google.guava:guava:25.1-jre File exists: Checksum validated. Considering library com.google.j2objc:j2objc-annotations:1.1 File exists: Checksum validated. Considering library com.nothome:javaxdelta:2.0.1 File exists: Checksum validated. Considering library com.opencsv:opencsv:4.4 File exists: Checksum validated. Considering library commons-beanutils:commons-beanutils:1.9.3 File exists: Checksum validated. Considering library commons-collections:commons-collections:3.2.2 File exists: Checksum validated. Considering library commons-io:commons-io:2.4 File exists: Checksum validated. Considering library commons-logging:commons-logging:1.2 File exists: Checksum validated. Considering library de.oceanlabs.mcp:mcp_config:1.18-20211130.085255@zip File exists: Checksum validated. Considering library de.siegmar:fastcsv:2.0.0 File exists: Checksum validated. Considering library net.md-5:SpecialSource:1.10.0 File exists: Checksum validated. Considering library net.minecraftforge:ForgeAutoRenamingTool:0.1.17:all File exists: Checksum validated. Considering library net.minecraftforge:binarypatcher:1.0.12 File exists: Checksum validated. Considering library net.minecraftforge:fmlcore:1.18-38.0.4 File exists: Checksum validated. Considering library net.minecraftforge:fmlloader:1.18-38.0.4 File exists: Checksum validated. Considering library net.minecraftforge:forge:1.18-38.0.4:universal File exists: Checksum validated. Considering library net.minecraftforge:installertools:1.2.10 File exists: Checksum validated. Considering library net.minecraftforge:jarsplitter:1.1.4 File exists: Checksum validated. Considering library net.minecraftforge:javafmllanguage:1.18-38.0.4 File exists: Checksum validated. Considering library net.minecraftforge:mclanguage:1.18-38.0.4 File exists: Checksum validated. Considering library net.minecraftforge:srgutils:0.4.3 File exists: Checksum validated. Considering library net.minecraftforge:srgutils:0.4.7 File exists: Checksum validated. Considering library net.sf.jopt-simple:jopt-simple:5.0.4 File exists: Checksum validated. Considering library net.sf.jopt-simple:jopt-simple:6.0-alpha-3 File exists: Checksum validated. Considering library org.apache.commons:commons-collections4:4.2 File exists: Checksum validated. Considering library org.apache.commons:commons-lang3:3.8.1 File exists: Checksum validated. Considering library org.apache.commons:commons-text:1.3 File exists: Checksum validated. Considering library org.checkerframework:checker-qual:2.0.0 File exists: Checksum validated. Considering library org.codehaus.mojo:animal-sniffer-annotations:1.14 File exists: Checksum validated. Considering library org.ow2.asm:asm-analysis:9.1 File exists: Checksum validated. Considering library org.ow2.asm:asm-analysis:9.2 File exists: Checksum validated. Considering library org.ow2.asm:asm-commons:9.1 File exists: Checksum validated. Considering library org.ow2.asm:asm-commons:9.2 File exists: Checksum validated. Considering library org.ow2.asm:asm-tree:9.1 File exists: Checksum validated. Considering library org.ow2.asm:asm-tree:9.2 File exists: Checksum validated. Considering library org.ow2.asm:asm:9.1 File exists: Checksum validated. Considering library org.ow2.asm:asm:9.2 File exists: Checksum validated. Considering library trove:trove:1.0.2 File exists: Checksum validated. Created Temporary Directory: /tmp/forge_installer10859551180063758840 Extracting: /data/client.lzma Building Processors =============================================================================== MainClass: net.minecraftforge.installertools.ConsoleTool Classpath: /home/qila/.minecraft/libraries/net/minecraftforge/installertools/1.2.10/installertools-1.2.10.jar /home/qila/.minecraft/libraries/net/md-5/SpecialSource/1.10.0/SpecialSource-1.10.0.jar /home/qila/.minecraft/libraries/net/sf/jopt-simple/jopt-simple/5.0.4/jopt-simple-5.0.4.jar /home/qila/.minecraft/libraries/com/google/code/gson/gson/2.8.7/gson-2.8.7.jar /home/qila/.minecraft/libraries/de/siegmar/fastcsv/2.0.0/fastcsv-2.0.0.jar /home/qila/.minecraft/libraries/net/minecraftforge/srgutils/0.4.3/srgutils-0.4.3.jar /home/qila/.minecraft/libraries/org/ow2/asm/asm-commons/9.1/asm-commons-9.1.jar /home/qila/.minecraft/libraries/com/google/guava/guava/20.0/guava-20.0.jar /home/qila/.minecraft/libraries/com/opencsv/opencsv/4.4/opencsv-4.4.jar /home/qila/.minecraft/libraries/org/ow2/asm/asm-analysis/9.1/asm-analysis-9.1.jar /home/qila/.minecraft/libraries/org/ow2/asm/asm-tree/9.1/asm-tree-9.1.jar /home/qila/.minecraft/libraries/org/ow2/asm/asm/9.1/asm-9.1.jar /home/qila/.minecraft/libraries/org/apache/commons/commons-text/1.3/commons-text-1.3.jar /home/qila/.minecraft/libraries/org/apache/commons/commons-lang3/3.8.1/commons-lang3-3.8.1.jar /home/qila/.minecraft/libraries/commons-beanutils/commons-beanutils/1.9.3/commons-beanutils-1.9.3.jar /home/qila/.minecraft/libraries/org/apache/commons/commons-collections4/4.2/commons-collections4-4.2.jar /home/qila/.minecraft/libraries/commons-logging/commons-logging/1.2/commons-logging-1.2.jar /home/qila/.minecraft/libraries/commons-collections/commons-collections/3.2.2/commons-collections-3.2.2.jar Args: --task, MCP_DATA, --input, /home/qila/.minecraft/libraries/de/oceanlabs/mcp/mcp_config/1.18-20211130.085255/mcp_config-1.18-20211130.085255.zip, --output, /home/qila/.minecraft/libraries/de/oceanlabs/mcp/mcp_config/1.18-20211130.085255/mcp_config-1.18-20211130.085255-mappings.txt, --key, mappings Task: MCP_DATA Input: /home/qila/.minecraft/libraries/de/oceanlabs/mcp/mcp_config/1.18-20211130.085255/mcp_config-1.18-20211130.085255.zip Output: /home/qila/.minecraft/libraries/de/oceanlabs/mcp/mcp_config/1.18-20211130.085255/mcp_config-1.18-20211130.085255-mappings.txt Key: mappings Could not delete output file: /home/qila/.minecraft/libraries/de/oceanlabs/mcp/mcp_config/1.18-20211130.085255/mcp_config-1.18-20211130.085255-mappings.txt java.lang.RuntimeException: Could not delete output file: /home/qila/.minecraft/libraries/de/oceanlabs/mcp/mcp_config/1.18-20211130.085255/mcp_config-1.18-20211130.085255-mappings.txt at net.minecraftforge.installertools.Task.error(Task.java:28) at net.minecraftforge.installertools.McpData.process(McpData.java:63) at net.minecraftforge.installertools.ConsoleTool.main(ConsoleTool.java:55) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at net.minecraftforge.installer.actions.PostProcessors.process(PostProcessors.java:226) at net.minecraftforge.installer.actions.ClientInstall.run(ClientInstall.java:144) at net.minecraftforge.installer.InstallerPanel.run(InstallerPanel.java:423) at net.minecraftforge.installer.SimpleInstaller.launchGui(SimpleInstaller.java:175) at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:147)  
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.