Skip to content

Commit

Permalink
feat(astral): patch astral tools
Browse files Browse the repository at this point in the history
Allows astral tools to break modded blocks that are incompletely described at full speed
  • Loading branch information
sam-kirby committed Oct 9, 2021
1 parent b4d07c9 commit 558aa46
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 28 deletions.
22 changes: 10 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
repositories {
maven { url = 'https://repo.spongepowered.org/maven' }
maven { url = 'https://files.minecraftforge.net/maven' }
maven { url = 'http://repo.spongepowered.org/maven' }
jcenter()
mavenCentral()
}
Expand All @@ -11,10 +11,6 @@ buildscript {
}
}

plugins {
id 'com.wynprice.cursemaven' version '2.1.4'
}

apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'org.spongepowered.mixin'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
Expand All @@ -36,8 +32,8 @@ sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = co

minecraft {
mappings channel: 'stable', version: '39-1.12'
accessTransformer = file('src/main/resources/META-INF/sevpatches_at.cfg')

// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
runs {
client {
workingDirectory project.file('run')
Expand Down Expand Up @@ -70,21 +66,22 @@ configurations {
}

repositories {
maven { url "http://repo.spongepowered.org/maven" }
maven { url "https://repo.spongepowered.org/maven" }
maven { url 'https://dvs1.progwml6.com/files/maven' }
maven { url "https://www.cursemaven.com" }
}

dependencies {
minecraft 'net.minecraftforge:forge:1.12.2-14.23.5.2854'
minecraft 'net.minecraftforge:forge:1.12.2-14.23.5.2855'

shade('org.spongepowered:mixin:0.8') {
transitive = false
}

compile fg.deobf('curse.maven:astralsorcery-1.0.23:2920254')
compile fg.deobf('curse.maven:jaff-1.7:2448283')
compile fg.deobf('slimeknights:TConstruct:1.12.2-2.13.0.184')
compile 'curse.maven:realisticitemdrops_deobf_1.2.14:2630385'
compile 'curse.maven:astralsorcery-1.0.23-241721:2920254'
compile 'curse.maven:jaff-1.7-235261:2448283'
compile 'slimeknights:TConstruct:1.12.2-2.13.0.184'
compile 'curse.maven:realisticitemdrops_deobf_1.2.14-245620:2630385'
}

mixin {
Expand All @@ -105,6 +102,7 @@ jar {
"FMLCorePlugin" : "tv.darkosto.sevpatches.core.SevPatchesLoadingPlugin",
"FMLCorePluginContainsFMLMod": "true",
"ForceLoadAsMod" : "true",
"FMLAT" : "sevpatches_at.cfg",
])
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
2 changes: 1 addition & 1 deletion src/main/java/tv/darkosto/sevpatches/SevPatches.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.List;
import java.util.Optional;

@Mod(modid = "sevpatches")
@Mod(modid = "sevpatches", acceptableRemoteVersions = "*")
public class SevPatches {
public static Logger LOGGER = LogManager.getLogger("sevpatches");
List<EntityItem> itemList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public class SevPatchesLoadingPlugin implements IFMLLoadingPlugin {
public static String ENTITY_TASKS;
public static String ENTITY_TASKS_ADD_TASK;

public static String GET_DESTROY_SPEED;
public static String GET_MATERIAL;
public static String EFFICIENCY;
public static String MATERIAL_ANVIL;
public static String MATERIAL_IRON;
public static String MATERIAL_PLANTS;
public static String MATERIAL_ROCK;
public static String MATERIAL_VINE;
public static String MATERIAL_WOOD;

public SevPatchesLoadingPlugin() {
LOGGER.info("setting up mixin environment");
MixinBootstrap.init();
Expand Down Expand Up @@ -91,6 +101,16 @@ public void injectData(Map<String, Object> data) {
SevPatchesLoadingPlugin.INIT_ENTITY_AI = dev ? "initEntityAI" : "func_184651_r";
SevPatchesLoadingPlugin.ENTITY_TASKS = dev ? "tasks" : "field_70714_bg";
SevPatchesLoadingPlugin.ENTITY_TASKS_ADD_TASK = dev ? "addTask" : "func_75776_a";

SevPatchesLoadingPlugin.GET_DESTROY_SPEED = dev ? "getDestroySpeed" : "func_150893_a";
SevPatchesLoadingPlugin.GET_MATERIAL = dev ? "getMaterial" : "func_185904_a";
SevPatchesLoadingPlugin.EFFICIENCY = dev ? "efficiency" : "field_77864_a";
SevPatchesLoadingPlugin.MATERIAL_ANVIL = dev ? "ANVIL" : "field_151574_g";
SevPatchesLoadingPlugin.MATERIAL_IRON = dev ? "IRON" : "field_151573_f";
SevPatchesLoadingPlugin.MATERIAL_PLANTS = dev ? "PLANTS" : "field_151585_k";
SevPatchesLoadingPlugin.MATERIAL_ROCK = dev ? "ROCK" : "field_151576_e";
SevPatchesLoadingPlugin.MATERIAL_VINE = dev ? "VINE" : "field_151582_l";
SevPatchesLoadingPlugin.MATERIAL_WOOD = dev ? "WOOD" : "field_151575_d";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
package tv.darkosto.sevpatches.core;

import net.minecraft.launchwrapper.IClassTransformer;
import tv.darkosto.sevpatches.core.patches.PatchAstralAmulet;
import tv.darkosto.sevpatches.core.patches.PatchAstralBootesCheat;
import tv.darkosto.sevpatches.core.patches.PatchHarvestOOO;
import tv.darkosto.sevpatches.core.patches.PatchInControlHandlerPriority;
import tv.darkosto.sevpatches.core.patches.PatchJaffFishAreFish;
import tv.darkosto.sevpatches.core.patches.PatchJaffFishLiveInWater;
import tv.darkosto.sevpatches.core.patches.PatchJaffSpawnRemover;
import tv.darkosto.sevpatches.core.patches.PatchMinecraftSpawnChunkSpawning;
import tv.darkosto.sevpatches.core.patches.PatchPrimalDrying;
import tv.darkosto.sevpatches.core.patches.PatchPrimalNicerHammerHeads;
import tv.darkosto.sevpatches.core.patches.PatchPrimalScaredyCat;
import tv.darkosto.sevpatches.core.patches.PatchPrimalSpreading;
import tv.darkosto.sevpatches.core.patches.PatchRidHandlerDeregister;
import tv.darkosto.sevpatches.core.patches.*;

public class SevPatchesTransformer implements IClassTransformer {
@Override
Expand All @@ -31,6 +19,9 @@ public byte[] transform(String name, String transformedName, byte[] basicClass)
return new PatchAstralBootesCheat(basicClass).apply();
case "hellfirepvp.astralsorcery.common.enchantment.amulet.EnchantmentUpgradeHelper":
return new PatchAstralAmulet(basicClass).apply();
case "hellfirepvp.astralsorcery.common.item.tool.ItemCrystalAxe":
case "hellfirepvp.astralsorcery.common.item.tool.ItemCrystalPickaxe":
return new PatchAstralTools(basicClass).apply();
case "mcjty.incontrol.ForgeEventHandlers":
return new PatchInControlHandlerPriority(basicClass).apply();
case "nmd.primal.core.common.entities.living.EntityHammerHead":
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
package tv.darkosto.sevpatches.core.patches;

import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.*;
import tv.darkosto.sevpatches.core.SevPatchesLoadingPlugin;
import tv.darkosto.sevpatches.core.utils.AsmUtils;

public class PatchAstralTools extends Patch {
public PatchAstralTools(byte[] inputClass) {
super(inputClass);
}

@Override
protected boolean patch() {
MethodNode destroySpeed = AsmUtils.findMethod(this.classNode, SevPatchesLoadingPlugin.GET_DESTROY_SPEED);
if (destroySpeed != null) this.classNode.methods.remove(destroySpeed);

/*
@Override
public float getDestroySpeed(ItemStack stack, IBlockState state) {
Material material = state.getMaterial();
if (material != Material.WOOD && material != Material.PLANTS && material != Material.VINE) {
return super.getDestroySpeed(stack, state);
} else {
ToolCrystalProperties properties = getToolProperties(stack);
return this.efficiency * properties.getEfficiencyMultiplier() * 2F;
}
}
*/
MethodNode getDestroySpeed = new MethodNode(
Opcodes.ACC_PUBLIC,
SevPatchesLoadingPlugin.GET_DESTROY_SPEED,
"(Lnet/minecraft/item/ItemStack;Lnet/minecraft/block/state/IBlockState;)F",
null,
null
);

InsnList hookInsns = getDestroySpeed.instructions;
hookInsns.add(new VarInsnNode(Opcodes.ALOAD, 2));
hookInsns.add(new MethodInsnNode(
Opcodes.INVOKEINTERFACE,
"net/minecraft/block/state/IBlockState",
SevPatchesLoadingPlugin.GET_MATERIAL,
"()Lnet/minecraft/block/material/Material;",
true
));
hookInsns.add(new VarInsnNode(Opcodes.ASTORE, 3));

String[] axe_materials = new String[]{SevPatchesLoadingPlugin.MATERIAL_WOOD, SevPatchesLoadingPlugin.MATERIAL_PLANTS, SevPatchesLoadingPlugin.MATERIAL_VINE};
String[] pickaxe_materials = new String[]{SevPatchesLoadingPlugin.MATERIAL_ROCK, SevPatchesLoadingPlugin.MATERIAL_IRON, SevPatchesLoadingPlugin.MATERIAL_ANVIL};

LabelNode jump_label = new LabelNode();

if (classNode.name.contains("Pickaxe")) {
for (String material : pickaxe_materials) {
hookInsns.add(new VarInsnNode(Opcodes.ALOAD, 3));
hookInsns.add(new FieldInsnNode(
Opcodes.GETSTATIC,
"net/minecraft/block/material/Material",
material,
"Lnet/minecraft/block/material/Material;"
));
hookInsns.add(new JumpInsnNode(Opcodes.IF_ACMPEQ, jump_label));
}
} else if (classNode.name.contains("Axe")) {
for (String material : axe_materials) {
hookInsns.add(new VarInsnNode(Opcodes.ALOAD, 3));
hookInsns.add(new FieldInsnNode(
Opcodes.GETSTATIC,
"net/minecraft/block/material/Material",
material,
"Lnet/minecraft/block/material/Material;"
));
hookInsns.add(new JumpInsnNode(Opcodes.IF_ACMPEQ, jump_label));
}
} else {
SevPatchesLoadingPlugin.LOGGER.warn("Unexpected tool class: {}", classNode.name);
return false;
}

hookInsns.add(new VarInsnNode(Opcodes.ALOAD, 0));
hookInsns.add(new VarInsnNode(Opcodes.ALOAD, 1));
hookInsns.add(new VarInsnNode(Opcodes.ALOAD, 2));
hookInsns.add(new MethodInsnNode(
Opcodes.INVOKESPECIAL,
"hellfirepvp/astralsorcery/common/item/tool/ItemCrystalToolBase",
SevPatchesLoadingPlugin.GET_DESTROY_SPEED,
"(Lnet/minecraft/item/ItemStack;Lnet/minecraft/block/state/IBlockState;)F",
false
));
hookInsns.add(new InsnNode(Opcodes.FRETURN));

hookInsns.add(jump_label);
hookInsns.add(new VarInsnNode(Opcodes.ALOAD, 1));
hookInsns.add(new MethodInsnNode(
Opcodes.INVOKESTATIC,
"hellfirepvp/astralsorcery/common/item/tool/ItemCrystalToolBase",
"getToolProperties",
"(Lnet/minecraft/item/ItemStack;)Lhellfirepvp/astralsorcery/common/item/crystal/ToolCrystalProperties;",
false
));
hookInsns.add(new VarInsnNode(Opcodes.ASTORE, 4));
hookInsns.add(new VarInsnNode(Opcodes.ALOAD, 0));
hookInsns.add(new FieldInsnNode(
Opcodes.GETFIELD,
"net/minecraft/item/ItemTool",
SevPatchesLoadingPlugin.EFFICIENCY,
"F"
));
hookInsns.add(new VarInsnNode(Opcodes.ALOAD, 4));
hookInsns.add(new MethodInsnNode(
Opcodes.INVOKEVIRTUAL,
"hellfirepvp/astralsorcery/common/item/crystal/ToolCrystalProperties",
"getEfficiencyMultiplier",
"()F",
false
));
hookInsns.add(new InsnNode(Opcodes.FMUL));
hookInsns.add(new InsnNode(Opcodes.FCONST_2));
hookInsns.add(new InsnNode(Opcodes.FMUL));
hookInsns.add(new InsnNode(Opcodes.FRETURN));

classNode.methods.add(getDestroySpeed);

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public PatchJaffFishAreFish(byte[] inputClass) {
protected boolean patch() {
/*
public boolean isNotColliding() {
this.world.checkNoEntityCollision(this.getEntityBoundingBox(), this);
return this.world.checkNoEntityCollision(this.getEntityBoundingBox(), this);
}
*/
MethodNode isFishNotColliding = new MethodNode(
Expand Down
Empty file.

0 comments on commit 558aa46

Please sign in to comment.