Initial commit

This commit is contained in:
Johann Bernhardt committed 2021-11-03 16:42:12 +01:00
1 parent 4101fb1d1c
commit 5a6afe6098
20 files changed
+1003

No files matched your search

@@ -0,0 +1,43 @@
package com.myname.mymodid;
import cpw.mods.fml.common.event.*;
public class ClientProxy extends CommonProxy {
// preInit "Run before anything else. Read your config, create blocks, items,
// etc, and register them with the GameRegistry."
public void preInit(FMLPreInitializationEvent event) {
super.preInit(event);
}
// load "Do your mod setup. Build whatever data structures you care about. Register recipes."
public void init(FMLInitializationEvent event) {
super.init(event);
}
// postInit "Handle interaction with other mods, complete your setup based on this."
public void postInit(FMLPostInitializationEvent event) {
super.postInit(event);
}
public void serverAboutToStart(FMLServerAboutToStartEvent event) {
super.serverAboutToStart(event);
}
// register server commands in this event handler
public void serverStarting(FMLServerStartingEvent event) {
super.serverStarting(event);
}
public void serverStarted(FMLServerStartedEvent event) {
super.serverStarted(event);
}
public void serverStopping(FMLServerStoppingEvent event) {
super.serverStopping(event);
}
public void serverStopped(FMLServerStoppedEvent event) {
super.serverStopped(event);
}
}
@@ -0,0 +1,46 @@
package com.myname.mymodid;
import cpw.mods.fml.common.event.*;
public class CommonProxy {
// preInit "Run before anything else. Read your config, create blocks, items,
// etc, and register them with the GameRegistry."
public void preInit(FMLPreInitializationEvent event) {
Config.syncronizeConfiguration(event.getSuggestedConfigurationFile());
MyMod.info(Config.greeting);
MyMod.info("I am " + Tags.MODNAME + " at version " + Tags.VERSION + " and group name " + Tags.GROUPNAME);
}
// load "Do your mod setup. Build whatever data structures you care about. Register recipes."
public void init(FMLInitializationEvent event) {
}
// postInit "Handle interaction with other mods, complete your setup based on this."
public void postInit(FMLPostInitializationEvent event) {
}
public void serverAboutToStart(FMLServerAboutToStartEvent event) {
}
// register server commands in this event handler
public void serverStarting(FMLServerStartingEvent event) {
}
public void serverStarted(FMLServerStartedEvent event) {
}
public void serverStopping(FMLServerStoppingEvent event) {
}
public void serverStopped(FMLServerStoppedEvent event) {
}
}
@@ -0,0 +1,31 @@
package com.myname.mymodid;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;
import java.io.File;
public class Config {
private static class Defaults {
public static final String greeting = "Hello World";
}
private static class Categories {
public static final String general = "general";
}
public static String greeting = Defaults.greeting;
public static void syncronizeConfiguration(File configFile) {
Configuration configuration = new Configuration(configFile);
configuration.load();
Property greetingProperty = configuration.get(Categories.general, "greeting", Defaults.greeting, "How shall I greet?");
greeting = greetingProperty.getString();
if(configuration.hasChanged()) {
configuration.save();
}
}
}
@@ -0,0 +1,77 @@
package com.myname.mymodid;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@Mod(modid = Tags.MODID, version = Tags.VERSION, name = Tags.MODNAME, acceptedMinecraftVersions = "[1.7.10]")
public class MyMod {
private static Logger LOG = LogManager.getLogger(Tags.MODID);
@SidedProxy(clientSide= Tags.GROUPNAME + ".ClientProxy", serverSide=Tags.GROUPNAME + ".CommonProxy")
public static CommonProxy proxy;
@Mod.EventHandler
// preInit "Run before anything else. Read your config, create blocks, items,
// etc, and register them with the GameRegistry."
public void preInit(FMLPreInitializationEvent event) {
proxy.preInit(event);
}
@Mod.EventHandler
// load "Do your mod setup. Build whatever data structures you care about. Register recipes."
public void init(FMLInitializationEvent event) {
proxy.init(event);
}
@Mod.EventHandler
// postInit "Handle interaction with other mods, complete your setup based on this."
public void postInit(FMLPostInitializationEvent event) {
proxy.postInit(event);
}
@Mod.EventHandler
public void serverAboutToStart(FMLServerAboutToStartEvent event) {
proxy.serverAboutToStart(event);
}
@Mod.EventHandler
// register server commands in this event handler
public void serverStarting(FMLServerStartingEvent event) {
proxy.serverStarting(event);
}
@Mod.EventHandler
public void serverStarted(FMLServerStartedEvent event) {
proxy.serverStarted(event);
}
@Mod.EventHandler
public void serverStopping(FMLServerStoppingEvent event) {
proxy.serverStopping(event);
}
@Mod.EventHandler
public void serverStopped(FMLServerStoppedEvent event) {
proxy.serverStopped(event);
}
public static void debug(String message) {
LOG.debug(message);
}
public static void info(String message) {
LOG.info(message);
}
public static void warn(String message) {
LOG.warn(message);
}
public static void error(String message) {
LOG.error(message);
}
}
@@ -0,0 +1,9 @@
package com.myname.mymodid;
public class Tags {
public static final String MODID = "GRADLETOKEN_MODID";
public static final String MODNAME = "GRADLETOKEN_MODNAME";
public static final String VERSION = "GRADLETOKEN_VERSION";
public static final String GROUPNAME = "GRADLETOKEN_GROUPNAME";
}
@@ -0,0 +1,92 @@
package com.myname.mymodid.mixinplugin;
import com.myname.mymodid.Tags;
import cpw.mods.fml.relauncher.FMLLaunchHandler;
import net.minecraft.launchwrapper.Launch;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.spongepowered.asm.lib.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import ru.timeconqueror.spongemixins.MinecraftURLClassPath;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class MixinPlugin implements IMixinConfigPlugin {
private static Logger LOG = LogManager.getLogger(Tags.MODID);
@Override
public void onLoad(String mixinPackage) {
}
@Override
public String getRefMapperConfig() {
return null;
}
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
return true;
}
@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {
}
@Override
public List<String> getMixins() {
final boolean loadClientSideOnlyClasses = FMLLaunchHandler.side().isClient();
final boolean isDevelopmentEnvironment = (boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
List<String> mixins = new ArrayList<>();
mixins.add("minecraft.ItemEditableBookMixin");
if(isDevelopmentEnvironment || loadJar("gregtech")) {
LOG.info("Found GregTech! Integrating now...");
//mixins.add("gregtech.SOMEGTMIXINEXAMPLE");
}
else {
LOG.info("Could not find GregTech! Skipping integration....");
}
return mixins;
}
private boolean loadJar(final String jarNameBeginsWith) {
try {
File jar = MinecraftURLClassPath.getJarInModPath(jarNameBeginsWith);
if(jar == null) {
LOG.info("Jar not found: " + jarNameBeginsWith);
return false;
}
LOG.info("Attempting to add " + jar.toString() + " to the URL Class Path");
if(!jar.exists()) {
throw new FileNotFoundException(jar.toString());
}
MinecraftURLClassPath.addJar(jar);
return true;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
}
@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
}
}
@@ -0,0 +1,24 @@
package com.myname.mymodid.mixins.minecraft;
import com.myname.mymodid.MyMod;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemEditableBook;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
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.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(value = ItemEditableBook.class)
public class ItemEditableBookMixin {
@Inject(method = "onItemRightClick",
at = @At("HEAD"),
require = 1,
locals = LocalCapture.CAPTURE_FAILEXCEPTION)
private void onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer, CallbackInfoReturnable<ItemStack> callbackInfoReturnable) {
MyMod.info("You are reading a book");
}
}