Changed durability code from reflection to ASM
parent
891c8a603c
commit
89dde83214
Binary file not shown.
Binary file not shown.
@ -1,78 +0,0 @@
|
|||||||
package com.zivilon.cinder_loe.mixins;
|
|
||||||
|
|
||||||
import lotr.common.LOTRMod;
|
|
||||||
import net.minecraft.block.Block;
|
|
||||||
import net.minecraft.item.Item;
|
|
||||||
|
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
|
||||||
import org.spongepowered.asm.mixin.Overwrite;
|
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
|
||||||
|
|
||||||
import lotr.common.item.LOTRMaterial;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.zivilon.cinder_loe.CinderLoE;
|
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|
||||||
|
|
||||||
@Mixin(LOTRMaterial.class)
|
|
||||||
public abstract class MixinLOTRMaterial {
|
|
||||||
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
Class<?> lotrMaterialClass = Class.forName("lotr.common.item.LOTRMaterial");
|
|
||||||
Field redDwarfSteelField = lotrMaterialClass.getField("RED_DWARF_STEEL");
|
|
||||||
|
|
||||||
|
|
||||||
// Reflection to access and instantiate the private constructor of LOTRMaterial
|
|
||||||
Constructor<?> constructor = lotrMaterialClass.getDeclaredConstructor(String.class);
|
|
||||||
constructor.setAccessible(true);
|
|
||||||
Object redDwarfSteelMaterial = constructor.newInstance("RED_DWARF_STEEL");
|
|
||||||
|
|
||||||
|
|
||||||
// Reflection to call the private methods on the new instance
|
|
||||||
Method setUses = lotrMaterialClass.getDeclaredMethod("setUses", int.class);
|
|
||||||
Method setDamage = lotrMaterialClass.getDeclaredMethod("setDamage", float.class);
|
|
||||||
Method setProtection = lotrMaterialClass.getDeclaredMethod("setProtection", float.class);
|
|
||||||
Method setHarvestLevel = lotrMaterialClass.getDeclaredMethod("setHarvestLevel", int.class);
|
|
||||||
Method setSpeed = lotrMaterialClass.getDeclaredMethod("setSpeed", float.class);
|
|
||||||
Method setEnchantability = lotrMaterialClass.getDeclaredMethod("setEnchantability", int.class);
|
|
||||||
|
|
||||||
setUses.setAccessible(true);
|
|
||||||
setDamage.setAccessible(true);
|
|
||||||
setProtection.setAccessible(true);
|
|
||||||
setHarvestLevel.setAccessible(true);
|
|
||||||
setSpeed.setAccessible(true);
|
|
||||||
setEnchantability.setAccessible(true);
|
|
||||||
|
|
||||||
// Red Dwarf
|
|
||||||
setUses.invoke(redDwarfSteelMaterial, 700);
|
|
||||||
setDamage.invoke(redDwarfSteelMaterial, 3.0F);
|
|
||||||
setProtection.invoke(redDwarfSteelMaterial, 0.7F);
|
|
||||||
setHarvestLevel.invoke(redDwarfSteelMaterial, 3);
|
|
||||||
setSpeed.invoke(redDwarfSteelMaterial, 7.0F);
|
|
||||||
setEnchantability.invoke(redDwarfSteelMaterial, 10);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Assuming a public method to set the crafting item exists
|
|
||||||
Method setCraftingItem = lotrMaterialClass.getDeclaredMethod("setCraftingItem", Item.class);
|
|
||||||
setCraftingItem.setAccessible(true);
|
|
||||||
setCraftingItem.invoke(redDwarfSteelMaterial, CinderLoE.redDwarfSteel);
|
|
||||||
|
|
||||||
|
|
||||||
// Now, assign the created and configured LOTRMaterial instance to the static field
|
|
||||||
redDwarfSteelField.set(null, redDwarfSteelMaterial);
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue