Jump to content

[1.14.4] Help with creating keybindings.


TesterTesting135

Recommended Posts

36 minutes ago, TesterTesting135 said:

I don't understand the parameters of registerMessage.

The first one is it's mod unique ID.
The second is a class that will be created by your decoder. (It needs to store all the information you want accessible on the other side(Server/Client)).

The third is a BIConsumer that takes in an instance of that class and a PacketBuffer. Use this to write the data sent over the network to the PacketBuffer.
The fourth is a Function that takes in a PacketBuffer and returns an instance of the class. Use this to read the data from the PacketBuffer into a new instance of the class.

The fifth and final parameter is a BiConsumer that takes in an instance of the class and a Supplier of NetworkEvent.Context. Use this to handle the information you sent over whether it be syncing data to the client or performing an action on the server.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

11 minutes ago, TesterTesting135 said:

Ok, thank you! Also, by any chance do you know how to add a tooltip to another item that you didn't create? (I'm trying to when you press a key, it will do stuff and also add a tooltip to that item that you're holding)

There is an event for it. I believe it is called RenderTooltipEvent. You'll have to use Pre sub event to modify the lines List

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

Sorry to bother you, but I'm trying to cancel the item drop event, and it works, but only if i have the inventory open, and then drag and drop out or press q inside the inventory menu. However, it doesn't work when i "q" inside the hotbar, without the inventory open. It just "deletes" the item, but when I click on the slot with the inventory open it reappears. Do you know why? Thanks. Code:

@SubscribeEvent
public static void onToss(ItemTossEvent event) {

    PlayerEntity player = event.getPlayer();
    //player.sendMessage(new StringTextComponent("1nd Stage."));
    if (ItemItemLock.hasLock(player)) {
        //player.sendMessage(new StringTextComponent("2nd Stage."));
        ItemStack droppedItem = event.getEntityItem().getItem();
        CompoundNBT nbt;
        if (droppedItem.hasTag()) {
            nbt = droppedItem.getTag();
        } else {
            nbt = new CompoundNBT();
        }
      //  player.sendMessage(new StringTextComponent("3nd Stage."));
        if (nbt.contains(ItemItemLock.NBT_LOCK)) {
        //    player.sendMessage(new StringTextComponent("4nd Stage."));
            if (nbt.getBoolean(ItemItemLock.NBT_LOCK)) {
        //        player.sendMessage(new StringTextComponent("5nd Stage."));

                event.setCanceled(true);
                ItemStack copy = droppedItem.copy();
                player.inventory.add(1, copy);

            }
        }
    }
}
Link to comment
Share on other sites

11 minutes ago, TesterTesting135 said:

if (nbt.contains(ItemItemLock.NBT_LOCK)) {

Firstly there is no point in checking if it contains it. It will return getBoolean will return false if it doesn't contain it.

 

15 minutes ago, TesterTesting135 said:

Do you know why?

Sounds like a client server desync.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

3 minutes ago, TesterTesting135 said:

Do you know how I could fix it? It worked in 1.12.2. Thanks.

Not off the top of my head. I will need more information. Is the event being called on the server or the client? If it's on the server you'll need to send a packet to the client specifically SSetSlotPacket I believe. There might be an easier way however.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

12 minutes ago, TesterTesting135 said:

I’m not sure if it’s on the server or client. I just created a class and annotated it event bus subscriber, and put that method in.

Put a println or log message in the event method and have it print out World#isRemote. True means client and false means server.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

2 minutes ago, TesterTesting135 said:

Ok, so I did player.container.detectandsendchanges but it still isn’t working.

That's not gonna work because the Container isn't open I believe.

 

3 minutes ago, TesterTesting135 said:

Also, if the item is not in slot 1 and the slot before is not occupied, it will push the item to the slot before and work. 

That's gotta be because it detected a change in the inventory. Like I said you will need to send a packet to the client.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

7 minutes ago, TesterTesting135 said:

Ok, so i made a packet handler. What should i send to the client?

Thanks.

No i said you could use the vanilla packet.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

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.



×
×
  • Create New...

Important Information

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