Skip to content

Commit

Permalink
The server now sends the world seed to players on login.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunatrius committed Nov 18, 2014
1 parent 52929e9 commit 302f9ed
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.github.lunatrius.core.version.VersionChecker;
import com.github.lunatrius.ingameinfo.handler.ConfigurationHandler;
import com.github.lunatrius.ingameinfo.network.PacketHandler;
import com.github.lunatrius.ingameinfo.proxy.CommonProxy;
import com.github.lunatrius.ingameinfo.reference.Reference;
import cpw.mods.fml.common.Mod;
Expand All @@ -19,7 +20,7 @@ public class InGameInfoXML {
@Instance(Reference.MODID)
public static InGameInfoXML instance;

@SidedProxy(serverSide = Reference.PROXY_COMMON, clientSide = Reference.PROXY_CLIENT)
@SidedProxy(serverSide = Reference.PROXY_SERVER, clientSide = Reference.PROXY_CLIENT)
public static CommonProxy proxy;

@EventHandler
Expand All @@ -34,6 +35,7 @@ public void preInit(FMLPreInitializationEvent event) {

@EventHandler
public void init(FMLInitializationEvent event) {
PacketHandler.init();
proxy.registerEvents();
proxy.registerCommands();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.lunatrius.ingameinfo.handler;

import com.github.lunatrius.ingameinfo.network.PacketHandler;
import com.github.lunatrius.ingameinfo.network.message.MessageSeed;
import com.github.lunatrius.ingameinfo.reference.Reference;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import net.minecraft.entity.player.EntityPlayerMP;

public class PlayerHandler {
@SubscribeEvent
public void onPlayerLogin(PlayerEvent.PlayerLoggedInEvent event) {
if (event.player instanceof EntityPlayerMP) {
try {
PacketHandler.INSTANCE.sendTo(new MessageSeed(event.player.worldObj.getSeed()), (EntityPlayerMP) event.player);
} catch (Exception ex) {
Reference.logger.error("Failed to send the seed!", ex);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.github.lunatrius.ingameinfo.network;

import com.github.lunatrius.ingameinfo.network.message.MessageSeed;
import com.github.lunatrius.ingameinfo.reference.Reference;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;

public class PacketHandler {
public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(Reference.MODID.toLowerCase());

public static void init() {
INSTANCE.registerMessage(MessageSeed.class, MessageSeed.class, 0, Side.CLIENT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.github.lunatrius.ingameinfo.network.message;

import com.github.lunatrius.ingameinfo.tag.Tag;
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 cpw.mods.fml.relauncher.Side;
import io.netty.buffer.ByteBuf;

public class MessageSeed implements IMessage, IMessageHandler<MessageSeed, IMessage> {
public long seed;

public MessageSeed() {
this.seed = 0;
}

public MessageSeed(long seed) {
this.seed = seed;
}

@Override
public void fromBytes(ByteBuf buf) {
this.seed = buf.readLong();
}

@Override
public void toBytes(ByteBuf buf) {
buf.writeLong(this.seed);
}

@Override
public IMessage onMessage(MessageSeed message, MessageContext ctx) {
if (ctx.side == Side.CLIENT) {
Tag.setSeed(message.seed);
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.lunatrius.ingameinfo.proxy;

import com.github.lunatrius.ingameinfo.handler.PlayerHandler;
import cpw.mods.fml.common.FMLCommonHandler;

public class ServerProxy extends CommonProxy {
@Override
public void registerEvents() {
FMLCommonHandler.instance().bus().register(new PlayerHandler());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Reference {
public static final String VERSION = "${version}";
public static final String FORGE = "${forgeversion}";
public static final String MINECRAFT = "${mcversion}";
public static final String PROXY_COMMON = "com.github.lunatrius.ingameinfo.proxy.CommonProxy";
public static final String PROXY_SERVER = "com.github.lunatrius.ingameinfo.proxy.ServerProxy";
public static final String PROXY_CLIENT = "com.github.lunatrius.ingameinfo.proxy.ClientProxy";
public static final String GUI_FACTORY = "com.github.lunatrius.ingameinfo.client.gui.GuiFactory";

Expand Down

0 comments on commit 302f9ed

Please sign in to comment.