-
Notifications
You must be signed in to change notification settings - Fork 3
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
ModernSpout:target-for-pr-4
Choose a base branch
from
Alvinn8:block-entities
base: target-for-pr-4
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 3 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
6 changes: 6 additions & 0 deletions
6
...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,6 @@ | ||
| package org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type; | ||
|
|
||
| import org.bukkit.Keyed; | ||
|
|
||
| public interface BlockEntityType extends Keyed { | ||
| } |
10 changes: 10 additions & 0 deletions
10
.../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,10 @@ | ||
| package org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type; | ||
|
|
||
| import io.papermc.paper.registry.RegistryBuilder; | ||
|
|
||
| public interface BlockEntityTypeRegistryEntry { | ||
|
|
||
| interface Builder extends RegistryBuilder<BlockEntityType> { | ||
|
|
||
| } | ||
| } |
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
20 changes: 20 additions & 0 deletions
20
...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,20 @@ | ||
| --- a/net/minecraft/world/level/block/entity/BlockEntityType.java | ||
| +++ b/net/minecraft/world/level/block/entity/BlockEntityType.java | ||
| @@ -292,7 +_,7 @@ | ||
| return Registry.register(BuiltInRegistries.BLOCK_ENTITY_TYPE, name, new BlockEntityType<>(factory, Set.of(validBlocks))); | ||
| } | ||
|
|
||
| - 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
11 changes: 11 additions & 0 deletions
11
...le/api/moredatadriven/paper/registry/type/nms/BlockEntityTypeRegistryEntryBuilderNMS.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,11 @@ | ||
| package org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.nms; | ||
|
|
||
| import net.minecraft.world.level.block.Block; | ||
| import net.minecraft.world.level.block.entity.BlockEntityType; | ||
| import org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.BlockEntityTypeRegistryEntry; | ||
|
|
||
| public interface BlockEntityTypeRegistryEntryBuilderNMS extends BlockEntityTypeRegistryEntry.Builder { | ||
| BlockEntityTypeRegistryEntryBuilderNMS factorNMS(BlockEntityType.BlockEntitySupplier<?> factory); | ||
|
|
||
| BlockEntityTypeRegistryEntryBuilderNMS validBlocksNMS(Block... 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
16 changes: 16 additions & 0 deletions
16
...java/org/fiddlemc/fiddle/impl/moredatadriven/paper/registry/type/BlockEntityTypeImpl.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,16 @@ | ||
| package org.fiddlemc.fiddle.impl.moredatadriven.paper.registry.type; | ||
|
|
||
| import io.papermc.paper.registry.HolderableBase; | ||
| import net.minecraft.core.Holder; | ||
| import net.minecraft.world.level.block.entity.BlockEntityType; | ||
|
|
||
| public class BlockEntityTypeImpl extends HolderableBase<BlockEntityType<?>> implements org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.BlockEntityType { | ||
|
|
||
| protected BlockEntityTypeImpl(final Holder<BlockEntityType<?>> holder) { | ||
| super(holder); | ||
| } | ||
|
|
||
| public static BlockEntityTypeImpl of(Holder<BlockEntityType<?>> holder) { | ||
| return new BlockEntityTypeImpl(holder); | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
...lemc/fiddle/impl/moredatadriven/paper/registry/type/BlockEntityTypeRegistryEntryImpl.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,48 @@ | ||
| package org.fiddlemc.fiddle.impl.moredatadriven.paper.registry.type; | ||
|
|
||
| import io.papermc.paper.registry.PaperRegistryBuilder; | ||
| import io.papermc.paper.registry.data.util.Conversions; | ||
| import net.minecraft.world.level.block.Block; | ||
| import net.minecraft.world.level.block.entity.BlockEntityType; | ||
| import org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.nms.BlockEntityTypeRegistryEntryBuilderNMS; | ||
| import org.jspecify.annotations.Nullable; | ||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| public class BlockEntityTypeRegistryEntryImpl { | ||
| protected @Nullable BlockEntityType<?> internal; | ||
|
|
||
| public BlockEntityTypeRegistryEntryImpl( | ||
| Conversions conversions, | ||
| @Nullable BlockEntityType<?> internal | ||
| ) { | ||
| this.internal = internal; | ||
| } | ||
|
|
||
| public static final class BuilderImpl implements BlockEntityTypeRegistryEntryBuilderNMS, PaperRegistryBuilder<net.minecraft.world.level.block.entity.BlockEntityType<?>, org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.BlockEntityType> { | ||
| private BlockEntityType.@Nullable BlockEntitySupplier<?> factory; | ||
| private final Set<Block> validBlocks = new HashSet<>(); | ||
|
|
||
| public BuilderImpl(Conversions conversions, @Nullable BlockEntityType<?> internal) {} | ||
|
|
||
| @Override | ||
| public BlockEntityTypeRegistryEntryBuilderNMS factorNMS(BlockEntityType.BlockEntitySupplier<?> factory) { | ||
| this.factory = factory; | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public BlockEntityTypeRegistryEntryBuilderNMS validBlocksNMS(final Block... blocks) { | ||
| this.validBlocks.addAll(Set.of(blocks)); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public BlockEntityType<?> build() { | ||
| if (this.factory == null) { | ||
| throw new IllegalStateException("Factory must be set before building a BlockEntityType."); | ||
| } | ||
| return new BlockEntityType<>(this.factory, this.validBlocks); | ||
| } | ||
| } | ||
| } |
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
40 changes: 40 additions & 0 deletions
40
test-plugin/src/main/java/org/fiddlemc/testplugin/TestBlock.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.testplugin; | ||
|
|
||
| import com.mojang.serialization.MapCodec; | ||
| import net.minecraft.core.BlockPos; | ||
| import net.minecraft.network.chat.Component; | ||
| import net.minecraft.world.InteractionResult; | ||
| import net.minecraft.world.entity.player.Player; | ||
| import net.minecraft.world.level.Level; | ||
| import net.minecraft.world.level.block.BaseEntityBlock; | ||
| import net.minecraft.world.level.block.entity.BlockEntity; | ||
| import net.minecraft.world.level.block.state.BlockState; | ||
| import net.minecraft.world.phys.BlockHitResult; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| public class TestBlock extends BaseEntityBlock { | ||
|
|
||
| protected TestBlock(final Properties properties) { | ||
| super(properties); | ||
| } | ||
|
|
||
| @Override | ||
| protected MapCodec<? extends BaseEntityBlock> codec() { | ||
| return simpleCodec(TestBlock::new); | ||
| } | ||
|
|
||
| @Override | ||
| public @Nullable BlockEntity newBlockEntity(final BlockPos blockPos, final BlockState blockState) { | ||
| return new TestBlockEntity(blockPos, blockState); | ||
| } | ||
|
|
||
| @Override | ||
| protected InteractionResult useWithoutItem(final BlockState state, final Level level, final BlockPos pos, final Player player, final BlockHitResult hitResult) { | ||
| BlockEntity blockEntity = level.getBlockEntity(pos); | ||
| if (blockEntity instanceof TestBlockEntity testBlockEntity) { | ||
| testBlockEntity.incrementCount(); | ||
| player.displayClientMessage(Component.literal("Count: " + testBlockEntity.getCount()), false); | ||
| } | ||
| return InteractionResult.SUCCESS_SERVER; | ||
| } | ||
| } |
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 😄