1.21.6 dev
Co-authored-by: Bjarne Koll <git@lynxplay.dev> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com> Co-authored-by: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Co-authored-by: Noah van der Aa <ndvdaa@gmail.com> Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com>
This commit is contained in:
committed by
Nassim Jahnke
parent
39203a65e0
commit
a24f9b204c
@@ -0,0 +1,40 @@
|
||||
--- a/net/minecraft/core/HolderLookup.java
|
||||
+++ b/net/minecraft/core/HolderLookup.java
|
||||
@@ -68,6 +_,9 @@
|
||||
}
|
||||
|
||||
public interface RegistryLookup<T> extends HolderLookup<T>, HolderOwner<T> {
|
||||
+
|
||||
+ Optional<T> getValueForCopying(ResourceKey<T> resourceKey); // Paper - add method to get the value for pre-filling builders in the reg mod API
|
||||
+
|
||||
ResourceKey<? extends Registry<? extends T>> key();
|
||||
|
||||
Lifecycle registryLifecycle();
|
||||
@@ -80,6 +_,13 @@
|
||||
|
||||
default HolderLookup.RegistryLookup<T> filterElements(final Predicate<T> predicate) {
|
||||
return new HolderLookup.RegistryLookup.Delegate<T>() {
|
||||
+ // Paper start - add getValueForCopying
|
||||
+ @Override
|
||||
+ public Optional<T> getValueForCopying(final ResourceKey<T> resourceKey) {
|
||||
+ return this.parent().getValueForCopying(resourceKey).filter(predicate);
|
||||
+ }
|
||||
+ // Paper end - add getValueForCopying
|
||||
+
|
||||
@Override
|
||||
public HolderLookup.RegistryLookup<T> parent() {
|
||||
return RegistryLookup.this;
|
||||
@@ -99,6 +_,13 @@
|
||||
|
||||
public interface Delegate<T> extends HolderLookup.RegistryLookup<T> {
|
||||
HolderLookup.RegistryLookup<T> parent();
|
||||
+
|
||||
+ // Paper start - add getValueForCopying
|
||||
+ @Override
|
||||
+ default Optional<T> getValueForCopying(ResourceKey<T> resourceKey) {
|
||||
+ return this.parent().getValueForCopying(resourceKey);
|
||||
+ }
|
||||
+ // Paper end - add getValueForCopying
|
||||
|
||||
@Override
|
||||
default ResourceKey<? extends Registry<? extends T>> key() {
|
||||
@@ -1,6 +1,6 @@
|
||||
--- a/net/minecraft/core/MappedRegistry.java
|
||||
+++ b/net/minecraft/core/MappedRegistry.java
|
||||
@@ -32,17 +_,18 @@
|
||||
@@ -32,17 +_,25 @@
|
||||
public class MappedRegistry<T> implements WritableRegistry<T> {
|
||||
private final ResourceKey<? extends Registry<T>> key;
|
||||
private final ObjectList<Holder.Reference<T>> byId = new ObjectArrayList<>(256);
|
||||
@@ -20,7 +20,14 @@
|
||||
private boolean frozen;
|
||||
@Nullable
|
||||
private Map<T, Holder.Reference<T>> unregisteredIntrusiveHolders;
|
||||
+ public final Map<ResourceLocation, T> temporaryUnfrozenMap = new HashMap<>(); // Paper - support pre-filling in registry mod API
|
||||
+ // Paper start - support pre-filling in registry mod API
|
||||
+ private final Map<ResourceLocation, T> temporaryUnfrozenMap = new HashMap<>();
|
||||
+
|
||||
+ @Override
|
||||
+ public Optional<T> getValueForCopying(final ResourceKey<T> resourceKey) {
|
||||
+ return this.frozen ? this.getOptional(resourceKey) : Optional.ofNullable(this.temporaryUnfrozenMap.get(resourceKey.location()));
|
||||
+ }
|
||||
+ // Paper end - support pre-filling in registry mod API
|
||||
|
||||
@Override
|
||||
public Stream<HolderSet.Named<T>> listTags() {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
--- a/net/minecraft/core/RegistrySetBuilder.java
|
||||
+++ b/net/minecraft/core/RegistrySetBuilder.java
|
||||
@@ -41,6 +_,13 @@
|
||||
final Map<ResourceKey<T>, Holder.Reference<T>> elements
|
||||
) {
|
||||
return new RegistrySetBuilder.EmptyTagRegistryLookup<T>(owner) {
|
||||
+ // Paper start - add getValueForCopying method
|
||||
+ @Override
|
||||
+ public Optional<T> getValueForCopying(final ResourceKey<T> resourceKey) {
|
||||
+ return this.get(resourceKey).map(Holder.Reference::value);
|
||||
+ }
|
||||
+ // Paper end - add getValueForCopying method
|
||||
+
|
||||
@Override
|
||||
public ResourceKey<? extends Registry<? extends T>> key() {
|
||||
return registryKey;
|
||||
@@ -121,6 +_,13 @@
|
||||
public <T> Optional<RegistryOps.RegistryInfo<T>> lookup(ResourceKey<? extends Registry<? extends T>> registryKey) {
|
||||
return getEntry(registryKey).map(Entry::opsInfo);
|
||||
}
|
||||
+
|
||||
+ // Paper start - add method to get the value for pre-filling builders in the reg mod API
|
||||
+ @Override
|
||||
+ public HolderLookup.Provider lookupForValueCopyViaBuilders() {
|
||||
+ throw new UnsupportedOperationException("Not implemented");
|
||||
+ }
|
||||
+ // Paper end - add method to get the value for pre-filling builders in the reg mod API
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -27,23 +27,27 @@
|
||||
+ // CraftBukkit end
|
||||
if (!serverLevel.isClientSide()) {
|
||||
BlockPos blockPos = blockSource.pos().relative(blockSource.state().getValue(DispenserBlock.FACING));
|
||||
- this.setSuccess(tryShearBeehive(serverLevel, blockPos) || tryShearLivingEntity(serverLevel, blockPos, item));
|
||||
+ this.setSuccess(tryShearBeehive(serverLevel, blockPos) || tryShearLivingEntity(serverLevel, blockPos, item, bukkitBlock, craftItem)); // CraftBukkit
|
||||
- this.setSuccess(tryShearBeehive(serverLevel, blockPos) || tryShearEntity(serverLevel, blockPos, item));
|
||||
+ this.setSuccess(tryShearBeehive(serverLevel, blockPos) || tryShearEntity(serverLevel, blockPos, item, bukkitBlock, craftItem)); // CraftBukkit
|
||||
if (this.isSuccess()) {
|
||||
item.hurtAndBreak(1, serverLevel, null, item1 -> {});
|
||||
}
|
||||
@@ -50,10 +_,18 @@
|
||||
@@ -50,14 +_,22 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
- private static boolean tryShearLivingEntity(ServerLevel level, BlockPos pos, ItemStack stack) {
|
||||
+ private static boolean tryShearLivingEntity(ServerLevel level, BlockPos pos, ItemStack stack, org.bukkit.block.Block bukkitBlock, org.bukkit.craftbukkit.inventory.CraftItemStack craftItem) { // CraftBukkit - add args
|
||||
for (LivingEntity livingEntity : level.getEntitiesOfClass(LivingEntity.class, new AABB(pos), EntitySelector.NO_SPECTATORS)) {
|
||||
if (livingEntity instanceof Shearable shearable && shearable.readyForShearing()) {
|
||||
- private static boolean tryShearEntity(ServerLevel level, BlockPos pos, ItemStack stack) {
|
||||
+ private static boolean tryShearEntity(ServerLevel level, BlockPos pos, ItemStack stack, org.bukkit.block.Block bukkitBlock, org.bukkit.craftbukkit.inventory.CraftItemStack craftItem) { // CraftBukkit - add args
|
||||
for (Entity entity : level.getEntitiesOfClass(Entity.class, new AABB(pos), EntitySelector.NO_SPECTATORS)) {
|
||||
if (entity.shearOffAllLeashConnections(null)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (entity instanceof Shearable shearable && shearable.readyForShearing()) {
|
||||
- shearable.shear(level, SoundSource.BLOCKS, stack);
|
||||
+ // CraftBukkit start
|
||||
+ // Paper start - Add drops to shear events
|
||||
+ org.bukkit.event.block.BlockShearEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockShearEntityEvent(livingEntity, bukkitBlock, craftItem, shearable.generateDefaultDrops(level, stack));
|
||||
+ org.bukkit.event.block.BlockShearEntityEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockShearEntityEvent(entity, bukkitBlock, craftItem, shearable.generateDefaultDrops(level, stack));
|
||||
+ if (event.isCancelled()) {
|
||||
+ // Paper end - Add drops to shear events
|
||||
+ continue;
|
||||
|
||||
@@ -1,32 +1,26 @@
|
||||
--- a/net/minecraft/core/registries/BuiltInRegistries.java
|
||||
+++ b/net/minecraft/core/registries/BuiltInRegistries.java
|
||||
@@ -311,6 +_,17 @@
|
||||
);
|
||||
@@ -325,6 +_,11 @@
|
||||
public static final Registry<MapCodec<? extends DialogBody>> DIALOG_BODY_TYPE = registerSimple(Registries.DIALOG_BODY_TYPE, DialogBodyTypes::bootstrap);
|
||||
public static final Registry<Consumer<GameTestHelper>> TEST_FUNCTION = registerSimple(Registries.TEST_FUNCTION, BuiltinTestFunctions::bootstrap);
|
||||
public static final Registry<? extends Registry<?>> REGISTRY = WRITABLE_REGISTRY;
|
||||
+ // Paper start - add built-in registry conversions
|
||||
+ public static final io.papermc.paper.registry.data.util.Conversions BUILT_IN_CONVERSIONS = new io.papermc.paper.registry.data.util.Conversions(new net.minecraft.resources.RegistryOps.RegistryInfoLookup() {
|
||||
+ @Override
|
||||
+ public <T> java.util.Optional<net.minecraft.resources.RegistryOps.RegistryInfo<T>> lookup(final ResourceKey<? extends Registry<? extends T>> registryRef) {
|
||||
+ final Registry<T> registry = net.minecraft.server.RegistryLayer.STATIC_ACCESS.lookupOrThrow(registryRef);
|
||||
+ return java.util.Optional.of(
|
||||
+ new net.minecraft.resources.RegistryOps.RegistryInfo<>(registry, registry, Lifecycle.experimental())
|
||||
+ );
|
||||
+ }
|
||||
+ });
|
||||
+ public static final io.papermc.paper.registry.data.util.Conversions STATIC_ACCESS_CONVERSIONS = new io.papermc.paper.registry.data.util.Conversions(
|
||||
+ new net.minecraft.resources.RegistryOps.HolderLookupAdapter(net.minecraft.server.RegistryLayer.STATIC_ACCESS)
|
||||
+ );
|
||||
+ // Paper end - add built-in registry conversions
|
||||
|
||||
private static <T> Registry<T> registerSimple(ResourceKey<? extends Registry<T>> key, BuiltInRegistries.RegistryBootstrap<T> bootstrap) {
|
||||
return internalRegister(key, new MappedRegistry<>(key, Lifecycle.stable(), false), bootstrap);
|
||||
@@ -336,6 +_,7 @@
|
||||
@@ -350,6 +_,7 @@
|
||||
ResourceKey<? extends Registry<T>> key, R registry, BuiltInRegistries.RegistryBootstrap<T> bootstrap
|
||||
) {
|
||||
Bootstrap.checkBootstrapCalled(() -> "registry " + key.location());
|
||||
+ io.papermc.paper.registry.PaperRegistryAccess.instance().registerRegistry(registry.key(), registry); // Paper - initialize API registry
|
||||
+ io.papermc.paper.registry.PaperRegistryAccess.instance().registerRegistry(registry); // Paper - initialize API registry
|
||||
ResourceLocation resourceLocation = key.location();
|
||||
LOADERS.put(resourceLocation, () -> bootstrap.run(registry));
|
||||
WRITABLE_REGISTRY.register((ResourceKey)key, registry, RegistrationInfo.BUILT_IN);
|
||||
@@ -343,16 +_,34 @@
|
||||
@@ -357,16 +_,34 @@
|
||||
}
|
||||
|
||||
public static void bootStrap() {
|
||||
@@ -61,11 +55,11 @@
|
||||
});
|
||||
}
|
||||
|
||||
@@ -361,6 +_,7 @@
|
||||
@@ -375,6 +_,7 @@
|
||||
|
||||
for (Registry<?> registry : REGISTRY) {
|
||||
bindBootstrappedTagsToEmpty(registry);
|
||||
+ io.papermc.paper.registry.PaperRegistryListenerManager.INSTANCE.runFreezeListeners(registry.key(), BUILT_IN_CONVERSIONS); // Paper
|
||||
+ io.papermc.paper.registry.PaperRegistryListenerManager.INSTANCE.runFreezeListeners(registry.key(), STATIC_ACCESS_CONVERSIONS); // Paper
|
||||
registry.freeze();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user