sk9zist :l
Исправился
- 981
- 18
- 157
Уже долго мучаюсь с этой пакетной системой, сделал более менее рабочий код (который только в eclipse отображаеться без обнаруженных ошибок) а точнее.. Раньше я не думал писать в моддинг про пакеты (вообще забыл что так можно сделать ы) ну и вообщем, так как очень долго у меня уже не получаеться, решил попросить у вас помощи.
Да уж, текст большой, такие темы обычно просто игнорируют...
Вот всё необходимое:
Засунул это:
в onItemRightClick, после пкм на предмет звук не проигрываеться, в консоли какие-то ошибки
Да уж, текст большой, такие темы обычно просто игнорируют...
Вот всё необходимое:
ModidPacketHandler.java:
public class ModidPacketHandler
{
private static short id;
public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("Kj6LW68VAkRd");
public static void register(){
INSTANCE.registerMessage(MyMessageHandler.class, MyMessage.class, id++, Side.SERVER);
}
}
MyMessage.java:
public class MyMessage implements IMessage {
// A default constructor is always required
public MyMessage(){}
int toSend;
public MyMessage(int toSend) {
this.toSend = toSend;
}
@Override public void toBytes(ByteBuf buf) {
// Writes the int into the buf
buf.writeInt(toSend);
}
@Override public void fromBytes(ByteBuf buf) {
// Reads the int back from the buf. Note that if you have multiple values, you must read in the same order you wrote.
toSend = buf.readInt();
}
}
MyMessageHandler.java:
public class MyMessageHandler implements IMessageHandler<MyMessage, IMessage> {
// Do note that the default constructor is required, but implicitly defined in this case
@Override public IMessage onMessage(MyMessage message, MessageContext ctx) {
// This is the player the packet was sent to the server from
EntityPlayerMP serverPlayer = ctx.getServerHandler().player;
// The value that was sent
int amount = message.toSend;
// Execute the action on the main server thread by adding it as a scheduled task
serverPlayer.getServerWorld().addScheduledTask(() -> {
serverPlayer.playSound(SoundRegistrator.TELESOUND, 1.0F, 1.0F);
serverPlayer.inventory.addItemStackToInventory(new ItemStack(Items.DIAMOND, amount)); //оставил для проверки, работает ли, но звук не проигрываеться.
});
// No response packet
return null;
}
}
Засунул это:
Java:
ModidPacketHandler.INSTANCE.sendToServer(new MyMessage(6));
Последнее редактирование: