Skip to content

Commit

Permalink
0.2.0 - Client Side
Browse files Browse the repository at this point in the history
Client side version, now has a coremod to make this possible (boo, etc.)
  • Loading branch information
Charles445 committed Nov 2, 2020
1 parent eb42643 commit ebc25cb
Show file tree
Hide file tree
Showing 12 changed files with 1,326 additions and 112 deletions.
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.


version = "1.12.2-0.1.0"
version = "1.12.2-0.2.0"
group = "com.charles445.damagetilt" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "DamageTilt"

Expand Down Expand Up @@ -46,3 +46,11 @@ processResources {
exclude 'mcmod.info'
}
}

jar {
manifest
{
attributes "FMLCorePlugin": "com.charles445.damagetilt.asm.CoreLoader"
attributes "FMLCorePluginContainsFMLMod": "com.charles445.damagetilt.DamageTilt"
}
}
13 changes: 4 additions & 9 deletions src/main/java/com/charles445/damagetilt/DamageTilt.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@
modid = DamageTilt.MODID,
name = DamageTilt.NAME,
version = DamageTilt.VERSION,
acceptedMinecraftVersions = "[1.12]"
acceptedMinecraftVersions = "[1.12, 1.13)",
acceptableRemoteVersions = "*",
clientSideOnly = true
)
public class DamageTilt
{
public static final String MODID = "damagetilt";
public static final String NAME = "Damage Tilt";
public static final String VERSION = "0.1.0";

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
{
PacketHandler.init();
MinecraftForge.EVENT_BUS.register(new EventHandler());
}
public static final String VERSION = "0.2.0";
}
26 changes: 0 additions & 26 deletions src/main/java/com/charles445/damagetilt/EventHandler.java

This file was deleted.

30 changes: 30 additions & 0 deletions src/main/java/com/charles445/damagetilt/HookEntity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.charles445.damagetilt;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.MathHelper;

public class HookEntity
{
public static void setVelocity(Entity entity, double x, double y, double z)
{
if(!ModConfig.damageTiltEnabled)
return;

//This is run before motion is locally set

if(entity != null)
{
EntityPlayer player = Minecraft.getMinecraft().player;
if(player != null && entity.equals(player))
{
//Set the value
float result = (float)(MathHelper.atan2(player.motionZ - z, player.motionX - x) * (180D / Math.PI) - (double)player.rotationYaw);

if(Float.isFinite(result))
player.attackedAtYaw = result;
}
}
}
}

This file was deleted.

15 changes: 0 additions & 15 deletions src/main/java/com/charles445/damagetilt/PacketHandler.java

This file was deleted.

49 changes: 49 additions & 0 deletions src/main/java/com/charles445/damagetilt/asm/CoreLoader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.charles445.damagetilt.asm;

import java.util.Map;

import com.charles445.damagetilt.asm.helper.ObfHelper;

import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;

@IFMLLoadingPlugin.Name("Damage Tilt ASM")
@IFMLLoadingPlugin.SortingIndex(1002)
@IFMLLoadingPlugin.TransformerExclusions({ "com.charles445.damagetilt.asm", "com.charles445.damagetilt.asm." })

public class CoreLoader implements IFMLLoadingPlugin
{
//
// IFMLLoadingPlugin
//

@Override
public String[] getASMTransformerClass()
{
return new String[] { "com.charles445.damagetilt.asm.DamageTiltASM" };
}

@Override
public void injectData(Map<String, Object> data)
{
ObfHelper.setObfuscated((Boolean) data.get("runtimeDeobfuscationEnabled"));
ObfHelper.setRunsAfterDeobfRemapper(true);
}

@Override
public String getModContainerClass()
{
return null;
}

@Override
public String getSetupClass()
{
return null;
}

@Override
public String getAccessTransformerClass()
{
return null;
}
}
63 changes: 63 additions & 0 deletions src/main/java/com/charles445/damagetilt/asm/DamageTiltASM.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.charles445.damagetilt.asm;

import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.VarInsnNode;

import com.charles445.damagetilt.asm.helper.ASMHelper;

import net.minecraft.launchwrapper.IClassTransformer;

public class DamageTiltASM implements IClassTransformer
{
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass)
{
if(transformedName.equals("net.minecraft.entity.Entity"))
{
return transformEntity(basicClass);
}

return basicClass;
}

public byte[] transformEntity(byte[] basicClass)
{
ClassNode cNode = ASMHelper.readClassFromBytes(basicClass);

//net.minecraft.entity.Entity

for(MethodNode mNode : cNode.methods)
{
if(mNode.name.equals("func_70016_h") || mNode.name.equals("setVelocity"))
{
//Matching name, verify correct desc
if(mNode.desc.equals("(DDD)V"))
{
//Found a match
InsnList hook = new InsnList();

hook.add(new VarInsnNode(Opcodes.ALOAD,0)); //push this to stack
hook.add(new VarInsnNode(Opcodes.DLOAD,1)); //push x to stack (increment 2 for doubles as param)
hook.add(new VarInsnNode(Opcodes.DLOAD,3)); //push y to stack
hook.add(new VarInsnNode(Opcodes.DLOAD,5)); //push z to stack
hook.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/charles445/damagetilt/HookEntity", "setVelocity", "(Lnet/minecraft/entity/Entity;DDD)V", false));

//Add to method head
mNode.instructions.insertBefore(ASMHelper.findFirstInstruction(mNode), hook);

System.out.println("Damage Tilt Patched net.minecraft.entity.Entity");
return ASMHelper.writeClassToBytes(cNode, ClassWriter.COMPUTE_MAXS);
}

}
}

System.out.println("Damage Tilt Skipping patch for net.minecraft.entity.Entity");
return basicClass;
}
}
Loading

0 comments on commit ebc25cb

Please sign in to comment.