提供: Minecraft Modding Wiki
この編集を取り消せます。
下記の差分を確認して、本当に取り消していいか検証してください。よろしければ変更を保存して取り消しを完了してください。
最新版 | 編集中の文章 | ||
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()メソッドを監視し続ければよい。 |