提供: Minecraft Modding Wiki
この編集を取り消せます。
下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 | 編集中の文章 | ||
1行目: | 1行目: | ||
{{前提チュートリアル|page=1.7のパケットについて}} | {{前提チュートリアル|page=1.7のパケットについて}} | ||
{{前提MOD|reqmod="Minecraft Forge Universal 10.12.1.1090~"}} | {{前提MOD|reqmod="Minecraft Forge Universal 10.12.1.1090~"}} | ||
− | {{過去リンク|version= | + | {{過去リンク|version=|url=http://minecraftjp.info/modding/index.php?title=1.7%E3%81%AE%E3%82%AD%E3%83%BC%E3%83%9C%E3%83%BC%E3%83%89%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E8%BF%BD%E5%8A%A0&oldid=2141}} |
54行目: | 54行目: | ||
public static void init() { | public static void init() { | ||
− | INSTANCE.registerMessage( | + | INSTANCE.registerMessage(MessageSample.class, MessageSample.class, 0, Side.SERVER); |
} | } | ||
}</source> | }</source> | ||
65行目: | 65行目: | ||
@SidedProxy(clientSide = "yourpackage.Client.ClientProxy", serverSide = "yourpackage.CommonProxy") | @SidedProxy(clientSide = "yourpackage.Client.ClientProxy", serverSide = "yourpackage.CommonProxy") | ||
public static CommonProxy proxy; | public static CommonProxy proxy; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
@EventHandler | @EventHandler | ||
87行目: | 82行目: | ||
<source lang = "java"> | <source lang = "java"> | ||
package yourpackage; | package yourpackage; | ||
+ | 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; | ||
+ | import net.minecraft.entity.player.EntityPlayer; | ||
− | public class MessageKeyPressed implements IMessage { | + | public class MessageKeyPressed implements IMessage, IMessageHandler<MessageKeyPressed, IMessage> { |
− | + | private byte key; | |
public MessageKeyPressed(){} | public MessageKeyPressed(){} | ||
109行目: | 109行目: | ||
buf.writeByte(this.key); | buf.writeByte(this.key); | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
@Override | @Override | ||
129行目: | 118行目: | ||
return null; | return null; | ||
} | } | ||
− | + | } | |
</source> | </source> | ||
− | |||
==解説== | ==解説== | ||
===ClientProxy=== | ===ClientProxy=== | ||
169行目: | 157行目: | ||
<source lang = "java"> | <source lang = "java"> | ||
package yourpackage; | package yourpackage; | ||
+ | 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; | ||
+ | import net.minecraft.entity.player.EntityPlayer; | ||
− | public class MessageKeyPressed implements IMessage { | + | public class MessageKeyPressed implements IMessage, IMessageHandler<MessageKeyPressed, IMessage> { |
private byte key; | private byte key; | ||
191行目: | 184行目: | ||
buf.writeByte(this.key); | buf.writeByte(this.key); | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
@Override | @Override | ||
216行目: | 195行目: | ||
} | } | ||
</source> | </source> | ||
− | + | キー判定を送るMessageクラス。 | |
− | + | ここでは、byte変数keyの内容をサーバーに送って、それをチャットに出力している。 | |
+ | |||
押しっぱなしかどうかを見たいのであれば、tick処理ループ内で、KeyBinding変数のgetIsKeyPressed()メソッドを監視し続ければよい。 | 押しっぱなしかどうかを見たいのであれば、tick処理ループ内で、KeyBinding変数のgetIsKeyPressed()メソッドを監視し続ければよい。 |