mirror of
https://github.com/GTNewHorizons/Postea.git
synced 2026-11-20 04:09:43 +00:00
Merge branch 'mixins'
This commit is contained in:
commit
0673c15af9
19 files changed
+201
-258
No files matched your search
@@ -35,4 +35,5 @@
|
||||
*/
|
||||
dependencies {
|
||||
api('com.github.GTNewHorizons:SpongePoweredMixin:0.8.5-GTNH-2:dev')
|
||||
//api('com.github.GTNewHorizons:GT5-Unofficial:5.09.44.30:dev')
|
||||
}
|
||||
+8
-8
@@ -1,9 +1,9 @@
|
||||
modName = MyMod
|
||||
modName = Postea
|
||||
|
||||
# This is a case-sensitive string to identify your mod. Convention is to use lower case.
|
||||
modId = mymodid
|
||||
modId = postea
|
||||
|
||||
modGroup = com.myname.mymodid
|
||||
modGroup = com.colen.postea
|
||||
|
||||
# WHY is there no version field?
|
||||
# The build script relies on git to provide a version via tags. It is super easy and will enable you to always know the
|
||||
@@ -37,7 +37,7 @@ enableModernJavaSyntax = true
|
||||
enableGenericInjection = false
|
||||
|
||||
# Generate a class with String fields for the mod id, name, version and group name named with the fields below
|
||||
generateGradleTokenClass = com.myname.mymodid.Tags
|
||||
generateGradleTokenClass = com.colen.postea.Tags
|
||||
gradleTokenModId = MODID
|
||||
gradleTokenModName = MODNAME
|
||||
gradleTokenVersion = VERSION
|
||||
@@ -61,17 +61,17 @@ apiPackage =
|
||||
accessTransformersFile =
|
||||
|
||||
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
|
||||
usesMixins = false
|
||||
usesMixins = true
|
||||
# Adds some debug arguments like verbose output and export
|
||||
usesMixinDebug = false
|
||||
usesMixinDebug = true
|
||||
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
|
||||
mixinPlugin =
|
||||
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
|
||||
mixinsPackage =
|
||||
mixinsPackage = mixins
|
||||
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
|
||||
# This parameter is for legacy compatibility only
|
||||
# Example value: coreModClass = asm.FMLPlugin + modGroup = com.myname.mymodid -> com.myname.mymodid.asm.FMLPlugin
|
||||
coreModClass =
|
||||
coreModClass = mixins.PosteaLoadingPlugin
|
||||
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
|
||||
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
|
||||
containsMixinsAndOrCoreModOnly = false
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.colen.postea.API;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
public class ItemStackKey {
|
||||
|
||||
private final Item item;
|
||||
private final int meta;
|
||||
|
||||
public ItemStackKey(Item item, int meta) {
|
||||
this.item = item;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) return false;
|
||||
if (o instanceof ItemStackKey that) {
|
||||
return (this.meta == that.meta) && (this.item == that.item);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(item, meta);
|
||||
}
|
||||
|
||||
public int getDamage() {
|
||||
return meta;
|
||||
}
|
||||
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.colen.postea.API;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
public class ReplacementManager {
|
||||
|
||||
private static final Map<ItemStackKey, ItemStackKey> replacementMap = new HashMap<>();
|
||||
|
||||
// Public API for adding replacements.
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static void addReplacement(Item itemIn, int metaIn, Item itemOut, int metaOut) {
|
||||
replacementMap.put(new ItemStackKey(itemIn, metaIn), new ItemStackKey(itemOut, metaOut));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static ItemStackKey getReplacement(Item itemIn, int metaIn) {
|
||||
return replacementMap.getOrDefault(new ItemStackKey(itemIn, metaIn), null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.colen.postea;
|
||||
|
||||
import cpw.mods.fml.common.Mod;
|
||||
|
||||
@Mod(modid = Tags.MODID, version = Tags.VERSION, name = Tags.MODNAME, acceptedMinecraftVersions = "[1.7.10]")
|
||||
@SuppressWarnings("unused")
|
||||
public class Postea {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.colen.postea.mixins;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.gtnewhorizon.gtnhmixins.IEarlyMixinLoader;
|
||||
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
||||
|
||||
@IFMLLoadingPlugin.MCVersion("1.7.10")
|
||||
public final class PosteaLoadingPlugin implements IEarlyMixinLoader, IFMLLoadingPlugin {
|
||||
|
||||
@Override
|
||||
public String[] getASMTransformerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessTransformerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModContainerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSetupClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectData(Map<String, Object> data) {}
|
||||
|
||||
@Override
|
||||
public String getMixinConfig() {
|
||||
return "mixins.postea.early.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMixins(Set<String> loadedCoreMods) {
|
||||
final List<String> mixins = new ArrayList<>();
|
||||
mixins.add("MixinItemStack");
|
||||
|
||||
return mixins;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.colen.postea.mixins.early;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.colen.postea.API.ItemStackKey;
|
||||
import com.colen.postea.API.ReplacementManager;
|
||||
|
||||
@Mixin(ItemStack.class)
|
||||
public abstract class MixinItemStack {
|
||||
|
||||
@Shadow
|
||||
private int itemDamage; // Metadata
|
||||
@Shadow
|
||||
private Item field_151002_e;
|
||||
|
||||
@Inject(method = "<init>(Lnet/minecraft/item/Item;II)V", at = @At("RETURN"))
|
||||
private void onConstructorReturn(Item item, int size, int metadata, CallbackInfo ci) {
|
||||
ItemStackKey replacement = ReplacementManager.getReplacement(item, metadata);
|
||||
|
||||
if (replacement == null) return;
|
||||
|
||||
// Edit private variables here.
|
||||
itemDamage = replacement.getDamage();
|
||||
func_150996_a(replacement.getItem());
|
||||
}
|
||||
|
||||
@Inject(method = "readFromNBT(Lnet/minecraft/nbt/NBTTagCompound;)V", at = @At("RETURN"))
|
||||
private void onReadFromNBTReturn(NBTTagCompound p_77963_1_, CallbackInfo ci) {
|
||||
ItemStackKey replacement = ReplacementManager.getReplacement(field_151002_e, itemDamage);
|
||||
|
||||
if (replacement == null) return;
|
||||
|
||||
func_150996_a(replacement.getItem());
|
||||
itemDamage = replacement.getDamage();
|
||||
}
|
||||
|
||||
@Unique
|
||||
public native void func_150996_a(Item p_150996_1_);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package com.myname.mymodid;
|
||||
|
||||
public class ClientProxy extends CommonProxy {
|
||||
|
||||
// Override CommonProxy methods here, if you want a different behaviour on the client (e.g. registering renders).
|
||||
// Don't forget to call the super methods as well.
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.myname.mymodid;
|
||||
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
|
||||
public class CommonProxy {
|
||||
|
||||
// preInit "Run before anything else. Read your config, create blocks, items, etc, and register them with the
|
||||
// GameRegistry." (Remove if not needed)
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
Config.synchronizeConfiguration(event.getSuggestedConfigurationFile());
|
||||
|
||||
MyMod.LOG.info(Config.greeting);
|
||||
MyMod.LOG.info("I am " + Tags.MODNAME + " at version " + Tags.VERSION);
|
||||
}
|
||||
|
||||
// load "Do your mod setup. Build whatever data structures you care about. Register recipes." (Remove if not needed)
|
||||
public void init(FMLInitializationEvent event) {}
|
||||
|
||||
// postInit "Handle interaction with other mods, complete your setup based on this." (Remove if not needed)
|
||||
public void postInit(FMLPostInitializationEvent event) {}
|
||||
|
||||
// register server commands in this event handler (Remove if not needed)
|
||||
public void serverStarting(FMLServerStartingEvent event) {}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.myname.mymodid;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
|
||||
public class Config {
|
||||
|
||||
public static String greeting = "Hello World";
|
||||
|
||||
public static void synchronizeConfiguration(File configFile) {
|
||||
Configuration configuration = new Configuration(configFile);
|
||||
|
||||
greeting = configuration.getString("greeting", Configuration.CATEGORY_GENERAL, greeting, "How shall I greet?");
|
||||
|
||||
if (configuration.hasChanged()) {
|
||||
configuration.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.myname.mymodid;
|
||||
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ItemStackKey {
|
||||
private final String modId;
|
||||
private final String itemName;
|
||||
private final int meta;
|
||||
|
||||
public ItemStackKey(String modId, String itemName, int meta) {
|
||||
this.modId = modId;
|
||||
this.itemName = itemName;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
public ItemStackKey(ItemStack stack) {
|
||||
this(stack.getItem().getUnlocalizedName().substring(4),
|
||||
GameRegistry.findUniqueIdentifierFor(stack.getItem()).modId,
|
||||
stack.getItemDamage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ItemStackKey that = (ItemStackKey) o;
|
||||
return meta == that.meta &&
|
||||
Objects.equals(modId, that.modId) &&
|
||||
Objects.equals(itemName, that.itemName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(modId, itemName, meta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
package com.myname.mymodid;
|
||||
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ItemStack.class)
|
||||
public abstract class MixinItemStack{
|
||||
|
||||
@Inject(method = "<init>(Lnet/minecraft/item/Item;II)V", at = @At("HEAD"))
|
||||
private void onConstructorHead(Item item, int stackSize, int metadata, CallbackInfo ci) {
|
||||
System.out.println(item.getUnlocalizedName() + " " + metadata + " " + stackSize);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
package com.myname.mymodid;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLServerStartingEvent;
|
||||
import org.spongepowered.asm.launch.MixinBootstrap;
|
||||
import org.spongepowered.asm.mixin.Mixins;
|
||||
|
||||
@Mod(modid = Tags.MODID, version = Tags.VERSION, name = Tags.MODNAME, acceptedMinecraftVersions = "[1.7.10]")
|
||||
public class MyMod {
|
||||
|
||||
public static final Logger LOG = LogManager.getLogger(Tags.MODID);
|
||||
|
||||
@SidedProxy(clientSide = "com.myname.mymodid.ClientProxy", serverSide = "com.myname.mymodid.CommonProxy")
|
||||
public static CommonProxy proxy;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
MixinBootstrap.init();
|
||||
Mixins.addConfiguration("mixins.json");
|
||||
|
||||
proxy.preInit(event);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
// load "Do your mod setup. Build whatever data structures you care about. Register recipes." (Remove if not needed)
|
||||
public void init(FMLInitializationEvent event) {
|
||||
proxy.init(event);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
// postInit "Handle interaction with other mods, complete your setup based on this." (Remove if not needed)
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
proxy.postInit(event);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
// register server commands in this event handler (Remove if not needed)
|
||||
public void serverStarting(FMLServerStartingEvent event) {
|
||||
proxy.serverStarting(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.myname.mymodid;
|
||||
|
||||
import com.falsepattern.gasstation.IEarlyMixinLoader;
|
||||
import cpw.mods.fml.relauncher.FMLLaunchHandler;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
||||
import jdk.jfr.Name;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@IFMLLoadingPlugin.TransformerExclusions({ "mods.mymod" })
|
||||
@Name("mymod")
|
||||
@IFMLLoadingPlugin.SortingIndex(1500)
|
||||
@IFMLLoadingPlugin.MCVersion("1.7.10")
|
||||
public final class PosteaLoadingPlugin implements IEarlyMixinLoader, IFMLLoadingPlugin {
|
||||
|
||||
public static final String ItemStackTransformer = "mods.battlegear2.coremod.transformers.EntityPlayerTransformer";
|
||||
|
||||
public static File debugOutputLocation;
|
||||
public static final String[] transformers = new String[] { ItemStackTransformer };
|
||||
|
||||
@Override
|
||||
public String[] getASMTransformerClass() {
|
||||
return transformers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAccessTransformerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModContainerClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSetupClass() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectData(Map<String, Object> data) {
|
||||
debugOutputLocation = new File(data.get("mcLocation").toString(), "ItemStack edited classes");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getMixinConfigs() {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("mixins.json" );
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.myname.mymodid;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ReplacementManager {
|
||||
private static final Map<ItemStackKey, ItemStack> replacementMap = new HashMap<>();
|
||||
|
||||
public static void addReplacement(String modId, String itemName, int meta, ItemStack replacement) {
|
||||
replacementMap.put(new ItemStackKey(modId, itemName, meta), replacement);
|
||||
}
|
||||
|
||||
public static ItemStack getReplacement(ItemStack original) {
|
||||
return replacementMap.getOrDefault(new ItemStackKey(original), original);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
"modList": [{
|
||||
"modid": "${modId}",
|
||||
"name": "${modName}",
|
||||
"description": "An example mod for Minecraft 1.7.10 with Forge focused on a stable setup.",
|
||||
"description": "Utility mod for converting ItemStacks.",
|
||||
"version": "${modVersion}",
|
||||
"mcversion": "${minecraftVersion}",
|
||||
"url": "https://github.com/SinTh0r4s/MyMod",
|
||||
"updateUrl": "",
|
||||
"authorList": ["SinTho0r4s"],
|
||||
"authorList": ["Colen"],
|
||||
"credits": "",
|
||||
"logoFile": "",
|
||||
"screenshots": [],
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"required": true,
|
||||
"package": "com.myname.mymodid",
|
||||
"mixins": [
|
||||
"MixinItemStack"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8.5-GTNH",
|
||||
"package": "com.colen.postea.mixins.early",
|
||||
"refmap": "mixins.postea.refmap.json",
|
||||
"target": "@env(DEFAULT)",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [
|
||||
"MixinItemStack"
|
||||
],
|
||||
"client": [],
|
||||
"server": []
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8.5-GTNH",
|
||||
"refmap": "mixins.postea.refmap.json",
|
||||
"target": "@env(DEFAULT)",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"mixins": [],
|
||||
"client": [],
|
||||
"server": []
|
||||
}
|
||||
Reference in new issue
Block a user