Jump to content

issues with keybinding 1.15.2


greenecojr

Recommended Posts

I was following a tutorial and another forum post on here and I have been trying to get potion effects to activate with the press of a button and every time i try a single player world the game crashes

Key,KeyBinding,Packet Classes

public class key {


        private final int key;

        public key(int keyIn) {
            this.key = keyIn;
        }

        public static void encode(key msg, PacketBuffer buf) {
            buf.writeInt(msg.key);
        }

        public static key decode(PacketBuffer buf) {
            return new key(buf.readInt());
        }

        public static void handle(key msg, Supplier<NetworkEvent.Context> ctx) {
            if(msg.key==0) {
                ctx.get().enqueueWork(() -> {
                    ServerPlayerEntity sender = ctx.get().getSender();
                    sender.addPotionEffect(new EffectInstance(Effect.get(5),20)); });
            }
            ctx.get().setPacketHandled(true);
        }
    }
@Mod.EventBusSubscriber(modid = DungeonWars.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class keyBind {
    static KeyBinding[] keyBindings = new KeyBinding[]{new KeyBinding("key.strong", KeyConflictContext.UNIVERSAL, InputMappings.Type.KEYSYM, 33, "key.categories.strong")};


   static Boolean keyPress = false;

    @SubscribeEvent
    public static void onTick(TickEvent.ClientTickEvent event) {
        if (keyPress && !keyBindings[0].isKeyDown()) {
            keyPress = false;
        }
    }

    @SubscribeEvent
    public static void onInput(InputEvent.KeyInputEvent event) {
        if (event.getKey() == keyBindings[0].getKey().getKeyCode() ) {
           // CrudeTechMod.log("pressed");
            Packets.INSTANCE.sendToServer(new key(0));
            keyPress = true;
        }
    }

    public static void registerKeyBindings() {
        for (int i = 0; i < keyBindings.length; i++) {
            ClientRegistry.registerKeyBinding(keyBindings[i]);
        }
    }
public class Packets {
    private static final String PROTOCOL_VERSION = "1";
    public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
            new ResourceLocation(DungeonWars.MOD_ID, "main"),
            () -> PROTOCOL_VERSION,
            PROTOCOL_VERSION::equals,
            PROTOCOL_VERSION::equals
    );
    public static int i=0;
}
//(Main)

    private void setup(final FMLCommonSetupEvent event)
    {
        // some preinit code
        Packets.INSTANCE.registerMessage(Packets.i++, key.class, key::encode, key::decode, key::handle);
     }

    private void doClientStuff(final FMLClientSetupEvent event) {
        // do something that can only be done on the client
        keyBind.registerKeyBindings();
        //ClientRegistry.registerKeyBinding(keybinding);

    }

Log

java.lang.RuntimeException: Why did the advancements not load yet?!
	at net.minecraftforge.common.AdvancementLoadFix.loadVisibility(AdvancementLoadFix.java:51) ~[?:?] {re:classloading}
	at net.minecraft.advancements.PlayerAdvancements.load(PlayerAdvancements.java:157) ~[?:?] {re:classloading}
	at net.minecraft.advancements.PlayerAdvancements.<init>(PlayerAdvancements.java:65) ~[?:?] {re:classloading}
	at net.minecraft.server.management.PlayerList.getPlayerAdvancements(PlayerList.java:806) ~[?:?] {re:classloading}
	at net.minecraft.entity.player.ServerPlayerEntity.<init>(ServerPlayerEntity.java:167) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.management.PlayerList.createPlayerForUser(PlayerList.java:395) ~[?:?] {re:classloading}
	at net.minecraft.network.login.ServerLoginNetHandler.tryAcceptPlayer(ServerLoginNetHandler.java:120) ~[?:?] {re:classloading}
	at net.minecraft.network.login.ServerLoginNetHandler.tick(ServerLoginNetHandler.java:64) ~[?:?] {re:classloading}
	at net.minecraft.network.NetworkManager.tick(NetworkManager.java:246) ~[?:?] {re:classloading}
	at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:152) ~[?:?] {re:classloading}
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:903) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:821) ~[?:?] {re:classloading,pl:accesstransformer:B}
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120) ~[?:?] {re:classloading,pl:runtimedistcleaner:A}
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:662) [?:?] {re:classloading,pl:accesstransformer:B}
	at java.lang.Thread.run(Thread.java:748) [?:1.8.0_251] {}


A detailed walkthrough of the error, its code path and all known details is as follows:
---------------------------------------------------------------------------------------

