#Custom cake-like block

152 messages · Page 1 of 1 (latest)

vestal yew
#

Hi all, I am trying to make a custom pizza block, with the following properties:

  • The pizza must be placed and eaten slice by slice, similar to a cake.
  • Breaking the item, regardless of tool, drops nothing
  • The number of slices should be customizable
  • The nutritional value of the slices should be customizable

Following this post: (#1184426569012351017 message) I can make a cake, but I can't figure out how to change the number of "slices" or "bites"; it looks like it just copies the exact properties of the vanilla minecraft cake.

(Also, on 1.20.1, it appears that using .tab() on $ItemProperties causes an error

§7dev.latvian.mods.rhino.EcmaError: TypeError: Cannot find function tab in object net.minecraft.world.item.Item$Properties@73c6ae9d. (startup_scripts:pizza.js#20)```
that I believe may be related to this change: (https://stackoverflow.com/questions/76941006/minecraft-forge-item-properties-tab-method-cannot-be-resolved). )

I am aware that the addon KubeJS Delight allows for custom Farmer's Delight pie-type foods, but the documentation doesn't show any way to change the number of slices or the nutritional value of each slice.

Does anyone know: what would be the best way to go about this?
sweet dewBOT
#

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

tight ruinBOT
#

[➤](#1184426569012351017 message)
Welp if anyone wants to make custom cakes:

let $CakeBlock = Java.loadClass('net.minecraft.world.level.block.CakeBlock')
let $BlockProperties = Java.loadClass('net.minecraft.world.level.block.state.BlockBehaviour$Properties')
let $ItemProperties = Java.loadClass('net.minecraft.world.item.Item$Properties')
let $BlockItem = Java.loadClass('net.minecraft.world.item.BlockItem')
let $FoodProperties = Java.loadClass('net.minecraft.world.food.FoodProperties')
/** @description Food Builder for custom food. */
let $FoodBuilder = Java.loadClass('net.minecraft.world.food.FoodProperties$Builder')
let $KubeJS = Java.loadClass('dev.latvian.mods.kubejs.KubeJS')

/*
public static final Block CAKE = Blocks.register("cake", new CakeBlock(BlockBehaviour.Properties.of().forceSolidOn().strength(0.5f).sound(SoundType.WOOL).pushReaction(PushReaction.DESTROY)));
*/

StartupEvents.registry('block', event => {
    event.createCustom('kubejs:la_lettre_a_focalors', () => new $CakeBlock(new $BlockProperties.copy(Block.getBlock('cake'))))
    event.createCustom('kubejs:pour_la_justice', () => new $CakeBlock(new $BlockProperties.copy(Block.getBlock('cake'))))
})

StartupEvents.registry('item', event => {
    event.createCustom('kubejs:la_lettre_a_focalors', () => new $BlockItem('kubejs:la_lettre_a_focalors',
        new $ItemProperties().tab($KubeJS.tab).food(new $FoodBuilder()
            .nutrition(2)
            .saturationMod(0.5)
            .fast()
            .build()
        )
    ))
    event.createCustom('kubejs:pour_la_justice', () => new $BlockItem('kubejs:pour_la_justice',
        new $ItemProperties().tab($KubeJS.tab).food(new $FoodBuilder()
            .nutrition(2)
            .saturationMod(0.5)
            .fast()
            .build()
        )
    ))
})
crisp lotus
#

Optionally if you have farmers delight installed you can reference that instead

#

I believe they have edible dishes more complex than a cake so you could look at that for how to make pizza dishes look slice proper slices and not pizza slivers

tardy canyon
#

From the vanilla cake it seems to be really hardcoded the amount of bites you can take

crisp lotus
#

Which is why I said look at farmers delight

#

It has pies with 4 slices iirc

tardy canyon
#

The amount of bites are referred in the block states and modifying them with kubejs is not possible for custom blocks

vestal yew
crisp lotus
#

Prob not too bad

#

You could check for a right click event, decrement a blockstate or nbt value and give food

crisp lotus
tardy canyon
#

No, you can only use the blockstates provided by farmers delight in general. The only exception would be if they have some sort of cake builder which does this dynamically

crisp lotus
#

Lytho and my direct reply are answering the top question btw

tardy canyon
#

There could be a change they have this, when they have multiple variants with different slices

crisp lotus
#

My first reply was the bottom question

crisp lotus
tardy canyon
#

Alternatively... how awful would it be to code what I want from scratch in KubeJS?

Completely in kubejs? not possible

crisp lotus
#

Nah it is

#

With some trickery using block entities etc

#

Definitely not ideal tho

tardy canyon
#

through block entities maybe. But thats not really nice

crisp lotus
#

Nope

#

Best to see if farmers delight has anything

tardy canyon
#

But with block states it's not possible as you need to override a method in the block class which is not possible with kubejs. There is maybe a Forge Event which can hook that, but I don't know one from my head. But I also don't remember all events

vestal yew
#

Okay, I think I understand. Sounds like my best bet is to see if Farmer's Delight has some kind of dynamic cake builder

crisp lotus
#

Yup

#

It might not be called cake builder though

#

Because I believe it has some roast chicken that does the same thing

vestal yew
#

Oh! hmmmmm

crisp lotus
#

It might be called sliced food builder if there is one

vestal yew
#

Farmer's Delight has a "feast"-type food item... and I know that KubeJS Delight can control how many "portions" a "feast" has...

crisp lotus
#

Or something more along those lines

crisp lotus
#

Assuming feast is like the roast chicken I was on about

vestal yew
#

I will look into this

tardy canyon
#

They don't have custom shapes (Hitbox). Is the shape for farmer delights cakes always the same no matter how many slices left

crisp lotus
#

No

#

It uses a voxel I think

#

public int getMaxBites() {

#

This is interesting

#

That function

#

If overridden

#

Could work

tardy canyon
#

also hardcoded then mmh

#

maybe time to add a cake block to kjs directly

vestal yew
crisp lotus
#

Any leads on the feast item

#

From the addon mod

vestal yew
tardy canyon
vestal yew
crisp lotus
#

Or just this

crisp lotus
tardy canyon
#

what is a feast item. JEI has no for feast

crisp lotus
#

It's what farmers delight calls the multi slice items as a group

crisp lotus
#

Thus does exactly what you want

vestal yew
#

I can't remember any examples, I think one of them is hoglin something (edit: I am mistaken, I am thinking of the Nether's Delight addon)

tardy canyon
#

dus?

crisp lotus
#

That's what I was on about yup

#

I'm on mobile rn

#

So I can't test

#

I'll get on my pc in a sec

tardy canyon
#

yeah its also hardcoded

#

ah no servings can be choosed, but it's not circular

#

for a pizza not that great

vestal yew
#

With the feast, it's a bit interesting - right clicking on the feast changes the blockstate, but then gives you a "portion" item, so you don't eat directly from the block

#

It's more like you "harvest" the block to get some item, and then eat the item

tardy canyon
#

yeah

tardy canyon
#

making 6 circular is not really possible as an example

#

or im too dumb for 3D

vestal yew
#

I am not familiar with model limitations

#

But, would it not be up to the user to decide what each successive model looks like?

tardy canyon
#

it can't really be diagonal

vestal yew
#

Ah I see

tardy canyon
#

so thats basic 4 slices

vestal yew
#

Well, there are square-cut pizzas

#

though that introduces problems for prime-numbered slices...

#

no wait

tardy canyon
#

this is how a 8 and 6 could look like

vestal yew
#

ugh

#

Prime-numbered slices would have to just have parallel cuts, like how vanilla cake is

tardy canyon
#

yeah but that kinda sucks for a pizza

crisp lotus
#

You can do diagonal

#

Just only 22.5 degree increments

crisp lotus
tardy canyon
#

no, shapes cannot be diagonal. Models can be, but then also they would clip in each other and may also has z fighting

crisp lotus
crisp lotus
#

Because its so much easier to make than circle ones

#

And fits the oven better

vestal yew
crisp lotus
tardy canyon
#

technically 32 are possible

#

1px wide lol

crisp lotus
#

They mean using diagonals

crisp lotus
vestal yew
crisp lotus
#

You're better off having square or rectangle slices

vestal yew
crisp lotus
#

That isn't hardcoded I don't think

#

That's just a model that could be overrided

#

Especially using KubeJS delight

dreamy steppe
#

Good thing people ask this type of thing so i can read it later, my dumbass would add a custom block for each state of the "cake" and then remove the slices with a right click event

tardy canyon
#

Thats not even a bad solution

#

Removing all item builders for the slices and just keep one item builder and update the loot tables correclty and you should be fine

#

Nice solution

vestal yew
tardy canyon
#

eh

#

iirc event.player.foodData and then idk which methods there exactly

#

Install probejs to get autocompletion there

tight ruinBOT
#

ProbeJS is an addon mod for KubeJS that generates typings files for VSCode, allowing VSCode to offer autocompletions for a ton of things!

Mod by @civic smelt

vestal yew
vestal yew
#

Okay, reporting back on my progress: creating the blocks was very straightforward and I believe I have the hunger/saturation mechanic working. However, when I right-click on the pizza it eats two slices at once

#

Here is the code for eating:

#
function eatBlock(ingredient, result) {
    BlockEvents.rightClicked(ingredient, event => {
        event.player.swing()
        if(event.player.getFoodLevel() < 20){
            event.block.set(result)
            event.player.setFoodLevel(event.player.getFoodLevel() + 7)
            event.player.setSaturation(event.player.getSaturation() + 7)
        }
    })
}

// Eat
eatBlock('kubejs:pizza_pie', 'kubejs:pizza_pie_slice1');
eatBlock('kubejs:pizza_pie_slice1', 'kubejs:pizza_pie_slice2');
eatBlock('kubejs:pizza_pie_slice2', 'kubejs:pizza_pie_slice3');
eatBlock('kubejs:pizza_pie_slice3', 'minecraft:air');
dreamy steppe
#

add a filter to check if the player is clicking with the main hand

#

event.player.hand iirc

vestal yew
#

The last thing is, for vanilla cake it's possible to eat the slices in creative mode

#

For my custom pizza, that doesn't seem to be working...

dreamy steppe
#

add a Or statement with event.player.isCreative()

vestal yew
#

IT WORKS!!!!

#

omg I am so happy, thank you everyone for your help!!

#

In case anyone else needs what I've done...

#

This is my pizza.js script that I placed in the startup_scripts folder:

StartupEvents.registry("block", (event) => {
    event.create("pizza_pie") // Create a new block
    .displayName("Test Pizza") // Set a custom name
    .hardness(0.5) // Set hardness (affects mining time)
    .resistance(0.5) // Set resistance (to explosions, etc)
    .tagBoth("hexpack_pizza:pizza") // Tag the block with `#my_namespace:my_other_tag`
    .mapColor('none') // block will not show up on maps
    .soundType('wool')
    .opaque(false)
    .fullBlock(false)
    .box(2, 0, 2, 14, 4, 14)
    .waterlogged()
    .noDrops()
    .noValidSpawns(true)
    .suffocating(false)
    .viewBlocking(true)
    .transparent(true)

    event.create("pizza_pie_slice1") // Create a new block
    .displayName("Test Pizza") // Set a custom name
    .hardness(0.5) // Set hardness (affects mining time)
    .resistance(0.5) // Set resistance (to explosions, etc)
    .noItem()
    .tagBlock("hexpack_pizza:pizza") // Tag the block with `#my_namespace:my_other_tag`
    .mapColor('none') // block will not show up on maps
    .soundType('wool')
    .opaque(false)
    .fullBlock(false)
    .box(2, 0, 2, 14, 4, 14)
    .waterlogged()
    .noDrops()
    .noValidSpawns(true)
    .suffocating(false)
    .viewBlocking(true)
    .transparent(true)

    event.create("pizza_pie_slice2") // Create a new block
    .displayName("Test Pizza") // Set a custom name
    .hardness(0.5) // Set hardness (affects mining time)
    .resistance(0.5) // Set resistance (to explosions, etc)
    .noItem()
    .tagBlock("hexpack_pizza:pizza") // Tag the block with `#my_namespace:my_other_tag`
    .mapColor('none') // block will not show up on maps
    .soundType('wool')
    .opaque(false)
    .fullBlock(false)
    .box(2, 0, 2, 14, 4, 14)
    .waterlogged()
    .noDrops()
    .noValidSpawns(true)
    .suffocating(false)
    .viewBlocking(true)
    .transparent(true)

    event.create("pizza_pie_slice3") // Create a new block
    .displayName("Test Pizza") // Set a custom name
    .hardness(0.5) // Set hardness (affects mining time)
    .resistance(0.5) // Set resistance (to explosions, etc)
    .noItem()
    .tagBlock("hexpack_pizza:pizza") // Tag the block with `#my_namespace:my_other_tag`
    .mapColor('none') // block will not show up on maps
    .soundType('wool')
    .opaque(false)
    .fullBlock(false)
    .box(2, 0, 2, 14, 4, 14)
    .waterlogged()
    .noDrops()
    .noValidSpawns(true)
    .suffocating(false)
    .viewBlocking(true)
    .transparent(true)
})
#

and this is my pizza_eating.js script that I placed in the server_scripts folder:

function eatBlock(ingredient, result) {
    BlockEvents.rightClicked(ingredient, event => {
        event.player.swing()
        if(
            (
                event.player.getFoodLevel() < 20 ||
                event.player.isCreative()
            ) &&
            event.hand == 'MAIN_HAND'
        )
        {
            event.block.set(result)
            event.player.setFoodLevel(event.player.getFoodLevel() + 7)
            event.player.setSaturation(event.player.getSaturation() + 7)
        }
    })
}

// Eat
eatBlock('kubejs:pizza_pie', 'kubejs:pizza_pie_slice1');
eatBlock('kubejs:pizza_pie_slice1', 'kubejs:pizza_pie_slice2');
eatBlock('kubejs:pizza_pie_slice2', 'kubejs:pizza_pie_slice3');
eatBlock('kubejs:pizza_pie_slice3', 'minecraft:air');
#

For my example, I chose four slices just to test

#

but one can set however many slices

#

It does require some work doing the models and textures for each block, but that is not a kubejs topic strictly speaking

#

The last thing I would ask is, by default kubejs automatically creates an item for the block. How do I change the texture for this item? I tried placing a file in kubejs/assets/textures/item/ but it does not seem to have worked

vestal yew
#

And with that all my dreams have come true

gray ore
#

like setting custom models, texture, and hitbox

crisp lotus
#

this ticket is really old

#

I directed you here to check it

#

but you already had your own ticket

#

please do not necro it

gray ore
#

oh sorry