your current location:首页 > news>[0.3.2/Kubejs] Use Kubejs to add additional Tooltip to display transaction information [NFWC] Minecraft Game to display

[0.3.2/Kubejs] Use Kubejs to add additional Tooltip to display transaction information [NFWC] Minecraft Game to display

2024-12-05 23:05:41|Myriagame |source:minecraft skins

This tutorial is set by the author's setting without permission.

question

In the process of playing brittleness, we will get a large number of delivery agreements.If you do not sort it specifically, then you must encounter the dilemma below:

Brother, how can I find this? (Sad) You have to take out these delivery agreements one by one, and then right -click to check the content of them. This is a very painful repeated work.

Therefore, we consider trying to add custom TOOLTIP to the delivery protocol, so that the cursor can be seen when the cursor hovers on the delivery protocol.The effect is as follows:

Solution

This tutorial will give a research idea of ​​the author, hoping that this can help friends who also want to further change crispy osteopia through Kubejs.

Find the information in the delivery agreement item

Through the module Ibe Editor, we can view the NBT information of the delivery agreement:

 {{

Count: 1B,

ID: "Wares: Delivery_agreement",

Tag: {

Experience: 0.0d,

ID: "Organ",

Message: '{"color": "#33333", "text": "This is some.....

We save quite intact, and ensure that they are used."} ',

Ordered: 4.0D,

Paymentitems: [[

{{

Count: 1B,

ID: "Kubejs: MUSCLE_GOLD"

}

],,,

RequestedItems: [[

{{

Count: 1B,

ID: "LightManscurrency: Coin_EMERALD"

}

],,,

Title: '{"COLOR": "#D15492", "Text": "Organ Merchant"}'

}

}

It is not difficult to see that the PaymentItems array indicates the required items, and the RequestedItems array represents the items that can be obtained by the transaction.

Therefore, we can read the corresponding data in the delivery protocol NBT through Kubejs to add a custom Tooltip to it.

Write Kubejs code

We create a wares_tooltip.js (of course you want to add it directly in the existing JS) under the kubejs/client_scripts. IP)=> {{

Tooltip.addadvanced ('#Wares: Agreements',

/**

*@Param {internalesstack} item

*/

(Item, Advanced, Text) => {

Let RequestedItems = item.nbt? .RequestedItems;

Let paymentItems = item.nbt? .PaymentItems;

If (requestedItems) {

Text.add (text.yllow ('Items required:'));

For (let i = 0; I

Let RequestedItem = requestedItems [i];

Let stack = item.of (requestedItem.id). WithCount (requestedItem.Count);

Text.add ([Stack.displayName, Text.gray ('X'+RequestedItem.Count)];}

}

If (paymentItems) {

Text.add (text.green ('Againable:'));

For (let i = 0; I

Let paymentITEM = PaymentItems [i];

Let stack = item.of (paymentitem.id). WithCount (paymentItem.Count);

Text.add ([Stack.displayName, Text.gray ('X'+PaymentItem.Count)];

}

}

});

})

Effect

Save the file and start the game. At this time, you will find that the trading information can be seen when the mouse hovers on the delivery agreement.

The problem to be solved

Since the author uses DisplayName to display the name of the item, there are still situations that cannot be displayed by some items that are distinguished by NBT, as follows: 2024-10-05 The first revision of the transfer door pearl has been solved.Information display problem.

2024-10-05 The first revision

A solution that uses reflex to obtain the portal pearl information. At the same time, the number of trading times is added. The following is the updated Kubejs code:

 const $ gatepearlitem = java.loadClass ('Shadows.gateway.Item.gatepearlitem')

Itemevents.Tooltip ((Tooltip) => {{

Tooltip.addadvanced ('#Wares: Agreements',

/**

*@Param {internalesstack} item

*/

(Item, Advanced, Text) => {

Let RequestedItems = item.nbt? .RequestedItems;

Let paymentItems = item.nbt? .PaymentItems;

Let delivered = item.nbt? .Delivered;

Let order = item.nbt? .Ondered;

If (requestedItems) {

Text.add (text.yllow ('Items required:'));

For (let i = 0; I

Let stack = item.of (requestedItems [i] .id). Withnbt (requestedItems [i]); Gray ('x'+stack.count)];

}

}

If (paymentItems) {

Text.add (text.green ('Againable:'));

For (let i = 0; I

Let stack = item.of (paymentItems [i] .id). Withnbt (paymentItems [i]);

If (Stack.id == 'Gateway: Gate_pearl') {{

Let name = component.translation ('gateways.gate_pearl', component.transLatable (paymentitems [i] .tag.gateway.replace (':', '.')). SetStyle k.displayName.getStyle ());Text.add ([Text.litral (''), name, text.gray ('x'+stack.count)];

}

Else

Text.add ([Stack.displayName, Text.gray ('X'+Stack.count)];

}

}

If (order) {

If (! Delivered)

Text.add ([Text.aqua ("" Exchangeable times: "), Text.aqua (` $ {OrderEd}/$ {orderEd}));););););

Else text.add ([Text.aqua ("" "Exchangeable times:"), text.aqua (`$ {orderd-delivers}/$ {orderEd}`)););

}

});

})

The effect is shown in the figure:

If you have any questions or a better solution, please make it in the comment area ~