-
Notifications
You must be signed in to change notification settings - Fork 1
Block entities using NMS #4
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
Open
Alvinn8
wants to merge
6
commits into
FiddleMC:master
Choose a base branch
from
Alvinn8:block-entities
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a2bc4a1
Use applyAllPatches instead of non-existing applyPatches
Alvinn8 bd914bd
Fix infinite recursion in factoryForBlockNMS
Alvinn8 18546fc
Add custom block entities using NMS
Alvinn8 e64295c
Do not send custom block entities to the client
Alvinn8 7651e5e
For now, return CraftBlockState for custom block entities to avoid error
Alvinn8 b96f116
Add validBlocks to builder for block entity types
Alvinn8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...main/java/org/fiddlemc/fiddle/api/moredatadriven/paper/registry/type/BlockEntityType.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type; | ||
|
|
||
| import org.bukkit.Keyed; | ||
|
|
||
| /** | ||
| * A type of block entity. | ||
| */ | ||
| public interface BlockEntityType extends Keyed { | ||
| } |
40 changes: 40 additions & 0 deletions
40
.../fiddlemc/fiddle/api/moredatadriven/paper/registry/type/BlockEntityTypeRegistryEntry.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type; | ||
|
|
||
| import io.papermc.paper.registry.RegistryBuilder; | ||
| import org.bukkit.block.BlockType; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
|
|
||
| /** | ||
| * A data-centric version-specific registry entry for the {@link BlockEntityType} type. | ||
| */ | ||
| @ApiStatus.Experimental | ||
| @ApiStatus.NonExtendable | ||
| public interface BlockEntityTypeRegistryEntry { | ||
|
|
||
| /** | ||
| * A mutable builder for the {@link BlockEntityTypeRegistryEntry}, | ||
| * that plugins may change in applicable registry events. | ||
| * <p> | ||
| * Currently, this must be cast to {@code BlockEntityTypeRegistryEntryBuilderNMS} to be used. | ||
| * </p> | ||
| * <p> | ||
| * It is mandatory to assign a factory. (Currently only possible using NMS) | ||
| * </p> | ||
| */ | ||
| @ApiStatus.Experimental | ||
| @ApiStatus.NonExtendable | ||
| interface Builder extends RegistryBuilder<BlockEntityType> { | ||
| /** | ||
| * Add block types that are valid for this block entity type. | ||
| * | ||
| * <p> | ||
| * For example, the shulker box block entity type would be valid for all the | ||
| * different colors of shulker box blocks. | ||
| * </p> | ||
| * | ||
| * @param blocks The block types. | ||
| * @return This builder, for chaining. | ||
| */ | ||
| Builder validBlocks(BlockType... blocks); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...s/sources/net/minecraft/network/protocol/game/ClientboundBlockEntityDataPacket.java.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- a/net/minecraft/network/protocol/game/ClientboundBlockEntityDataPacket.java | ||
| +++ b/net/minecraft/network/protocol/game/ClientboundBlockEntityDataPacket.java | ||
| @@ -28,6 +_,7 @@ | ||
| private final CompoundTag tag; | ||
|
|
||
| public static ClientboundBlockEntityDataPacket create(BlockEntity blockEntity, BiFunction<BlockEntity, RegistryAccess, CompoundTag> dataGetter) { | ||
| + if (!blockEntity.getType().isVanilla()) return null; // Fiddle - More data-driven - Block entities - Don't send non-vanilla block entities to the client | ||
| RegistryAccess registryAccess = blockEntity.getLevel().registryAccess(); | ||
| return new ClientboundBlockEntityDataPacket(blockEntity.getBlockPos(), blockEntity.getType(), blockEntity.sanitizeSentNbt(dataGetter.apply(blockEntity, registryAccess))); // Paper - Sanitize sent data | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...necraft-patches/sources/net/minecraft/world/level/block/entity/BlockEntityType.java.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| --- a/net/minecraft/world/level/block/entity/BlockEntityType.java | ||
| +++ b/net/minecraft/world/level/block/entity/BlockEntityType.java | ||
| @@ -277,6 +_,32 @@ | ||
| public final Set<Block> validBlocks; | ||
| private final Holder.Reference<BlockEntityType<?>> builtInRegistryHolder = BuiltInRegistries.BLOCK_ENTITY_TYPE.createIntrusiveHolder(this); | ||
|
|
||
| + // Fiddle start - More data-driven - Vanilla flag - Implementation part | ||
| + private boolean isVanilla; | ||
| + | ||
| + /** | ||
| + * Returns whether this block entity type is present in vanilla. | ||
| + * @return Whether this block is present in vanilla. | ||
| + */ | ||
| + public boolean isVanilla() { | ||
| + return this.isVanilla; | ||
| + } | ||
| + | ||
| + /** | ||
| + * Sets {@link #isVanilla} to true. | ||
| + * | ||
| + * <p> | ||
| + * This must only be called at most once, | ||
| + * before the block is registered to {@link BuiltInRegistries#BLOCK_ENTITY_TYPE}. | ||
| + * </p> | ||
| + * @return this. | ||
| + */ | ||
| + private BlockEntityType<T> markAsVanilla() { | ||
| + this.isVanilla = true; | ||
| + return this; | ||
| + } | ||
| + // Fiddle end - More data-driven - Vanilla flag - Implementation part | ||
| + | ||
| public static @Nullable Identifier getKey(BlockEntityType<?> type) { | ||
| return BuiltInRegistries.BLOCK_ENTITY_TYPE.getKey(type); | ||
| } | ||
| @@ -289,10 +_,10 @@ | ||
| } | ||
|
|
||
| Util.fetchChoiceType(References.BLOCK_ENTITY, name); | ||
| - return Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, name, new BlockEntityType<>(factory, Set.of(validBlocks))); | ||
| + return Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, name, new BlockEntityType<T>(factory, Set.of(validBlocks)).markAsVanilla()); // Fiddle - More data-driven - Block entities - mark as vanilla | ||
| } | ||
|
|
||
| - private BlockEntityType(BlockEntityType.BlockEntitySupplier<? extends T> factory, Set<Block> validBlocks) { | ||
| + public BlockEntityType(BlockEntityType.BlockEntitySupplier<? extends T> factory, Set<Block> validBlocks) { // Fiddle - More data-driven - Block entities - public | ||
| this.factory = factory; | ||
| this.validBlocks = validBlocks; | ||
| } | ||
| @@ -320,7 +_,7 @@ | ||
| } | ||
|
|
||
| @FunctionalInterface | ||
| - interface BlockEntitySupplier<T extends BlockEntity> { | ||
| + public interface BlockEntitySupplier<T extends BlockEntity> { // Fiddle - More data-driven - Block entities - public | ||
| T create(BlockPos pos, BlockState state); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...patches/files/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java | ||
| +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java | ||
| @@ -219,6 +_,7 @@ | ||
|
|
||
| @Nullable | ||
| public Packet<ClientGamePacketListener> getUpdatePacket(@NotNull Location location) { | ||
| + if (!this.snapshot.getType().isVanilla()) return null; // Fiddle - More data-driven - Block entities - Don't send non-vanilla block entities to the client | ||
| return new ClientboundBlockEntityDataPacket(CraftLocation.toBlockPosition(location), this.snapshot.getType(), this.getUpdateNBT()); | ||
| } | ||
|
|
10 changes: 10 additions & 0 deletions
10
...aper-patches/files/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java | ||
| +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java | ||
| @@ -72,6 +_,7 @@ | ||
| private static final BlockStateFactory<?> DEFAULT_FACTORY = new BlockStateFactory<>(CraftBlockState.class) { | ||
| @Override | ||
| public CraftBlockState createBlockState(World world, BlockPos pos, net.minecraft.world.level.block.state.BlockState state, BlockEntity blockEntity) { | ||
| + if (blockEntity != null && !blockEntity.getType().isVanilla()) return new CraftBlockState(world, pos, state); // Fiddle - More data-driven - Block entities - TODO provide API so that plugins can read data from custom block entities using the API. For now, return a generic CraftBlockState instead of erroring. | ||
| // Paper - revert upstream's revert of the block state changes. Block entities that have already had the block type set to AIR are still valid, upstream decided to ignore them | ||
| Preconditions.checkState(blockEntity == null, "Unexpected BlockState for %s", CraftBlockType.minecraftToBukkit(state.getBlock())); | ||
| return new CraftBlockState(world, pos, state); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked at the build file since Paperweight updated. I kind of didn't want there to be proper JARs at first haha. But now it's time!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Now it instead fails because the dev bundle is not published. So jars still have to wait if that is desirable 😄