提供: Minecraft Modding Wiki
この編集を取り消せます。
下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 | 編集中の文章 | ||
1行目: | 1行目: | ||
{{前提MOD|reqmod="Minecraft Forge Universal 10.12.1.1090~"}} | {{前提MOD|reqmod="Minecraft Forge Universal 10.12.1.1090~"}} | ||
+ | |||
==パケットについて== | ==パケットについて== | ||
<p>1.7.2でパケット関連のシステムが大幅に変更され、nettyと呼ばれるオープンプロジェクトのシステムを利用したHandshake方式になりました。<br> | <p>1.7.2でパケット関連のシステムが大幅に変更され、nettyと呼ばれるオープンプロジェクトのシステムを利用したHandshake方式になりました。<br> | ||
18行目: | 19行目: | ||
//このMOD用のSimpleNetworkWrapperを生成。チャンネルの文字列は固有であれば何でも良い。MODIDの利用を推奨。 | //このMOD用のSimpleNetworkWrapperを生成。チャンネルの文字列は固有であれば何でも良い。MODIDの利用を推奨。 | ||
− | |||
public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("SamplePacketMod"); | public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("SamplePacketMod"); | ||
24行目: | 24行目: | ||
public static void init() { | public static void init() { | ||
− | /* | + | /*IMesssageHandlerクラスとMessageクラスの登録。今回同じクラスにしているが、別々でもよい。 |
*第三引数:MessageクラスのMOD内での登録ID。256個登録できる | *第三引数:MessageクラスのMOD内での登録ID。256個登録できる | ||
*第四引数:送り先指定。クライアントかサーバーか、Side.CLIENT Side.SERVER*/ | *第四引数:送り先指定。クライアントかサーバーか、Side.CLIENT Side.SERVER*/ | ||
− | INSTANCE.registerMessage( | + | INSTANCE.registerMessage(MessageSample.class, MessageSample.class, 0, Side.SERVER); |
} | } | ||
}</source> | }</source> | ||
35行目: | 35行目: | ||
package mods.samplepacketmod; | package mods.samplepacketmod; | ||
+ | import cpw.mods.fml.client.FMLClientHandler; | ||
+ | import cpw.mods.fml.common.FMLCommonHandler; | ||
import cpw.mods.fml.common.network.simpleimpl.IMessage; | 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; | import io.netty.buffer.ByteBuf; | ||
− | public class MessageSample implements IMessage { | + | public class MessageSample implements IMessage, IMessageHandler<MessageSample, IMessage> { |
− | + | private byte data; | |
public MessageSample(){} | public MessageSample(){} | ||
57行目: | 61行目: | ||
buf.writeByte(this.data); | buf.writeByte(this.data); | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
@Override//IMessageHandlerのメソッド | @Override//IMessageHandlerのメソッド | ||
− | public IMessage onMessage( | + | public IMessage onMessage(MessageKeyPressed message, MessageContext ctx) { |
− | // | + | //クライアントへ送った際に、Worldインスタンスはこのように取れる。 |
− | // | + | //FMLClientHandler.instance().getClient().theWorld |
//サーバーへ送った際に、EntityPlayerインスタンス(EntityPlayerMPインスタンス)はこのように取れる。 | //サーバーへ送った際に、EntityPlayerインスタンス(EntityPlayerMPインスタンス)はこのように取れる。 | ||
//EntityPlayer entityPlayer = ctx.getServerHandler().playerEntity; | //EntityPlayer entityPlayer = ctx.getServerHandler().playerEntity; | ||
83行目: | 73行目: | ||
} | } | ||
</source> | </source> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
===@Modクラス内の記述=== | ===@Modクラス内の記述=== | ||
<source lang = "java"> | <source lang = "java"> | ||
120行目: | 84行目: | ||
@Mod.Instance("SamplePacketMod") | @Mod.Instance("SamplePacketMod") | ||
public static SamplePacketMod instance; | public static SamplePacketMod instance; | ||
− | |||
− | |||
@Mod.EventHandler | @Mod.EventHandler | ||
public void preInit(FMLPreInitializationEvent event) | public void preInit(FMLPreInitializationEvent event) | ||
129行目: | 91行目: | ||
} | } | ||
</source> | </source> | ||
− | |||
===パケットを送る際の記述=== | ===パケットを送る際の記述=== | ||
<source lang = "java"> | <source lang = "java"> |