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

Add builders for BlockSetType and WoodType to replace registries #3115

Merged
merged 6 commits into from
Jul 3, 2023

Conversation

Shnupbups
Copy link
Contributor

@Shnupbups Shnupbups commented Jun 11, 2023

Adds BlockSetTypeBuilder and WoodTypeBuilder to replace BlockSetTypeRegistry and WoodTypeRegistry respectively.

The builder format is more suited to these as they have an large amount of values which aren't often changed. BlockSetTypeRegistry's register method in particular has a whopping 11 parameters, most of which are sound events that you'd have to try not to mess up the order on.

Previously, if you wanted a BlockSetType that was identical to BlockSetType.OAK except with custom button sounds and doors that require redstone to open, you'd have to write:

public static final BlockSetType MAPLE = BlockSetTypeRegistry.register(
	 new Identifier("mymod","maple"),
	 false,
	 BlockSoundGroup.WOOD,
	 SoundEvents.BLOCK_WOODEN_DOOR_CLOSE,
	 SoundEvents.BLOCK_WOODEN_DOOR_OPEN,
	 SoundEvents.BLOCK_WOODEN_TRAPDOOR_CLOSE,
	 SoundEvents.BLOCK_WOODEN_TRAPDOOR_OPEN,
	 SoundEvents.BLOCK_WOODEN_PRESSURE_PLATE_CLICK_OFF,
	 SoundEvents.BLOCK_WOODEN_PRESSURE_PLATE_CLICK_ON,
	 MyModSoundEvents.BLOCK_MAPLE_BUTTON_CLICK_OFF,
	 MyModSoundEvents.BLOCK_MAPLE_BUTTON_CLICK_ON
);

Now you can write simply:

public static final BlockSetType MAPLE = BlockSetTypeBuilder.copyOf(BlockSetType.OAK)
	 .openableByHand(false)
	 .buttonClickOffSound(MyModSoundEvents.BLOCK_MAPLE_BUTTON_CLICK_OFF)
	 .buttonClickOnSound(MyModSoundEvents.BLOCK_MAPLE_BUTTON_CLICK_ON)
	 .register(new Identifier("mymod","maple"));

Much clearer what each value does (particularly the openableByHand boolean value!), no need to worry about getting the order wrong for the many sound events, and the copyOf method allows to skip things that are already set just how you want them.

An added bonus is, that if Mojang decides to add new values to block set types or wood types (as they did in 1.20 by adding the openableByHand boolean!), where previously the already unwieldy register methods would need those new values added, changing the method signatures and making them even longer, now with the builder format we can simply add a new method.

All the values default to those used by the shortform constructors of BlockSetType and WoodType.

The old registry classes are deprecated in favour of these builders.

This can be backported to 1.19.4 (would need references to the openableByHand boolean removed).

Adds `BlockSetTypeBuilder` and `WoodTypeBuilder` to replace `BlockSetTypeRegistry` and `WoodTypeRegistry` respectively.
@Technici4n Technici4n requested a review from a team June 12, 2023 14:53
Separated the register and build methods, with the former calling the latter. Their relationship is explained in the javadoc.
Copy link
Member

@Technici4n Technici4n left a comment

Choose a reason for hiding this comment

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

Looks good, though someone else should check in an IDE that the names make sense.

@Technici4n Technici4n requested a review from a team June 23, 2023 16:07
@modmuss50 modmuss50 self-requested a review June 23, 2023 16:17
@modmuss50 modmuss50 added the last call If you care, make yourself heard right away! label Jun 23, 2023
@modmuss50 modmuss50 added the merge me please Pull requests that are ready to merge label Jul 2, 2023
@modmuss50 modmuss50 merged commit 6beca84 into FabricMC:1.20.1 Jul 3, 2023
5 checks passed
modmuss50 pushed a commit that referenced this pull request Jul 3, 2023
* Add builders for BlockSetType and WoodType to replace registries

Adds `BlockSetTypeBuilder` and `WoodTypeBuilder` to replace `BlockSetTypeRegistry` and `WoodTypeRegistry` respectively.

* whoops

* double whoops

* Register and Build now separate methods

Separated the register and build methods, with the former calling the latter. Their relationship is explained in the javadoc.

* Update BlockSetTypeBuilder.java

Signed-off-by: modmuss50 <modmuss50@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
last call If you care, make yourself heard right away! merge me please Pull requests that are ready to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants