Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
Contributor 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`
Comment thread
Alvinn8 marked this conversation as resolved.
* 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,6 @@
package org.fiddlemc.fiddle.api.moredatadriven.paper.registry.type;

import org.bukkit.Keyed;

public interface BlockEntityType extends Keyed {
}
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> {

}
}
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
Comment thread
Alvinn8 marked this conversation as resolved.
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,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);
}
}
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,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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public ItemRegistryEntryImpl.BuilderImpl factoryForBlockNMS() {

@Override
public ItemRegistryEntryImpl.BuilderImpl factoryForBlockNMS(Identifier blockIdentifier) {
return this.factoryForBlockNMS(blockIdentifier);
return this.factoryNMS(properties -> new BlockItem(BlockRegistry.get().getValue(blockIdentifier), properties));
Comment thread
Alvinn8 marked this conversation as resolved.
}

@Override
Expand Down
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);
}
}
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);
}
}
}
4 changes: 2 additions & 2 deletions test-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ version = "1.0.0-SNAPSHOT"

// Uncomment the lines below to include the dev bundle
// (after having published it by calling the script at gradle-bin/refreshTestPluginDevBundle)
// plugins { id("io.papermc.paperweight.userdev") version "2.0.0-beta.19" }
// dependencies { paperweight.paperDevBundle("1.21.11-R0.1-SNAPSHOT", "org.fiddlemc.fiddle") }
plugins { id("io.papermc.paperweight.userdev") version "2.0.0-beta.19" }
dependencies { paperweight.paperDevBundle("1.21.11-R0.1-SNAPSHOT", "org.fiddlemc.fiddle") }

repositories {
mavenLocal()
Expand Down
40 changes: 40 additions & 0 deletions test-plugin/src/main/java/org/fiddlemc/testplugin/TestBlock.java
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;
}
}
Loading