Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a callback to change/override the pick block result. #907

Open
wants to merge 13 commits into
base: 2001
Choose a base branch
from

Conversation

Tcat2000
Copy link

Description

Adds a callback to change the pick block result.

Example Script

StartupEvents.registry("block", event => {
    event.create('example_block')
        .property(BlockProperties.AGE_4)
        .pickBlock(event => {
        	if(event.state.getValue(BlockProperties.AGE_4) == 4) event.setPickBlockItem("minecraft:stone");
        	else event.setPickBlockItem("kubejs:example_block");
        })
       ...

Other details

I am not familiar on callbacks, so if there is a way to have 'return' in the callback return the string, instead of 'event.setPickBlockItem' that would be an improvement, but I'm not sure how to do that myself.

@Tcat2000
Copy link
Author

Ignore all of the older commits, they were reverted for this pr

Comment on lines +774 to +776
* Sets random tick callback for this black.
*
* @param pickBlockCallback A callback using a block container and a random.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This javadoc is very wrong

import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;

public class PickBlockCallbackJS {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there no way to get a BlockContainerJS from here? Typically these callbacks provide one of those rather than the individual components that make it up such as BlockGetter, BlockState and BlockPos. Have a look at the other existing callbacks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, will do that.

@@ -31,6 +32,7 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like some random imports got added, you can run 'Optimise Imports' in Intellij to clean them up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants