#Make an item that behaves like a spawn egg

31 messages · Page 1 of 1 (latest)

lavish tendon
#

I'm trying to make a custom item that behaves like a spawn egg:
StartupEvents.registry('item', e => {
const $SpawnEggItem = Java.loadClass('net.minecraft.world.item.SpawnEggItem')
const $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')
const $EntityType = Java.loadClass('net.minecraft.world.entity.EntityType')
e.custom('cow_bait', new $SpawnEggItem($EntityType.COW, 4470310, 10592673, new $ItemProperties))
})

The error I get:
There were KubeJS startup errors [1]!

  1. Error occurred while handling event 'StartupEvents.registry': java.lang.IllegalStateException:
    Registry is already frozen

The log is in the txt. Thanks!

drowsy crestBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

grave creekBOT
#

Paste version of message.txt from @lavish tendon

gloomy helm
#

??codeblock

grave creekBOT
# gloomy helm ??codeblock

You can write your code in a codeblock by typing it between the codeblock delimiters:

```js :arrow_left:

ServerEvents.recipes(event => {
event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})

``` :arrow_left:

As an example, :arrow_up: will look like this:

ServerEvents.recipes(event => {
  event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})
mortal crypt
#

use event.createCustom and pass it a supplier

gloomy helm
#

^

mortal crypt
#

event.createCustom('my_id', () => new MyThing())

lavish tendon
#

Thank you! I'll try it!

#

I did not get an error this way launching the game, but there were no cow_bait custom item, but strangely the cow spawn egg lost it's color.

gloomy helm
lavish tendon
#
e.createCustom('cow_bait', () => new $SpawnEggItem($EntityType.COW, 4470310, 10592673, new $ItemProperties))
gloomy helm
#

try this:

const $SpawnEggItem = Java.loadClass('net.minecraft.world.item.SpawnEggItem')
const $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')
const $EntityType = Java.loadClass('net.minecraft.world.entity.EntityType')

StartupEvents.registry('item', e => {
    e.createCustom('cow_bait', () => new $SpawnEggItem($EntityType.COW, 4470310, 10592673, new $ItemProperties()))
})
lavish tendon
#

I'll try it

#

The same thing happened this way too

gloomy helm
mortal crypt
#

use forges spawn egg item

#

net.minecraftforge.common.ForgeSpawnEggItem
public ForgeSpawnEggItem(Supplier<? extends EntityType<? extends Mob>> type, int backgroundColor, int highlightColor, Properties props)

lavish tendon
#
const $ForgeSpawnEggItem = Java.loadClass('net.minecraftforge.common.ForgeSpawnEggItem')
const $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')
const $EntityType = Java.loadClass('net.minecraft.world.entity.EntityType')
StartupEvents.registry('item', e => {
    e.createCustom('cow_bait', () => new $ForgeSpawnEggItem($EntityType.COW, 4470310, 10592673, new $ItemProperties()))
})

The game crashes:
The game crashed whilst initializing game
Error: java.lang.RuntimeException: null

gloomy helm
#

send the full error

lavish tendon
grave creekBOT
#

Paste version of message.txt from @lavish tendon

mortal crypt
#

the first arg needs to be a supplier for the forge egg

#

see the constructor args i pasted

lavish tendon
#

damn sorry i didnt see that

#

Sorry I'm new to all this and I don't really understand what are suppliers or how to use them, so if you could maybe help me out again, I would be very grateful

mortal crypt
#

put () => before it

lavish tendon
#
const $ForgeSpawnEggItem = Java.loadClass('net.minecraftforge.common.ForgeSpawnEggItem')
const $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')
const $EntityType = Java.loadClass('net.minecraft.world.entity.EntityType')
StartupEvents.registry('item', e => {
    e.createCustom('cow_bait', () => new $ForgeSpawnEggItem(() => $EntityType.COW, 4470310, 10592673, new $ItemProperties()))
})

Now there was no crash, but it seems that the item wasn't created. I can't find it with the give command.

mortal crypt
#

/give @s kubejs:cow_bait?

lavish tendon
#

I just restarted the game and it was there, sorry I don't know what happened

#

Thanks for the help!!!