-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
asbyth
committed
Jan 11, 2020
0 parents
commit 7fc2114
Showing
14 changed files
with
424 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# eclipse | ||
eclipse | ||
bin | ||
*.launch | ||
.settings | ||
.metadata | ||
.classpath | ||
.project | ||
|
||
# idea | ||
out | ||
classes | ||
*.ipr | ||
*.iws | ||
*.iml | ||
.idea | ||
|
||
# gradle | ||
build | ||
.gradle | ||
|
||
#Netbeans | ||
.nb-gradle | ||
.nb-gradle-properties | ||
|
||
# other | ||
run | ||
.DS_Store | ||
Thumbs.db |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
buildscript { | ||
repositories { | ||
jcenter() | ||
maven { | ||
name = "forge" | ||
url = "https://files.minecraftforge.net/maven" | ||
} | ||
} | ||
dependencies { | ||
classpath "net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT" | ||
} | ||
} | ||
|
||
apply plugin: "net.minecraftforge.gradle.forge" | ||
|
||
version = modVersion | ||
group = modGroup | ||
archivesBaseName = modBaseName | ||
|
||
sourceCompatibility = targetCompatibility = 1.8 | ||
|
||
minecraft { | ||
version = project.forgeVersion | ||
runDir = "run" | ||
|
||
// the mappings can be changed at any time, and must be in the following format. | ||
// snapshot_YYYYMMDD snapshot are built nightly. | ||
// stable_# stables are built at the discretion of the MCP team. | ||
// Use non-default mappings at your own risk. they may not always work. | ||
// simply re-run your setup task after changing the mappings to update your workspace. | ||
mappings = project.mcpVersion | ||
// makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
} | ||
|
||
processResources { | ||
// this will ensure that this task is redone when the versions change. | ||
inputs.property "version", project.version | ||
inputs.property "mcversion", project.minecraft.version | ||
|
||
// replace stuff in mcmod.info, nothing else | ||
from(sourceSets.main.resources.srcDirs) { | ||
include "mcmod.info" | ||
|
||
// replace version and mcversion | ||
expand "version": project.version, "mcversion": project.minecraft.version | ||
} | ||
|
||
// copy everything else, thats not the mcmod.info | ||
from(sourceSets.main.resources.srcDirs) { | ||
exclude "mcmod.info" | ||
} | ||
} | ||
|
||
jar { | ||
manifest { | ||
attributes("FMLCorePlugin": "club.sk1er.items.tweaker.ItemTweaker", "ForceLoadAsMod": true, FMLCorePluginContainsFMLMod: true, "ModSide": "CLIENT") | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
modGroup=club.sk1er | ||
modVersion=1.0 | ||
modBaseName=ItemOptimizations | ||
forgeVersion=1.8.9-11.15.1.2318-1.8.9 | ||
mcpVersion=stable_22 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Fri Jan 10 20:36:02 EST 2020 | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStorePath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<p>Item Optimizations provides a minor optimization to item searching & disables the enchantment glint on both potions and enchanted books, allowing for better performance in situations where there could be a lot of them on the ground.</p> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
mod_id=item_optimization | ||
display_name=Item Optimizations | ||
not_complete=false | ||
hide=false |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package club.sk1er.items; | ||
|
||
import net.minecraftforge.fml.common.Mod; | ||
|
||
@Mod(modid = "item_optimization", name = "Item Optimization", version = "1.0") | ||
public class ItemOptimization { | ||
} |
70 changes: 70 additions & 0 deletions
70
src/main/java/club/sk1er/items/asm/EntityItemTransformer.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package club.sk1er.items.asm; | ||
|
||
import club.sk1er.items.tweaker.transform.ItemTransformer; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.FieldInsnNode; | ||
import org.objectweb.asm.tree.InsnList; | ||
import org.objectweb.asm.tree.InsnNode; | ||
import org.objectweb.asm.tree.JumpInsnNode; | ||
import org.objectweb.asm.tree.LabelNode; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
import org.objectweb.asm.tree.VarInsnNode; | ||
|
||
public class EntityItemTransformer implements ItemTransformer { | ||
@Override | ||
public String[] getClassNames() { | ||
return new String[]{"net.minecraft.entity.item.EntityItem"}; | ||
} | ||
|
||
@Override | ||
public void transform(ClassNode classNode, String name) { | ||
for (MethodNode methodNode : classNode.methods) { | ||
String methodName = mapMethodName(classNode, methodNode); | ||
|
||
if (methodName.equals("searchForOtherItemsNearby") || methodName.equals("func_85054_d")) { | ||
methodNode.instructions.insertBefore(methodNode.instructions.getFirst(), stopSearch()); | ||
} | ||
|
||
if (methodName.equals("combineItems") || methodName.equals("func_70289_a")) { | ||
methodNode.instructions.insertBefore(methodNode.instructions.getFirst(), stopSearchBoolean()); | ||
} | ||
} | ||
} | ||
|
||
private InsnList stopSearch() { | ||
InsnList list = new InsnList(); | ||
list.add(new VarInsnNode(Opcodes.ALOAD, 0)); | ||
list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "net/minecraft/entity/item/EntityItem", "func_92059_d", | ||
"()Lnet/minecraft/item/ItemStack;", false)); | ||
list.add(new VarInsnNode(Opcodes.ASTORE, 1)); | ||
list.add(new VarInsnNode(Opcodes.ALOAD, 1)); | ||
list.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/item/ItemStack", "field_77994_a", "I")); | ||
list.add(new VarInsnNode(Opcodes.ALOAD, 1)); | ||
list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "net/minecraft/item/ItemStack", "func_77976_d", "()I", false)); | ||
LabelNode ificmplt = new LabelNode(); | ||
list.add(new JumpInsnNode(Opcodes.IF_ICMPLT, ificmplt)); | ||
list.add(new InsnNode(Opcodes.RETURN)); | ||
list.add(ificmplt); | ||
return list; | ||
} | ||
|
||
private InsnList stopSearchBoolean() { | ||
InsnList list = new InsnList(); | ||
list.add(new VarInsnNode(Opcodes.ALOAD, 0)); | ||
list.add(new MethodInsnNode(Opcodes.INVOKESPECIAL, "net/minecraft/entity/item/EntityItem", "func_92059_d", | ||
"()Lnet/minecraft/item/ItemStack;", false)); | ||
list.add(new VarInsnNode(Opcodes.ASTORE, 2)); | ||
list.add(new VarInsnNode(Opcodes.ALOAD, 2)); | ||
list.add(new FieldInsnNode(Opcodes.GETFIELD, "net/minecraft/item/ItemStack", "field_77994_a", "I")); | ||
list.add(new VarInsnNode(Opcodes.ALOAD, 2)); | ||
list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "net/minecraft/item/ItemStack", "func_77976_d", "()I", false)); | ||
LabelNode labelNode = new LabelNode(); | ||
list.add(new JumpInsnNode(Opcodes.IF_ICMPLT, labelNode)); | ||
list.add(new InsnNode(Opcodes.ICONST_0)); | ||
list.add(new InsnNode(Opcodes.IRETURN)); | ||
list.add(labelNode); | ||
return list; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/club/sk1er/items/asm/ItemEnchantedBookTransformer.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package club.sk1er.items.asm; | ||
|
||
import club.sk1er.items.tweaker.transform.ItemTransformer; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.InsnList; | ||
import org.objectweb.asm.tree.InsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
|
||
public class ItemEnchantedBookTransformer implements ItemTransformer { | ||
@Override | ||
public String[] getClassNames() { | ||
return new String[]{"net.minecraft.item.ItemEnchantedBook"}; | ||
} | ||
|
||
@Override | ||
public void transform(ClassNode classNode, String name) { | ||
for (MethodNode methodNode : classNode.methods) { | ||
String methodName = mapMethodName(classNode, methodNode); | ||
|
||
if (methodName.equals("hasEffect") || methodName.equals("func_77636_d")) { | ||
methodNode.instructions.clear(); | ||
methodNode.localVariables.clear(); | ||
methodNode.instructions.add(returnFalse()); | ||
} | ||
} | ||
} | ||
|
||
private InsnList returnFalse() { | ||
InsnList list = new InsnList(); | ||
list.add(new InsnNode(Opcodes.ICONST_0)); | ||
list.add(new InsnNode(Opcodes.IRETURN)); | ||
return list; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/club/sk1er/items/asm/ItemPotionTransformer.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package club.sk1er.items.asm; | ||
|
||
import club.sk1er.items.tweaker.transform.ItemTransformer; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.InsnList; | ||
import org.objectweb.asm.tree.InsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
|
||
public class ItemPotionTransformer implements ItemTransformer { | ||
@Override | ||
public String[] getClassNames() { | ||
return new String[]{"net.minecraft.item.ItemPotion"}; | ||
} | ||
|
||
@Override | ||
public void transform(ClassNode classNode, String name) { | ||
for (MethodNode methodNode : classNode.methods) { | ||
String methodName = mapMethodName(classNode, methodNode); | ||
|
||
if (methodName.equals("hasEffect") || methodName.equals("func_77636_d")) { | ||
methodNode.instructions.clear(); | ||
methodNode.localVariables.clear(); | ||
methodNode.instructions.add(returnFalse()); | ||
} | ||
} | ||
} | ||
|
||
private InsnList returnFalse() { | ||
InsnList list = new InsnList(); | ||
list.add(new InsnNode(Opcodes.ICONST_0)); | ||
list.add(new InsnNode(Opcodes.IRETURN)); | ||
return list; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/club/sk1er/items/tweaker/ClassTransformer.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package club.sk1er.items.tweaker; | ||
|
||
import club.sk1er.items.asm.EntityItemTransformer; | ||
import club.sk1er.items.asm.ItemEnchantedBookTransformer; | ||
import club.sk1er.items.tweaker.transform.ItemTransformer; | ||
import com.google.common.collect.ArrayListMultimap; | ||
import com.google.common.collect.Multimap; | ||
import club.sk1er.items.asm.ItemPotionTransformer; | ||
import net.minecraft.launchwrapper.IClassTransformer; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.tree.ClassNode; | ||
|
||
import java.util.Collection; | ||
|
||
public class ClassTransformer implements IClassTransformer { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger("ItemTransformer"); | ||
private final Multimap<String, ItemTransformer> transformerMap = ArrayListMultimap.create(); | ||
|
||
public ClassTransformer() { | ||
registerTransformer(new EntityItemTransformer()); | ||
registerTransformer(new ItemPotionTransformer()); | ||
registerTransformer(new ItemEnchantedBookTransformer()); | ||
} | ||
|
||
private void registerTransformer(ItemTransformer transformer) { | ||
for (String cls : transformer.getClassNames()) { | ||
transformerMap.put(cls, transformer); | ||
} | ||
} | ||
|
||
@Override | ||
public byte[] transform(String name, String transformedName, byte[] bytes) { | ||
if (bytes == null) return null; | ||
|
||
Collection<ItemTransformer> transformers = transformerMap.get(transformedName); | ||
if (transformers.isEmpty()) return bytes; | ||
|
||
LOGGER.info("Found {} transformers for {}", transformers.size(), transformedName); | ||
|
||
ClassReader classReader = new ClassReader(bytes); | ||
ClassNode classNode = new ClassNode(); | ||
classReader.accept(classNode, ClassReader.EXPAND_FRAMES); | ||
|
||
transformers.forEach(transformer -> { | ||
LOGGER.info("Applying transformer {} on {}...", transformer.getClass().getName(), transformedName); | ||
transformer.transform(classNode, transformedName); | ||
}); | ||
|
||
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); | ||
|
||
try { | ||
classNode.accept(classWriter); | ||
} catch (Throwable e) { | ||
System.out.println("Exception when transforming " + transformedName + " : " + e.getClass().getSimpleName()); | ||
e.printStackTrace(); | ||
} | ||
|
||
return classWriter.toByteArray(); | ||
} | ||
} |
Oops, something went wrong.