Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
run: |
git config --global user.email "no-reply@github.com"
git config --global user.name "Github Actions"
./gradlew applyPatches --stacktrace
Copy link
Copy Markdown
Member

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!

Copy link
Copy Markdown
Author

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 😄

./gradlew applyAllPatches --stacktrace

- name: Build
run: ./gradlew build --stacktrace
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ You are very welcome to help with implementation, testing, sharing knowledge or
Fiddle is a drop-in replacement for Paper.

There are no builds available at the moment, but you can build Fiddle yourself by cloning the project and doing:
* `./gradlew applyPatches`
* `./gradlew applyAllPatches`
* Create a runnable server jar with `./gradlew createMojmapPaperclipJar` (the jar file will be placed in `fiddle-server/build/libs`)

You can easily run a test server (which [includes some example blocks and items](https://github.com/FiddleMC/Fiddle/blob/master/test-plugin/src/main/java/org/fiddlemc/testplugin/TestPluginBootstrap.java)):
* `./gradlew applyPatches`
* `./gradlew applyAllPatches`
* `./gradlew runDevServer`
<!--
You can download the latest stable JAR from [releases](https://github.com/FiddleMC/Fiddle/releases) and the latest development JAR from [actions](https://github.com/FiddleMC/Fiddle/actions).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
--- a/src/main/java/io/papermc/paper/registry/RegistryKey.java
+++ b/src/main/java/io/papermc/paper/registry/RegistryKey.java
@@ -39,6 +_,8 @@
@@ -39,6 +_,9 @@
import org.bukkit.map.MapCursor;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
+import org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.BlockEntityType;
+import org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.FiddleBlockType;
+import org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.FiddleItemType;
import org.jspecify.annotations.NullMarked;

import static io.papermc.paper.registry.RegistryKeyImpl.create;
@@ -77,6 +_,16 @@
@@ -77,6 +_,20 @@
* @see io.papermc.paper.registry.keys.MobEffectKeys
*/
RegistryKey<PotionEffectType> MOB_EFFECT = create("mob_effect");
Expand All @@ -22,6 +23,10 @@
+ * Built-in registry for Fiddle item types.
+ */
+ RegistryKey<FiddleItemType> FIDDLE_ITEM_TYPE = create("fiddle:item_type");
+ /**
+ * Built-in registry for block entity types.
+ */
+ RegistryKey<BlockEntityType> BLOCK_ENTITY_TYPE = create("block_entity_type");
+ // Fiddle end - More data-driven - Paper registry API - Types - API part - Define registry keys
/**
* Built-in registry for block types.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java
+++ b/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java
@@ -57,6 +_,14 @@
@@ -57,6 +_,15 @@
public static final RegistryEventProvider<ZombieNautilus.Variant, ZombieNautilusVariantRegistryEntry.Builder> ZOMBIE_NAUTILUS_VARIANT = create(RegistryKey.ZOMBIE_NAUTILUS_VARIANT);
public static final RegistryEventProvider<Dialog, DialogRegistryEntry.Builder> DIALOG = create(RegistryKey.DIALOG);
// End generate - RegistryEvents
Expand All @@ -11,6 +11,7 @@
+ // Fiddle start - More data-driven - Paper registry API - API part - Add event providers
+ public static final RegistryEventProvider<org.bukkit.block.BlockType, org.fiddlemc.fiddle.api.moredatadriven.paper.registry.BlockRegistryEntry.Builder> BLOCK = RegistryEventProviderImpl.create(RegistryKey.BLOCK);
+ public static final RegistryEventProvider<org.bukkit.inventory.ItemType, org.fiddlemc.fiddle.api.moredatadriven.paper.registry.ItemRegistryEntry.Builder> ITEM = RegistryEventProviderImpl.create(RegistryKey.ITEM);
+ public static final RegistryEventProvider<org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.BlockEntityType, org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.BlockEntityTypeRegistryEntry.Builder> BLOCK_ENTITY_TYPE = RegistryEventProviderImpl.create(RegistryKey.BLOCK_ENTITY_TYPE);
+ // Fiddle end - More data-driven - Paper registry API - API part - Add event providers

private RegistryEvents() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import org.fiddlemc.fiddle.api.bukkit.enuminjection.material.MaterialEnumNames;
import org.fiddlemc.fiddle.api.moredatadriven.paper.registry.BlockRegistryEntry;
import org.fiddlemc.fiddle.api.moredatadriven.paper.registry.ItemRegistryEntry;
import org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.BlockEntityType;
import org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.BlockEntityTypeRegistryEntry;
import org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.FiddleBlockTypeRegistryEntry;
import org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.FiddleItemTypeRegistryEntry;
import org.fiddlemc.fiddle.api.packetmapping.block.BlockMappings;
Expand Down Expand Up @@ -43,6 +45,7 @@ private FiddleEvents() {
public static final LifecycleEventType.Prioritizable<BootstrapContext, RegistryComposeEvent<?, FiddleItemTypeRegistryEntry.Builder>> ITEM_TYPE = (LifecycleEventType.Prioritizable) RegistryEvents.ITEM_TYPE.compose();
public static final LifecycleEventType.Prioritizable<BootstrapContext, RegistryComposeEvent<BlockType, BlockRegistryEntry.Builder>> BLOCK = RegistryEvents.BLOCK.compose();
public static final LifecycleEventType.Prioritizable<BootstrapContext, RegistryComposeEvent<ItemType, ItemRegistryEntry.Builder>> ITEM = RegistryEvents.ITEM.compose();
public static final LifecycleEventType.Prioritizable<BootstrapContext, RegistryComposeEvent<BlockEntityType, BlockEntityTypeRegistryEntry.Builder>> BLOCK_ENTITY_TYPE = RegistryEvents.BLOCK_ENTITY_TYPE.compose();
public static final ComposableEventType<FiddleResourcePackConstructEvent> RESOURCE_PACK_CONSTRUCT = FiddleResourcePackConstruction.get().compose();
public static final LifecycleEventType<BootstrapContext, FiddleResourcePackConstructFinishEvent, PrioritizedLifecycleEventHandlerConfiguration<BootstrapContext>> RESOURCE_PACK_CONSTRUCT_FINISH = FiddleResourcePackConstruction.get().finish();
public static final ComposableEventType<BlockMappingsComposeEvent<?>> BLOCK_MAPPING = ((BlockMappings) BlockMappings.get()).compose();
Expand Down
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 {
}
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/net/minecraft/core/registries/BuiltInRegistries.java
+++ b/net/minecraft/core/registries/BuiltInRegistries.java
@@ -172,12 +_,12 @@
@@ -172,16 +_,25 @@
public static final Registry<SoundEvent> SOUND_EVENT = registerSimple(Registries.SOUND_EVENT, registry -> SoundEvents.ITEM_PICKUP);
public static final DefaultedRegistry<Fluid> FLUID = registerDefaultedWithIntrusiveHolders(Registries.FLUID, "empty", registry -> Fluids.EMPTY);
public static final Registry<MobEffect> MOB_EFFECT = registerSimple(Registries.MOB_EFFECT, MobEffects::bootstrap);
Expand All @@ -14,14 +14,29 @@
+ public static final org.fiddlemc.fiddle.impl.moredatadriven.minecraft.ItemRegistry ITEM = internalRegister(Registries.ITEM, org.fiddlemc.fiddle.impl.moredatadriven.minecraft.ItemRegistry.get(), registry -> Items.AIR); // Fiddle - More data-driven - Minecraft registries - Use custom class
public static final Registry<Potion> POTION = registerSimple(Registries.POTION, Potions::bootstrap);
public static final Registry<ParticleType<?>> PARTICLE_TYPE = registerSimple(Registries.PARTICLE_TYPE, registry -> ParticleTypes.BLOCK);
public static final Registry<BlockEntityType<?>> BLOCK_ENTITY_TYPE = registerSimpleWithIntrusiveHolders(
- public static final Registry<BlockEntityType<?>> BLOCK_ENTITY_TYPE = registerSimpleWithIntrusiveHolders(
- Registries.BLOCK_ENTITY_TYPE, registry -> BlockEntityType.FURNACE
+ // Fiddle start - More data-driven - Block entities - Use delayed freezing
+ public static final Registry<BlockEntityType<?>> BLOCK_ENTITY_TYPE = internalRegister(
+ Registries.BLOCK_ENTITY_TYPE,
+ new MappedRegistry<>(Registries.BLOCK_ENTITY_TYPE, Lifecycle.stable(), true) {
+ @Override
+ public boolean isFreezingDelayed() {
+ return true;
+ }
+ },
+ registry -> BlockEntityType.FURNACE
+ // Fiddle end - More data-driven - Block entities - Use delayed freezing
);
public static final Registry<Identifier> CUSTOM_STAT = registerSimple(Registries.CUSTOM_STAT, registry -> Stats.JUMP);
public static final DefaultedRegistry<ChunkStatus> CHUNK_STATUS = registerDefaulted(Registries.CHUNK_STATUS, "empty", registry -> ChunkStatus.EMPTY);
@@ -278,7 +_,8 @@
public static final Registry<MapCodec<? extends DensityFunction>> DENSITY_FUNCTION_TYPE = registerSimple(
Registries.DENSITY_FUNCTION_TYPE, DensityFunctions::bootstrap
);
- public static final Registry<MapCodec<? extends Block>> BLOCK_TYPE = registerSimple(Registries.BLOCK_TYPE, BlockTypes::bootstrap);
+ public static final Registry<org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.nms.WrappedBlockCodec<?>> FIDDLE_BLOCK_TYPE = registerSimple(Registries.FIDDLE_BLOCK_TYPE, BlockTypes::bootstrap); // Fiddle - More data-driven - Minecraft registries - Types - Adapt existing block type registry
+ public static final Registry<org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.nms.WrappedItemCodec<?>> FIDDLE_ITEM_TYPE = registerSimple(Registries.FIDDLE_ITEM_TYPE, org.fiddlemc.fiddle.impl.moredatadriven.minecraft.type.ItemTypes::bootstrap); // Fiddle - More data-driven - Minecraft registries - Types - Add item type registry
+ public static final Registry<org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.nms.WrappedBlockCodec<?>> FIDDLE_BLOCK_TYPE = BuiltInRegistries.<org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.nms.WrappedBlockCodec<?>>registerSimple(Registries.FIDDLE_BLOCK_TYPE, BlockTypes::bootstrap); // Fiddle - More data-driven - Minecraft registries - Types - Adapt existing block type registry
+ public static final Registry<org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.nms.WrappedItemCodec<?>> FIDDLE_ITEM_TYPE = BuiltInRegistries.<org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.nms.WrappedItemCodec<?>>registerSimple(Registries.FIDDLE_ITEM_TYPE, org.fiddlemc.fiddle.impl.moredatadriven.minecraft.type.ItemTypes::bootstrap); // Fiddle - More data-driven - Minecraft registries - Types - Add item type registry
public static final Registry<StructureProcessorType<?>> STRUCTURE_PROCESSOR = registerSimple(
Registries.STRUCTURE_PROCESSOR, registry -> StructureProcessorType.BLOCK_IGNORE
);
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
// Paper start - Anti-Xray - Add chunk packet info
if (chunkPacketInfo != null) {
chunkPacketInfo.setBuffer(this.buffer);
@@ -62,6 +_,7 @@
int totalTileEntities = 0; // Paper - Handle oversized block entities in chunks

for (Entry<BlockPos, BlockEntity> entry : levelChunk.getBlockEntities().entrySet()) {
+ if (!entry.getValue().getType().isVanilla()) return; // Fiddle - More data-driven - Block entities - Don't send non-vanilla block entities to the client
// Paper start - Handle oversized block entities in chunks
if (++totalTileEntities > BLOCK_ENTITY_LIMIT) {
net.minecraft.network.protocol.Packet<ClientGamePacketListener> packet = entry.getValue().getUpdatePacket();
@@ -82,6 +_,7 @@
throw new RuntimeException("Chunk Packet trying to allocate too much memory on read.");
} else {
Expand Down
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/src/main/java/io/papermc/paper/registry/PaperRegistries.java
+++ b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
@@ -110,8 +_,14 @@
@@ -110,8 +_,15 @@
start(Registries.GAME_EVENT, RegistryKey.GAME_EVENT).craft(GameEvent.class, CraftGameEvent::new).writable(PaperGameEventRegistryEntry.PaperBuilder::new),
start(Registries.STRUCTURE_TYPE, RegistryKey.STRUCTURE_TYPE).craft(StructureType.class, CraftStructureType::new).build(),
start(Registries.MOB_EFFECT, RegistryKey.MOB_EFFECT).craft(PotionEffectType.class, CraftPotionEffectType::new).build(),
Expand All @@ -13,6 +13,7 @@
+ // Fiddle start - More data-driven - Paper registry API - Implementation part - Make writable and delayed
+ start(Registries.BLOCK, RegistryKey.BLOCK).craft(BlockType.class, CraftBlockType::new).writable(org.fiddlemc.fiddle.impl.moredatadriven.paper.registry.BlockRegistryEntryImpl.BuilderImpl::new).delayed(),
+ start(Registries.ITEM, RegistryKey.ITEM).craft(ItemType.class, CraftItemType::new).writable(org.fiddlemc.fiddle.impl.moredatadriven.paper.registry.ItemRegistryEntryImpl.BuilderImpl::new).delayed(),
+ start(Registries.BLOCK_ENTITY_TYPE, RegistryKey.BLOCK_ENTITY_TYPE).craft(org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type.BlockEntityType.class, org.fiddlemc.fiddle.impl.moredatadriven.paper.registry.type.BlockEntityTypeImpl::of).writable(org.fiddlemc.fiddle.impl.moredatadriven.paper.registry.type.BlockEntityTypeRegistryEntryImpl.BuilderImpl::new).delayed(),
+ // Fiddle end - More data-driven - Paper registry API - Implementation part - Make writable and delayed
start(Registries.VILLAGER_PROFESSION, RegistryKey.VILLAGER_PROFESSION).craft(Villager.Profession.class, CraftVillager.CraftProfession::new).build(),
start(Registries.VILLAGER_TYPE, RegistryKey.VILLAGER_TYPE).craft(Villager.Type.class, CraftVillager.CraftType::new).build(),
Expand Down
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());
}

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);
Loading