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

Bonemeal API #78

Merged
merged 7 commits into from
Nov 3, 2023
Merged

Conversation

paulevsGitch
Copy link
Contributor

Simple API to add more blocks into bonemeal actions.

Blocks can override onBonemealUse method to change their state when bonemeal was performed on them (in test mod obsidian will turn into log block).

Plants/Structures can be added into BonemealAPI to be generated on specified terrain. In test mod you can use bonemeal on sand to grow bookshelves.

PR is ready for review

2023-10-30_14 51 22

@mineLdiver mineLdiver self-requested a review October 30, 2023 12:28
}

static {
addPlant(BlockBase.GRASS.getDefaultState(), new GrassStructure(), 1);
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this replace the vanilla generation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it replaces vanilla generator since calling API cancels vanilla code

Copy link
Member

Choose a reason for hiding this comment

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

Flowers no longer generate because of this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now it should be fine

2023-10-30_16 15 20

Copy link
Member

Choose a reason for hiding this comment

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

Don't really understand why only grass generator is replaced out of all bonemeal generators

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you will not override it then:

  • If event is not cancellable custom plant will generate with too hight density and override vanilla grass. If its generation chance will be forced to be low it will be not possible to generate hight density plants
  • If event is cancellable then adding custom plant will stop any grass from spawning

Basically adding these generators just makes things simple - you get a complete control over custom plant density together with grass, and it will generate patches almost identical to vanilla

Copy link
Member

Choose a reason for hiding this comment

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

When you say "it will generate patches almost identical to vanilla", do you mean with custom plants or without?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both, by default it will generate vanilla grass and flowers in vanilla way, but you can add more flowers/grasses (or even structures) to generation pool, and they can have weight even larger than vanilla grass

Copy link
Member

Choose a reason for hiding this comment

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

I'm kind of hesitant of overriding vanilla generation like this. Though, to be fair, the original code does use ItemBase#rand which uses a different seed each run, so it probably won't affect anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That produces a result equal to vanilla code. It is possible to use more injects into vanilla code, but there will be no difference except worse performance and troubles for mods to mixin above that

# Conflicts:
#	station-items-v0/src/main/java/net/modificationstation/stationapi/api/bonemeal/BonemealAPI.java
@paulevsGitch
Copy link
Contributor Author

I added a small fix for missing Overworld biomes, it is a small fix so I didn't open another PR for it


public static void addPlant(TagKey<BlockBase> ground, Structure plant, int weight) {
BlockRegistry.INSTANCE.forEach(blockBase ->
blockBase.getStateManager().getStates().stream().filter(state -> state.isIn(ground)).forEach(state -> addPlant(state, plant, weight))
Copy link
Member

Choose a reason for hiding this comment

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

Caching states from tags like this is probably not a very good idea, tags are reloadable after all.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, original idea was to add plants to all blocks with tag, like "nether_ground" or similar things. I can adapt code to work with additional internal tag storage, that can solve this issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, now it should support both reloadable tags and states

@mineLdiver mineLdiver self-requested a review November 3, 2023 15:10
@mineLdiver mineLdiver merged commit 0e5ec99 into ModificationStation:master Nov 3, 2023
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