-- Head --
Thread: Server thread
Stacktrace:
	at net.minecraftforge.common.AdvancementLoadFix.loadVisibility(AdvancementLoadFix.java:51)
	at net.minecraft.advancements.PlayerAdvancements.load(PlayerAdvancements.java:157)
	at net.minecraft.advancements.PlayerAdvancements.<init>(PlayerAdvancements.java:65)
	at net.minecraft.server.management.PlayerList.getPlayerAdvancements(PlayerList.java:806)
	at net.minecraft.entity.player.ServerPlayerEntity.<init>(ServerPlayerEntity.java:167)
	at net.minecraft.server.management.PlayerList.createPlayerForUser(PlayerList.java:395)
	at net.minecraft.network.login.ServerLoginNetHandler.tryAcceptPlayer(ServerLoginNetHandler.java:120)
	at net.minecraft.network.login.ServerLoginNetHandler.tick(ServerLoginNetHandler.java:64)
	at net.minecraft.network.NetworkManager.tick(NetworkManager.java:246)

-- Ticking connection --
Details:
	Connection: net.minecraft.network.NetworkManager@2751f8c8
Stacktrace:
	at net.minecraft.network.NetworkSystem.tick(NetworkSystem.java:152)
	at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:903)
	at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:821)
	at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:120)
	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:662)
	at java.lang.Thread.run(Thread.java:748)

-- System Details --
Details:
	Minecraft Version: 1.15.2
	Minecraft Version ID: 1.15.2
	Operating System: Windows 10 (amd64) version 10.0
	Java Version: 1.8.0_251, Oracle Corporation
	Java VM Version: Java HotSpot(TM) 64-Bit Server VM (mixed mode), Oracle Corporation
	Memory: 762228824 bytes (726 MB) / 2077753344 bytes (1981 MB) up to 3799515136 bytes (3623 MB)
	CPUs: 8
	JVM Flags: 1 total; -XX:HeapDumpPath=MojangTricksIntelDriversForPerformance_javaw.exe_minecraft.exe.heapdump
	ModLauncher: 5.1.0+69+master.79f13f7
	ModLauncher launch target: fmluserdevclient
	ModLauncher naming: mcp
	ModLauncher services: 
		/eventbus-2.2.0-service.jar eventbus PLUGINSERVICE 
		/forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-launcher.jar object_holder_definalize PLUGINSERVICE 
		/forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-launcher.jar runtime_enum_extender PLUGINSERVICE 
		/accesstransformers-2.1.1-shadowed.jar accesstransformer PLUGINSERVICE 
		/forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-launcher.jar capability_inject_definalize PLUGINSERVICE 
		/forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-launcher.jar runtimedistcleaner PLUGINSERVICE 
		/forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-launcher.jar fml TRANSFORMATIONSERVICE 
	FML: 31.2
	Forge: net.minecraftforge:31.2.0
	FML Language Providers: 
		[email protected]
		minecraft@1
	Mod List: 
		client-extra.jar Minecraft {[email protected] DONE}
		forge-1.15.2-31.2.0_mapped_snapshot_20200514-1.15.1-recomp.jar Forge {[email protected] DONE}
		main Minecraft World War: Dungeon Wars {[email protected] DONE}
	Player Count: 0 / 8; []
	Data Packs: vanilla, mod:forge (incompatible), mod:mwwdungeonwars
	Type: Integrated Server (map_client.txt)

 

Link to comment
Share on other sites

A few things I notice at first glance,

  1. I usually register my packets in my main constructor, don't know if that's relevant.
  2. Why do you have a static boolean for if the key is pressed, your keybind most likely won't work in multiplayer if you use it.
  3. The int parameter in your key class is completely useless, you should remove it.
  4. I think ctx.get.setPacketHandled(true) should always be called, whether or not your requirement was met, call it at the end of the handle method.

It's sad how much time mods spend saying "x is no longer supported on this forum. Please update to a modern version of Minecraft to receive support".

Link to comment
Share on other sites

37 minutes ago, Novârch said:

A few things I notice at first glance,

  1. I usually register my packets in my main constructor, don't know if that's relevant.
  2. Why do you have a static boolean for if the key is pressed, your keybind most likely won't work in multiplayer if you use it.
  3. The int parameter in your key class is completely useless, you should remove it.
  4. I think ctx.get.setPacketHandled(true) should always be called, whether or not your requirement was met, call it at the end of the handle method.

Do you think keypress is what is making it crash because the rest of the points do not result in a server crash besides the setpackethandled

 

also i do call setpackethandled at the end of the handle method

Edited by greenecojr
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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