Files
StructureLib/src/main/java/com/gtnewhorizon/structurelib/StructureLib.java
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

157 lines
6.1 KiB
Java
Raw Normal View History

package com.gtnewhorizon.structurelib;
2021-05-17 07:44:45 +08:00
import net.minecraft.block.Block;
2021-05-27 13:32:38 +08:00
import net.minecraft.creativetab.CreativeTabs;
2021-05-29 19:05:50 +08:00
import net.minecraft.entity.player.EntityPlayer;
2021-05-27 13:32:38 +08:00
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
2022-08-23 18:57:17 +08:00
import net.minecraft.launchwrapper.Launch;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2021-05-17 07:44:45 +08:00
import com.gtnewhorizon.structurelib.block.BlockHint;
2022-08-23 12:29:59 +08:00
import com.gtnewhorizon.structurelib.command.CommandConfigureChannels;
2024-08-07 16:37:30 +08:00
import com.gtnewhorizon.structurelib.command.CommandRegistryDebug;
2021-05-17 07:44:45 +08:00
import com.gtnewhorizon.structurelib.item.ItemBlockHint;
import com.gtnewhorizon.structurelib.item.ItemConstructableTrigger;
2021-05-29 22:33:15 +08:00
import com.gtnewhorizon.structurelib.item.ItemFrontRotationTool;
2022-08-08 17:40:12 +08:00
import com.gtnewhorizon.structurelib.net.AlignmentMessage;
2022-08-24 12:22:02 +08:00
import com.gtnewhorizon.structurelib.net.ErrorHintParticleMessage;
2024-08-07 16:37:30 +08:00
import com.gtnewhorizon.structurelib.net.RegistryOrderSyncMessage;
2022-08-23 12:29:59 +08:00
import com.gtnewhorizon.structurelib.net.SetChannelDataMessage;
2022-08-08 17:40:12 +08:00
import com.gtnewhorizon.structurelib.net.UpdateHintParticleMessage;
2024-08-07 16:37:30 +08:00
import com.gtnewhorizon.structurelib.util.InventoryUtility;
import com.gtnewhorizon.structurelib.util.XSTR;
2022-08-25 16:09:16 +08:00
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
2024-08-07 16:37:30 +08:00
import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
2021-05-17 07:44:45 +08:00
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
2022-08-23 12:29:59 +08:00
import cpw.mods.fml.common.event.FMLServerStartingEvent;
2021-05-29 19:05:50 +08:00
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
2021-05-17 07:44:45 +08:00
import cpw.mods.fml.common.registry.GameRegistry;
2021-05-27 13:32:38 +08:00
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
2021-05-29 19:05:50 +08:00
/**
* This class does not contain a stable API. Refrain from using this class.
*/
2022-08-08 17:40:12 +08:00
@Mod(
modid = StructureLibAPI.MOD_ID,
name = "StructureLib",
version = "GRADLETOKEN_VERSION",
acceptableRemoteVersions = "*",
guiFactory = "com.gtnewhorizon.structurelib.GuiFactory")
public class StructureLib {
2022-08-25 16:09:16 +08:00
private static final String STRUCTURECOMPAT_MODID = "structurecompat";
2022-08-23 18:57:17 +08:00
public static boolean DEBUG_MODE;
2022-08-08 17:40:12 +08:00
public static boolean PANIC_MODE = Boolean.getBoolean("structurelib.panic");
2022-09-06 16:34:46 +08:00
public static final Logger LOGGER = LogManager.getLogger("StructureLib");
2021-05-29 19:05:50 +08:00
2022-08-08 17:40:12 +08:00
@SidedProxy(
serverSide = "com.gtnewhorizon.structurelib.CommonProxy",
clientSide = "com.gtnewhorizon.structurelib.ClientProxy")
2022-07-08 17:14:18 +08:00
static CommonProxy proxy;
2022-08-08 17:40:12 +08:00
2022-09-06 16:34:46 +08:00
static final SimpleNetworkWrapper net = NetworkRegistry.INSTANCE.newSimpleChannel(StructureLibAPI.MOD_ID);
2021-05-29 22:33:15 +08:00
2022-07-08 17:14:18 +08:00
static {
2022-08-08 17:40:12 +08:00
net.registerMessage(
AlignmentMessage.ServerHandler.class,
AlignmentMessage.AlignmentQuery.class,
0,
Side.SERVER);
2022-07-08 17:14:18 +08:00
net.registerMessage(AlignmentMessage.ClientHandler.class, AlignmentMessage.AlignmentData.class, 1, Side.CLIENT);
2022-08-08 17:40:12 +08:00
net.registerMessage(UpdateHintParticleMessage.Handler.class, UpdateHintParticleMessage.class, 2, Side.CLIENT);
2022-08-23 12:29:59 +08:00
net.registerMessage(SetChannelDataMessage.Handler.class, SetChannelDataMessage.class, 3, Side.SERVER);
2022-08-24 12:22:02 +08:00
net.registerMessage(ErrorHintParticleMessage.Handler.class, ErrorHintParticleMessage.class, 4, Side.CLIENT);
2024-08-07 16:37:30 +08:00
net.registerMessage(RegistryOrderSyncMessage.Handler.class, RegistryOrderSyncMessage.class, 5, Side.SERVER);
2022-08-23 18:57:17 +08:00
try {
DEBUG_MODE = Boolean.parseBoolean(System.getProperty("structurelib.debug"));
} catch (IllegalArgumentException | NullPointerException e) {
// turn on debug by default in dev mode
// this will be overridden if above property is present and set to false
DEBUG_MODE = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
}
2022-07-08 17:14:18 +08:00
}
2021-05-29 19:05:50 +08:00
2022-07-08 17:14:18 +08:00
public static final XSTR RANDOM = new XSTR();
2021-05-17 07:44:45 +08:00
2022-08-23 12:29:59 +08:00
@Mod.Instance
static StructureLib INSTANCE;
2022-08-25 16:09:16 +08:00
static Object COMPAT;
2022-07-08 17:14:18 +08:00
static Block blockHint;
static Item itemBlockHint;
static Item itemFrontRotationTool;
static Item itemConstructableTrigger;
public static final CreativeTabs creativeTab = new CreativeTabs("structurelib") {
2022-07-08 17:14:18 +08:00
@Override
@SideOnly(Side.CLIENT)
public Item getTabIconItem() {
return StructureLibAPI.getItemBlockHint();
}
};
2021-05-17 07:44:45 +08:00
2022-07-08 17:14:18 +08:00
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent e) {
ConfigurationHandler.INSTANCE.init(e.getSuggestedConfigurationFile());
GameRegistry.registerBlock(blockHint = new BlockHint(), ItemBlockHint.class, "blockhint");
itemBlockHint = ItemBlock.getItemFromBlock(StructureLibAPI.getBlockHint());
2022-08-08 17:40:12 +08:00
GameRegistry.registerItem(
itemFrontRotationTool = new ItemFrontRotationTool(),
itemFrontRotationTool.getUnlocalizedName());
GameRegistry.registerItem(
itemConstructableTrigger = new ItemConstructableTrigger(),
itemConstructableTrigger.getUnlocalizedName());
2022-07-08 17:14:18 +08:00
proxy.preInit(e);
2022-08-23 12:29:59 +08:00
NetworkRegistry.INSTANCE.registerGuiHandler(instance(), new GuiHandler());
2022-08-25 16:09:16 +08:00
2024-08-07 16:37:30 +08:00
InventoryUtility.init();
2022-08-25 16:09:16 +08:00
if (Loader.isModLoaded(STRUCTURECOMPAT_MODID)) {
COMPAT = Loader.instance().getIndexedModList().get(STRUCTURECOMPAT_MODID).getMod();
}
2022-08-23 12:29:59 +08:00
}
2024-08-07 16:37:30 +08:00
@Mod.EventHandler
public void loadComplete(FMLLoadCompleteEvent e) {
proxy.loadComplete(e);
}
2022-08-23 12:29:59 +08:00
@Mod.EventHandler
public void serverStarting(FMLServerStartingEvent e) {
e.registerServerCommand(new CommandConfigureChannels());
2024-08-07 16:37:30 +08:00
e.registerServerCommand(new CommandRegistryDebug());
2022-07-08 17:14:18 +08:00
}
2021-05-29 19:05:50 +08:00
2022-07-08 17:14:18 +08:00
public static void addClientSideChatMessages(String... messages) {
proxy.addClientSideChatMessages(messages);
}
2021-05-29 19:05:50 +08:00
2022-07-08 17:14:18 +08:00
public static EntityPlayer getCurrentPlayer() {
return proxy.getCurrentPlayer();
}
2021-05-29 19:05:50 +08:00
2022-07-08 17:14:18 +08:00
public static boolean isCurrentPlayer(EntityPlayer player) {
return proxy.isCurrentPlayer(player);
}
2022-08-08 17:40:12 +08:00
public static long getOverworldTime() {
return proxy.getOverworldTime();
}
2022-08-23 12:29:59 +08:00
public static StructureLib instance() {
return INSTANCE;
}
public CommonProxy proxy() {
return proxy;
}
}