Jump to content

Davidthemodder

Members
  • Posts

    46
  • Joined

  • Last visited

Everything posted by Davidthemodder

  1. I GOT IT TO WORK!!! I registered the ModPacketHandler in my main class and it workend. (In the private void setup)
  2. This is about the registering of the ModPacketHandler
  3. I think the problem is that the default dist is client and it never gets registered on the server.
  4. Wait. Is this Right? @Mod.EventBusSubscriber(modid = UltimateSheepMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
  5. Can I post a zip file of the mod?
  6. So I should make my mod a git project? Like the Folder or the folder where the mod folder is?
  7. It crashed. crash-2021-05-23_20.00.52-client.txt latest.log
  8. Can I just do it twice? EDIT: Like on Server and on the Client in the two classes?
  9. @Mod.EventBusSubscriber(modid = UltimateSheepMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public class ModClientEvent { @SubscribeEvent public static void lightning(AttackEntityEvent event){ if(event.getEntityLiving().getHeldItemMainhand().getItem() == ModItems.LIGHTNING_HAMMER.get()){ LightningBoltEntity lightning = new LightningBoltEntity(EntityType.LIGHTNING_BOLT,event.getEntity().world); lightning.setPosition(event.getTarget().getPosX(), event.getTarget().getPosY(), event.getTarget().getPosZ()); event.getPlayer().world.addEntity(lightning); } } @SubscribeEvent public static void onCrafting(GuiOpenEvent event){ if (event.isCancelable()){ if (event.getGui() instanceof CraftingScreen){ if (event.getResult().equals(Items.APPLE)){ event.setCanceled(true); } } } } @SubscribeEvent public static void fly(TickEvent.ClientTickEvent event){ if(event.phase == TickEvent.Phase.START){ if(UltimateSheepMod.KEY.isKeyDown()){ ModPacketHandler.simpleChannel.sendToServer(new FlyActivateMessage()); } } } @SubscribeEvent public static void doClientSetup(FMLClientSetupEvent event){ ClientRegistry.registerKeyBinding(UltimateSheepMod.KEY); } @SubscribeEvent public static void doCommonSetup(FMLCommonSetupEvent event){ ModPacketHandler.init(); }
  10. Here the Crash report. crash-2021-05-23_19.08.29-client.txt
  11. There is no error but it crashes as soon as I press the key
  12. public static final KeyBinding KEY = new KeyBinding("Fly",GLFW.GLFW_KEY_V, "Ultimate Sheep Mod"); @SubscribeEvent public static void doClientSetup(FMLClientSetupEvent event){ ClientRegistry.registerKeyBinding(UltimateSheepMod.KEY); } @SubscribeEvent public static void fly(TickEvent.ClientTickEvent event){ if(event.phase == TickEvent.Phase.START){ if(UltimateSheepMod.KEY.isKeyDown()){ ModPacketHandler.simpleChannel.sendToServer(new FlyActivateMessage()); } } } public class ModPacketHandler { private static final String version = "1"; private static int id = 0; public static SimpleChannel simpleChannel; public static void init(){ simpleChannel = NetworkRegistry.newSimpleChannel(new ResourceLocation("usm:simple_channel"), () -> version, version::equals, version::equals); simpleChannel.registerMessage(id++, FlyActivateMessage.class, FlyActivateMessage::encode, FlyActivateMessage::decode, FlyActivateMessage::handle, Optional.of(NetworkDirection.PLAY_TO_SERVER)); } } Like this?
  13. public static final KeyBinding KEY = new KeyBinding("Fly",GLFW.GLFW_KEY_V, "Ultimate Sheep Mod"); @SubscribeEvent public static void doClientSetup(FMLClientSetupEvent event){ ClientRegistry.registerKeyBinding(UltimateSheepMod.KEY); } @SubscribeEvent public static void fly(TickEvent.ClientTickEvent event){ if(event.phase == TickEvent.Phase.START){ if(UltimateSheepMod.KEY.isKeyDown()){ ModPacketHandler.simpleChannel.sendToServer(new FlyActivateMessage()); } } } public class ModPacketHandler { private static final String version = "1"; private static int id = 0; public static SimpleChannel simpleChannel; public static void init(){ simpleChannel = NetworkRegistry.newSimpleChannel(new ResourceLocation("usm:simple_channel"), () -> version, version::equals, version::equals); simpleChannel.registerMessage(id++, FlyActivateMessage.class, FlyActivateMessage::encode, FlyActivateMessage::decode, FlyActivateMessage::handle, Optional.of(NetworkDirection.PLAY_TO_SERVER)); } } public class FlyActivateMessage { public static void encode(FlyActivateMessage message,PacketBuffer packetBuffer) { } public static FlyActivateMessage decode(PacketBuffer packetBuffer) { return new FlyActivateMessage(); } public static void handle(FlyActivateMessage message, Supplier<NetworkEvent.Context> networkContext) { ServerPlayerEntity player = networkContext.get().getSender(); networkContext.get().enqueueWork(() -> { }); networkContext.get().setPacketHandled(true); } }
  14. I did everything like you did but it always crashes when I try it.
  15. Thank you for your help. And without you I would never have found out how to run the code.
  16. I want to make the player to do somethingwhen I press V. How?
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.