First work to 1.14
Updated core mod file following examples from McJty's example 1.14 mod
This commit is contained in:
84
src/main/java/com/example/examplemod/ExampleMod.java
Normal file
84
src/main/java/com/example/examplemod/ExampleMod.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package com.example.examplemod;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.InterModComms;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
|
||||
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
// The value here should match an entry in the META-INF/mods.toml file
|
||||
@Mod("examplemod")
|
||||
public class ExampleMod
|
||||
{
|
||||
// Directly reference a log4j logger.
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
public ExampleMod() {
|
||||
// Register the setup method for modloading
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
|
||||
// Register the enqueueIMC method for modloading
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
|
||||
// Register the processIMC method for modloading
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
|
||||
// Register the doClientStuff method for modloading
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
|
||||
|
||||
// Register ourselves for server and other game events we are interested in
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
private void setup(final FMLCommonSetupEvent event)
|
||||
{
|
||||
// some preinit code
|
||||
LOGGER.info("HELLO FROM PREINIT");
|
||||
LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
|
||||
}
|
||||
|
||||
private void doClientStuff(final FMLClientSetupEvent event) {
|
||||
// do something that can only be done on the client
|
||||
LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
|
||||
}
|
||||
|
||||
private void enqueueIMC(final InterModEnqueueEvent event)
|
||||
{
|
||||
// some example code to dispatch IMC to another mod
|
||||
InterModComms.sendTo("examplemod", "helloworld", () -> { LOGGER.info("Hello world from the MDK"); return "Hello world";});
|
||||
}
|
||||
|
||||
private void processIMC(final InterModProcessEvent event)
|
||||
{
|
||||
// some example code to receive and process InterModComms from other mods
|
||||
LOGGER.info("Got IMC {}", event.getIMCStream().
|
||||
map(m->m.getMessageSupplier().get()).
|
||||
collect(Collectors.toList()));
|
||||
}
|
||||
// You can use SubscribeEvent and let the Event Bus discover methods to call
|
||||
@SubscribeEvent
|
||||
public void onServerStarting(FMLServerStartingEvent event) {
|
||||
// do something when the server starts
|
||||
LOGGER.info("HELLO from server starting");
|
||||
}
|
||||
|
||||
// You can use EventBusSubscriber to automatically subscribe events on the contained class (this is subscribing to the MOD
|
||||
// Event bus for receiving Registry Events)
|
||||
@Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
|
||||
public static class RegistryEvents {
|
||||
@SubscribeEvent
|
||||
public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
|
||||
// register a new block here
|
||||
LOGGER.info("HELLO from Register Block");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,8 @@ import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.yseven.findyourway.CommonProxy;
|
||||
import net.yseven.findyourway.setup.ClientProxy;
|
||||
import net.yseven.findyourway.setup.ServerProxy;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
@@ -97,9 +98,9 @@ public class AngleGetter implements IItemPropertyGetter {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private void setBlockPos(ItemStack stack) {
|
||||
for (int i = 0; i < CommonProxy.compassList.size(); i++) {
|
||||
if (stack.getItem().getUnlocalizedName().equals(CommonProxy.compassList.get(i).getUnlocalizedName())) {
|
||||
blockPos = CommonProxy.compassList.get(i).getStructurePos();
|
||||
for (int i = 0; i < ServerProxy.compassList.size(); i++) {
|
||||
if (stack.getItem().getUnlocalizedName().equals(ServerProxy.compassList.get(i).getUnlocalizedName())) {
|
||||
blockPos = ServerProxy.compassList.get(i).getStructurePos();
|
||||
} else {
|
||||
if (!ClientProxy.hasAngleErrrored()) {
|
||||
System.out.println("unable to get blockPos from compassList in AngleGetter class");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.yseven.findyourway;
|
||||
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.yseven.findyourway.setup.ServerProxy;
|
||||
|
||||
public class Config {
|
||||
private static final String CATEGORY_GENERAL = "ggeneral";
|
||||
@@ -12,7 +13,7 @@ public class Config {
|
||||
public static boolean useVillageCompass = true;
|
||||
|
||||
public static void readConfig() {
|
||||
Configuration cfg = CommonProxy.config;
|
||||
Configuration cfg = ServerProxy.config;
|
||||
try {
|
||||
cfg.load();
|
||||
initGeneralConfig(cfg);
|
||||
|
||||
@@ -1,37 +1,43 @@
|
||||
package net.yseven.findyourway;
|
||||
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.SidedProxy;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.yseven.findyourway.setup.ClientProxy;
|
||||
import net.yseven.findyourway.setup.IProxy;
|
||||
import net.yseven.findyourway.setup.ModSetup;
|
||||
import net.yseven.findyourway.setup.ServerProxy;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
@Mod(modid = FindYourWay.modId, name = FindYourWay.name, version = FindYourWay.version)
|
||||
@Mod("findyourway")
|
||||
public class FindYourWay {
|
||||
public static final String modId = "findyourway";
|
||||
public static final String name = "Find Your Way";
|
||||
public static final String version = "1.2.1";
|
||||
//TODO Fix the ServerProxy and ClientProxy and add both to the setup package
|
||||
public static IProxy proxy = DistExecutor.runForDist(() -> () -> new ClientProxy(), () -> () -> new ServerProxy())
|
||||
|
||||
@Mod.Instance(modId)
|
||||
public static FindYourWay instance;
|
||||
public static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
@SidedProxy(serverSide = "net.yseven.findyourway.CommonProxy", clientSide = "net.yseven.findyourway.Client.ClientProxy")
|
||||
public static CommonProxy proxy;
|
||||
public static ModSetup setup = new ModSetup();
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
proxy.preInit(event);
|
||||
public FindYourWay() {
|
||||
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
proxy.init(event);
|
||||
private void setup(final FMLCommonSetupEvent event) {
|
||||
setup.init();
|
||||
proxy.init();
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
proxy.postInit(event);
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public static class RegistryEvents {
|
||||
@SubscribeEvent
|
||||
public static void onItemsRegistry(final RegistryEvent.Register<Item> event) {
|
||||
Item.Properties properties = new Item.Properties().group(setup.itemGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.yseven.findyourway.CommonProxy;
|
||||
import net.yseven.findyourway.setup.ServerProxy;
|
||||
|
||||
public class MessageHandlerOnServer implements IMessageHandler<MessageToServer, IMessage> {
|
||||
public IMessage onMessage(final MessageToServer message, MessageContext ctx) {
|
||||
@@ -43,7 +43,7 @@ public class MessageHandlerOnServer implements IMessageHandler<MessageToServer,
|
||||
|
||||
MessageToClient msg = new MessageToClient(structurePos, message.getCompass());
|
||||
if (dimension == sendingPlayer.dimension) {
|
||||
CommonProxy.simpleNetworkWrapper.sendTo(msg, sendingPlayer);
|
||||
ServerProxy.simpleNetworkWrapper.sendTo(msg, sendingPlayer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,14 +12,13 @@ import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import net.yseven.findyourway.Client.AngleGetter;
|
||||
import net.yseven.findyourway.Client.ClientProxy;
|
||||
import net.yseven.findyourway.CommonProxy;
|
||||
import net.yseven.findyourway.setup.ClientProxy;
|
||||
import net.yseven.findyourway.setup.ServerProxy;
|
||||
import net.yseven.findyourway.FindYourWay;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -36,8 +35,8 @@ public class ItemCompassBase extends Item {
|
||||
structureType = structureName;
|
||||
setCreativeTab(CreativeTabs.TOOLS);
|
||||
setMaxStackSize(1);
|
||||
CommonProxy.compassList.add(this);
|
||||
ItemCompassID = CommonProxy.compassList.indexOf(this);
|
||||
ServerProxy.compassList.add(this);
|
||||
ItemCompassID = ServerProxy.compassList.indexOf(this);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
@@ -74,15 +73,15 @@ public class ItemCompassBase extends Item {
|
||||
//netcode implementation
|
||||
|
||||
public void toBytes(ByteBuf buf) {
|
||||
if(CommonProxy.compassList.contains(this)) {
|
||||
if(ServerProxy.compassList.contains(this)) {
|
||||
buf.writeInt(ItemCompassID);
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemCompassBase fromBytes(ByteBuf buf) {
|
||||
int ID = buf.readInt();
|
||||
for(int i = 0; i <= CommonProxy.compassList.size(); i++) {
|
||||
if(ID == CommonProxy.compassList.get(i).getCompassID()) return CommonProxy.compassList.get(i);
|
||||
for(int i = 0; i <= ServerProxy.compassList.size(); i++) {
|
||||
if(ID == ServerProxy.compassList.get(i).getCompassID()) return ServerProxy.compassList.get(i);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package net.yseven.findyourway.Client;
|
||||
package net.yseven.findyourway.setup;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityPlayerSP;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.ModelRegistryEvent;
|
||||
import net.minecraftforge.client.model.ModelLoader;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
@@ -16,8 +14,7 @@ import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.yseven.findyourway.CommonProxy;
|
||||
import net.yseven.findyourway.FindYourWay;
|
||||
import net.yseven.findyourway.setup.ServerProxy;
|
||||
import net.yseven.findyourway.Network.MessageHandlerOnClient;
|
||||
import net.yseven.findyourway.Network.MessageToClient;
|
||||
import net.yseven.findyourway.Network.MessageToServer;
|
||||
@@ -25,7 +22,7 @@ import net.yseven.findyourway.item.ItemCompassBase;
|
||||
import net.yseven.findyourway.item.ModItems;
|
||||
|
||||
@Mod.EventBusSubscriber(Side.CLIENT)
|
||||
public class ClientProxy extends CommonProxy {
|
||||
public class ClientProxy extends ServerProxy {
|
||||
|
||||
//Get information about the player and world
|
||||
public static Minecraft getMinecraft() {
|
||||
@@ -48,13 +45,13 @@ public class ClientProxy extends CommonProxy {
|
||||
}
|
||||
|
||||
public static boolean hasCompass(ItemCompassBase compass) {
|
||||
return getPlayer() != null && CommonProxy.containsCompass(getPlayer().inventory, compass);
|
||||
return getPlayer() != null && ServerProxy.containsCompass(getPlayer().inventory, compass);
|
||||
}
|
||||
|
||||
public static void resetStructurePos(ItemCompassBase compass) {
|
||||
compass.setStructurePos(null);
|
||||
compass.setStructureWorld(getWorld());
|
||||
CommonProxy.simpleNetworkWrapper.sendToServer(new MessageToServer(compass));
|
||||
ServerProxy.simpleNetworkWrapper.sendToServer(new MessageToServer(compass));
|
||||
}
|
||||
|
||||
//Proxy Info
|
||||
@@ -62,7 +59,7 @@ public class ClientProxy extends CommonProxy {
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
super.preInit(event);
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
CommonProxy.simpleNetworkWrapper.registerMessage(MessageHandlerOnClient.class, MessageToClient.class, CommonProxy.MESSAGE_TO_CLIENT_ID, Side.CLIENT);
|
||||
ServerProxy.simpleNetworkWrapper.registerMessage(MessageHandlerOnClient.class, MessageToClient.class, ServerProxy.MESSAGE_TO_CLIENT_ID, Side.CLIENT);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,10 +79,10 @@ public class ClientProxy extends CommonProxy {
|
||||
|
||||
@SubscribeEvent
|
||||
public void onClientTick(TickEvent.ClientTickEvent event) {
|
||||
for(int i = 0; i < CommonProxy.compassList.size(); i++) {
|
||||
if(hasCompass(CommonProxy.compassList.get(i))) {
|
||||
if(getWorld() != CommonProxy.compassList.get(i).getStructureWorld()) {
|
||||
resetStructurePos(CommonProxy.compassList.get(i));
|
||||
for(int i = 0; i < ServerProxy.compassList.size(); i++) {
|
||||
if(hasCompass(ServerProxy.compassList.get(i))) {
|
||||
if(getWorld() != ServerProxy.compassList.get(i).getStructureWorld()) {
|
||||
resetStructurePos(ServerProxy.compassList.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
9
src/main/java/net/yseven/findyourway/setup/IProxy.java
Normal file
9
src/main/java/net/yseven/findyourway/setup/IProxy.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package net.yseven.findyourway.setup;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IProxy {
|
||||
void init();
|
||||
|
||||
World getClientWorld();
|
||||
}
|
||||
18
src/main/java/net/yseven/findyourway/setup/ModSetup.java
Normal file
18
src/main/java/net/yseven/findyourway/setup/ModSetup.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package net.yseven.findyourway.setup;
|
||||
|
||||
import net.minecraft.item.ItemGroup;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.yseven.findyourway.item.ModItems;
|
||||
|
||||
public class ModSetup {
|
||||
public ItemGroup itemGroup = new ItemGroup("findyourway") {
|
||||
@java.lang.Override
|
||||
public ItemStack createIcon() {
|
||||
return new ItemStack(ModItems.ENDER_COMPASS);
|
||||
}
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package net.yseven.findyourway;
|
||||
package net.yseven.findyourway.setup;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -13,6 +13,8 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.yseven.findyourway.Config;
|
||||
import net.yseven.findyourway.FindYourWay;
|
||||
import net.yseven.findyourway.Network.MessageHandlerOnServer;
|
||||
import net.yseven.findyourway.Network.MessageHandlerOnServerDummy;
|
||||
import net.yseven.findyourway.Network.MessageToClient;
|
||||
@@ -24,7 +26,7 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public class CommonProxy {
|
||||
public class ServerProxy {
|
||||
|
||||
public static ArrayList<ItemCompassBase> compassList = new ArrayList<ItemCompassBase>();
|
||||
public static SimpleNetworkWrapper simpleNetworkWrapper;
|
||||
Reference in New Issue
Block a user