Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/main/java/com/silvermoon/boxplusplus/boxplusplus.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

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 cpw.mods.fml.common.event.*;

@Mod(
modid = Tags.MODID,
Expand Down Expand Up @@ -66,6 +63,11 @@ public void serverStarting(FMLServerStartingEvent event) {
proxy.serverStarting(event);
}

@Mod.EventHandler
public void serverStarted(FMLServerStartedEvent event) {
proxy.serverStarted(event);
}

public static final CreativeTabs BoxTab = new CreativeTabs("BoxPlusPlus") {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;

public class ClientProxy extends CommonProxy {

Expand All @@ -23,4 +24,9 @@ public void init(FMLInitializationEvent e) {
*/
MinecraftForge.EVENT_BUS.register(BoxNEIHandler.instance);
}

@Override
public void postInit(FMLPostInitializationEvent event) {
super.postInit(event);
}
}
33 changes: 20 additions & 13 deletions src/main/java/com/silvermoon/boxplusplus/common/CommonProxy.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package com.silvermoon.boxplusplus.common;

import static com.silvermoon.boxplusplus.common.loader.RecipeLoader.loadAddUpgradeModuleRecipe;

import net.minecraftforge.common.MinecraftForge;

import com.silvermoon.boxplusplus.common.config.Config;
import com.silvermoon.boxplusplus.common.loader.BlockRegister;
import com.silvermoon.boxplusplus.common.loader.RecipeLoader;
import com.silvermoon.boxplusplus.common.loader.TileEntitiesLoader;
import com.silvermoon.boxplusplus.event.ServerEvent;
import com.silvermoon.boxplusplus.network.NetworkLoader;
import com.silvermoon.boxplusplus.util.ResultModuleRequirement;

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 bartworks.API.SideReference;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.event.*;
import gregtech.api.recipe.check.CheckRecipeResultRegistry;

public class CommonProxy {

private static boolean hasRunRecipeLoader = true;

// 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) {
Expand All @@ -29,19 +31,24 @@ public void preInit(FMLPreInitializationEvent event) {
public void init(FMLInitializationEvent event) {
TileEntitiesLoader.register();
CheckRecipeResultRegistry.register(new ResultModuleRequirement(0, false));
ServerEvent serverEvent = new ServerEvent();
if (SideReference.Side.Server) {
MinecraftForge.EVENT_BUS.register(serverEvent);
}
FMLCommonHandler.instance()
.bus()
.register(serverEvent);
}

// postInit "Handle interaction with other mods, complete your setup based on this." (Remove if not needed)
public void postInit(FMLPostInitializationEvent event) {

}
public void postInit(FMLPostInitializationEvent event) {}

// register server commands in this event handler (Remove if not needed)
public void serverStarting(FMLServerStartingEvent event) {
if (hasRunRecipeLoader) {
new RecipeLoader().run();
hasRunRecipeLoader = false;
}
new RecipeLoader().run();
}

public void serverStarted(FMLServerStartedEvent event) {
loadAddUpgradeModuleRecipe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ public void run() {
addMachineBlockRecipe();
addModuleRecipe();
addRingRecipe();
}

public static boolean hasLoadedAddUpgradeModuleRecipe = false;

public static void loadAddUpgradeModuleRecipe() {

if (hasLoadedAddUpgradeModuleRecipe) {
return;
}
hasLoadedAddUpgradeModuleRecipe = true;
addUpgradeModuleRecipe();
}

Expand Down Expand Up @@ -427,7 +437,7 @@ public void addModuleRecipe() {
}

// All - ResearchAssemblyLine
public void addUpgradeModuleRecipe() {
public static void addUpgradeModuleRecipe() {
GTValues.RA.stdBuilder()
.metadata(RESEARCH_ITEM, new ItemStack(BlockRegister.BoxModule, 1, 0))
.metadata(RESEARCH_TIME, 12000)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.silvermoon.boxplusplus.common.loader;

public class ServerInitLoader {

public static void initOnPlayerJoinedSever() {
RecipeLoader.loadAddUpgradeModuleRecipe();
}
}
24 changes: 24 additions & 0 deletions src/main/java/com/silvermoon/boxplusplus/event/ServerEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.silvermoon.boxplusplus.event;

import static com.silvermoon.boxplusplus.boxplusplus.LOG;

import net.minecraft.entity.player.EntityPlayerMP;

import com.silvermoon.boxplusplus.network.NetworkLoader;
import com.silvermoon.boxplusplus.network.packet.ServerJoinedPacket;

import bartworks.API.SideReference;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;

public class ServerEvent {

@SubscribeEvent(priority = EventPriority.LOWEST)
public void PlayerJoinServerEvent(PlayerEvent.PlayerLoggedInEvent event) {
LOG.info("PlayerJoinServerEvent running");
if (event == null || !(event.player instanceof EntityPlayerMP player) || !SideReference.Side.Server) return;
NetworkLoader.instance.sendTo(new ServerJoinedPacket(), player);
LOG.info("PlayerJoinedPacket run finished");
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.silvermoon.boxplusplus.network;

import com.silvermoon.boxplusplus.Tags;
import com.silvermoon.boxplusplus.network.packet.ServerJoinedPacket;

import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
Expand All @@ -14,5 +15,8 @@ public class NetworkLoader {

public static void init() {
instance.registerMessage(MessageRouting.Handler.class, MessageRouting.class, nextID++, Side.SERVER);

instance.registerMessage(ServerJoinedPacket.class, ServerJoinedPacket.class, nextID++, Side.SERVER);
instance.registerMessage(ServerJoinedPacket.class, ServerJoinedPacket.class, nextID++, Side.CLIENT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.silvermoon.boxplusplus.network.packet;

import com.silvermoon.boxplusplus.common.loader.ServerInitLoader;

import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;

public class ServerJoinedPacket implements IMessage, IMessageHandler<ServerJoinedPacket, IMessage> {

@Override
public void fromBytes(ByteBuf buf) {

}

@Override
public void toBytes(ByteBuf buf) {

}

@Override
public IMessage onMessage(ServerJoinedPacket message, MessageContext ctx) {
ServerInitLoader.initOnPlayerJoinedSever();
return null;
}
}