This commit is contained in:
modmuss50 2024-01-24 19:59:21 +00:00
parent 3945d7aeb7
commit 9bfa344c7d
19 changed files with 87 additions and 232 deletions
fabric-lifecycle-events-v1/src/client/java/net/fabricmc/fabric/mixin/event/lifecycle/client
fabric-object-builder-api-v1/src/main
java/net/fabricmc/fabric/api/object/builder/v1/entity
resources
fabric-registry-sync-v0/src/main
fabric-transfer-api-v1/src/main/java/net/fabricmc/fabric/impl/transfer
fabric-transitive-access-wideners-v1
gradle.properties

View file

@ -101,8 +101,7 @@ abstract class ClientPlayNetworkHandlerMixin {
method = "onSynchronizeTags",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/client/network/ClientCommonNetworkHandler;onSynchronizeTags(Lnet/minecraft/network/packet/s2c/common/SynchronizeTagsS2CPacket;)V",
shift = At.Shift.AFTER, by = 1
target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;refreshTagBasedData()V"
)
)
private void hookOnSynchronizeTags(SynchronizeTagsS2CPacket packet, CallbackInfo ci) {

View file

@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableSet;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.Block;
import net.minecraft.class_9168;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
@ -422,7 +423,7 @@ public class FabricEntityTypeBuilder<T extends Entity> {
* @param <T> Entity class.
*/
public static class Mob<T extends MobEntity> extends FabricEntityTypeBuilder.Living<T> {
private SpawnRestriction.Location restrictionLocation;
private class_9168 spawnLocation;
private Heightmap.Type restrictionHeightmap;
private SpawnRestriction.SpawnPredicate<T> spawnPredicate;
@ -535,8 +536,8 @@ public class FabricEntityTypeBuilder<T extends Entity> {
*
* @return this builder for chaining.
*/
public FabricEntityTypeBuilder.Mob<T> spawnRestriction(SpawnRestriction.Location location, Heightmap.Type heightmap, SpawnRestriction.SpawnPredicate<T> spawnPredicate) {
this.restrictionLocation = Objects.requireNonNull(location, "Location cannot be null.");
public FabricEntityTypeBuilder.Mob<T> spawnRestriction(class_9168 spawnLocation, Heightmap.Type heightmap, SpawnRestriction.SpawnPredicate<T> spawnPredicate) {
this.spawnLocation = Objects.requireNonNull(spawnLocation, "Spawn location cannot be null.");
this.restrictionHeightmap = Objects.requireNonNull(heightmap, "Heightmap type cannot be null.");
this.spawnPredicate = Objects.requireNonNull(spawnPredicate, "Spawn predicate cannot be null.");
return this;
@ -547,7 +548,7 @@ public class FabricEntityTypeBuilder<T extends Entity> {
EntityType<T> type = super.build();
if (this.spawnPredicate != null) {
SpawnRestriction.register(type, this.restrictionLocation, this.restrictionHeightmap, this.spawnPredicate);
SpawnRestriction.register(type, this.spawnLocation, this.restrictionHeightmap, this.spawnPredicate);
}
return type;

View file

@ -8,7 +8,7 @@ accessible class net/minecraft/village/TradeOffers$TypeAwareBuyForOneEmeraldFact
mutable field net/minecraft/village/TradeOffers REBALANCED_PROFESSION_TO_LEVELED_TRADE Ljava/util/Map;
mutable field net/minecraft/village/TradeOffers REBALANCED_WANDERING_TRADER_TRADES Ljava/util/List;
accessible method net/minecraft/entity/SpawnRestriction register (Lnet/minecraft/entity/EntityType;Lnet/minecraft/entity/SpawnRestriction$Location;Lnet/minecraft/world/Heightmap$Type;Lnet/minecraft/entity/SpawnRestriction$SpawnPredicate;)V
accessible method net/minecraft/entity/SpawnRestriction register (Lnet/minecraft/entity/EntityType;Lnet/minecraft/class_9168;Lnet/minecraft/world/Heightmap$Type;Lnet/minecraft/entity/SpawnRestriction$SpawnPredicate;)V
accessible field net/minecraft/village/VillagerType BIOME_TO_TYPE Ljava/util/Map;
accessible method net/minecraft/village/VillagerType <init> (Ljava/lang/String;)V

View file

@ -140,8 +140,8 @@ public final class DynamicRegistries {
* @param <T> the entry type of the registry
*/
public static <T> void registerSynced(RegistryKey<? extends Registry<T>> key, Codec<T> dataCodec, Codec<T> networkCodec, SyncOption... options) {
DynamicRegistriesImpl.register(key, dataCodec);
DynamicRegistriesImpl.addSyncedRegistry(key, networkCodec, options);
RegistryLoader.Entry<T> entry = DynamicRegistriesImpl.register(key, dataCodec);
DynamicRegistriesImpl.addSyncedRegistry(entry, options);
}
/**

View file

@ -62,11 +62,4 @@ public interface DynamicRegistryView {
* @param callback the callback of the event
*/
<T> void registerEntryAdded(RegistryKey<? extends Registry<? extends T>> registryRef, RegistryEntryAddedCallback<T> callback);
/**
* A shortcut to register {@link RegistryEntryRemovedCallback}.
* @param registryRef the registry key of the registry to register the event to
* @param callback the callback of the event
*/
<T> void registerEntryRemoved(RegistryKey<? extends Registry<? extends T>> registryRef, RegistryEntryRemovedCallback<T> callback);
}

View file

@ -1,32 +0,0 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.fabricmc.fabric.api.event.registry;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.impl.registry.sync.ListenableRegistry;
@FunctionalInterface
public interface RegistryEntryRemovedCallback<T> {
void onEntryRemoved(int rawId, Identifier id, T object);
static <T> Event<RegistryEntryRemovedCallback<T>> event(Registry<T> registry) {
return ListenableRegistry.get(registry).fabric_getRemoveObjectEvent();
}
}

View file

@ -17,7 +17,6 @@
package net.fabricmc.fabric.impl.registry.sync;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
@ -29,7 +28,6 @@ import org.jetbrains.annotations.Unmodifiable;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryLoader;
import net.minecraft.registry.SerializableRegistries;
import net.fabricmc.fabric.api.event.registry.DynamicRegistries;
@ -52,7 +50,7 @@ public final class DynamicRegistriesImpl {
return List.copyOf(DYNAMIC_REGISTRIES);
}
public static <T> void register(RegistryKey<? extends Registry<T>> key, Codec<T> codec) {
public static <T> RegistryLoader.Entry<T> register(RegistryKey<? extends Registry<T>> key, Codec<T> codec) {
Objects.requireNonNull(key, "Registry key cannot be null");
Objects.requireNonNull(codec, "Codec cannot be null");
@ -63,22 +61,22 @@ public final class DynamicRegistriesImpl {
var entry = new RegistryLoader.Entry<>(key, codec);
DYNAMIC_REGISTRIES.add(entry);
FABRIC_DYNAMIC_REGISTRY_KEYS.add(key);
return entry;
}
public static <T> void addSyncedRegistry(RegistryKey<? extends Registry<T>> registryKey, Codec<T> networkCodec, DynamicRegistries.SyncOption... options) {
Objects.requireNonNull(registryKey, "Registry key cannot be null");
Objects.requireNonNull(networkCodec, "Network codec cannot be null");
public static <T> void addSyncedRegistry(RegistryLoader.Entry<T> entry, DynamicRegistries.SyncOption... options) {
Objects.requireNonNull(entry, "Registry loader entry cannot be null");
Objects.requireNonNull(options, "Options cannot be null");
if (!(SerializableRegistries.REGISTRIES instanceof HashMap<?, ?>)) {
SerializableRegistries.REGISTRIES = new HashMap<>(SerializableRegistries.REGISTRIES);
if (!(RegistryLoader.field_48709 instanceof ArrayList<RegistryLoader.Entry<?>>)) {
RegistryLoader.field_48709 = new ArrayList<>(RegistryLoader.field_48709);
}
SerializableRegistries.REGISTRIES.put(registryKey, new SerializableRegistries.Info<>(registryKey, networkCodec));
RegistryLoader.field_48709.add(entry);
for (DynamicRegistries.SyncOption option : options) {
if (option == DynamicRegistries.SyncOption.SKIP_WHEN_EMPTY) {
SKIP_EMPTY_SYNC_REGISTRIES.add(registryKey);
SKIP_EMPTY_SYNC_REGISTRIES.add(entry.key());
}
}
}

View file

@ -26,7 +26,6 @@ import net.minecraft.registry.RegistryKey;
import net.fabricmc.fabric.api.event.registry.DynamicRegistryView;
import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback;
import net.fabricmc.fabric.api.event.registry.RegistryEntryRemovedCallback;
public final class DynamicRegistryViewImpl implements DynamicRegistryView {
private final Map<RegistryKey<? extends Registry<?>>, Registry<?>> registries;
@ -78,14 +77,4 @@ public final class DynamicRegistryViewImpl implements DynamicRegistryView {
RegistryEntryAddedCallback.event(registry).register(callback);
}
}
@Override
@SuppressWarnings("unchecked")
public <T> void registerEntryRemoved(RegistryKey<? extends Registry<? extends T>> registryRef, RegistryEntryRemovedCallback<T> callback) {
Registry<T> registry = (Registry<T>) this.registries.get(registryRef);
if (registry != null) {
RegistryEntryRemovedCallback.event(registry).register(callback);
}
}
}

View file

@ -20,12 +20,10 @@ import net.minecraft.registry.Registry;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback;
import net.fabricmc.fabric.api.event.registry.RegistryEntryRemovedCallback;
import net.fabricmc.fabric.api.event.registry.RegistryIdRemapCallback;
public interface ListenableRegistry<T> {
Event<RegistryEntryAddedCallback<T>> fabric_getAddObjectEvent();
Event<RegistryEntryRemovedCallback<T>> fabric_getRemoveObjectEvent();
Event<RegistryIdRemapCallback<T>> fabric_getRemapEvent();
@SuppressWarnings("unchecked")
static <T> ListenableRegistry<T> get(Registry<T> registry) {

View file

@ -24,11 +24,10 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.collection.IdList;
import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback;
import net.fabricmc.fabric.api.event.registry.RegistryEntryRemovedCallback;
import net.fabricmc.fabric.api.event.registry.RegistryIdRemapCallback;
import net.fabricmc.fabric.impl.registry.sync.RemovableIdList;
public class IdListTracker<V, OV> implements RegistryEntryAddedCallback<V>, RegistryIdRemapCallback<V>, RegistryEntryRemovedCallback<V> {
public class IdListTracker<V, OV> implements RegistryEntryAddedCallback<V>, RegistryIdRemapCallback<V> {
private final String name;
private final IdList<OV> mappers;
private Map<Identifier, OV> removedMapperCache = new HashMap<>();
@ -42,7 +41,6 @@ public class IdListTracker<V, OV> implements RegistryEntryAddedCallback<V>, Regi
IdListTracker<V, OV> updater = new IdListTracker<>(name, mappers);
RegistryEntryAddedCallback.event(registry).register(updater);
RegistryIdRemapCallback.event(registry).register(updater);
RegistryEntryRemovedCallback.event(registry).register(updater);
}
@Override
@ -57,13 +55,4 @@ public class IdListTracker<V, OV> implements RegistryEntryAddedCallback<V>, Regi
public void onRemap(RemapState<V> state) {
((RemovableIdList<OV>) mappers).fabric_remapIds(state.getRawIdChangeMap());
}
@Override
public void onEntryRemoved(int rawId, Identifier id, V object) {
if (mappers.get(rawId) != null) {
removedMapperCache.put(id, mappers.get(rawId));
//noinspection unchecked
((RemovableIdList<OV>) mappers).fabric_removeId(rawId);
}
}
}

View file

@ -32,10 +32,9 @@ import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback;
import net.fabricmc.fabric.api.event.registry.RegistryEntryRemovedCallback;
import net.fabricmc.fabric.api.event.registry.RegistryIdRemapCallback;
public class Int2ObjectMapTracker<V, OV> implements RegistryEntryAddedCallback<V>, RegistryIdRemapCallback<V>, RegistryEntryRemovedCallback<V> {
public class Int2ObjectMapTracker<V, OV> implements RegistryEntryAddedCallback<V>, RegistryIdRemapCallback<V> {
private static final Logger LOGGER = LoggerFactory.getLogger(Int2ObjectMapTracker.class);
private final String name;
private final Int2ObjectMap<OV> mappers;
@ -50,7 +49,6 @@ public class Int2ObjectMapTracker<V, OV> implements RegistryEntryAddedCallback<V
Int2ObjectMapTracker<V, OV> updater = new Int2ObjectMapTracker<>(name, mappers);
RegistryEntryAddedCallback.event(registry).register(updater);
RegistryIdRemapCallback.event(registry).register(updater);
RegistryEntryRemovedCallback.event(registry).register(updater);
}
@Override
@ -91,13 +89,4 @@ public class Int2ObjectMapTracker<V, OV> implements RegistryEntryAddedCallback<V
throw new RuntimeException("Errors while remapping Int2ObjectMap " + name + " found:\n" + Joiner.on('\n').join(errors));
}
}
@Override
public void onEntryRemoved(int rawId, Identifier id, V object) {
OV mapper = mappers.remove(rawId);
if (mapper != null) {
removedMapperCache.put(id, mapper);
}
}
}

View file

@ -20,20 +20,17 @@ import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import com.mojang.datafixers.util.Pair;
import com.llamalad7.mixinextras.sugar.Local;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Coerce;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.MutableRegistry;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryLoader;
import net.minecraft.registry.RegistryOps;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.fabricmc.fabric.api.event.registry.DynamicRegistrySetupCallback;
@ -43,19 +40,18 @@ import net.fabricmc.fabric.impl.registry.sync.DynamicRegistryViewImpl;
@Mixin(RegistryLoader.class)
public class RegistryLoaderMixin {
@Inject(
method = "load(Lnet/minecraft/resource/ResourceManager;Lnet/minecraft/registry/DynamicRegistryManager;Ljava/util/List;)Lnet/minecraft/registry/DynamicRegistryManager$Immutable;",
method = "load(Lnet/minecraft/registry/RegistryLoader$RegistryLoadable;Lnet/minecraft/registry/DynamicRegistryManager;Ljava/util/List;)Lnet/minecraft/registry/DynamicRegistryManager$Immutable;",
at = @At(
value = "INVOKE",
target = "Ljava/util/List;forEach(Ljava/util/function/Consumer;)V",
ordinal = 0
),
locals = LocalCapture.CAPTURE_FAILHARD
)
)
private static void beforeLoad(ResourceManager resourceManager, DynamicRegistryManager baseRegistryManager, List<RegistryLoader.Entry<?>> entries, CallbackInfoReturnable<DynamicRegistryManager.Immutable> cir, Map a, List<Pair<MutableRegistry<?>, ?>> registriesList, RegistryOps.RegistryInfoGetter registryManager) {
private static void beforeLoad(@Coerce Object registryLoadable, DynamicRegistryManager baseRegistryManager, List<RegistryLoader.Entry<?>> entries, CallbackInfoReturnable<DynamicRegistryManager.Immutable> cir, @Local(ordinal = 1) List<RegistryLoader.class_9158<?>> registriesList) {
Map<RegistryKey<? extends Registry<?>>, Registry<?>> registries = new IdentityHashMap<>(registriesList.size());
for (Pair<MutableRegistry<?>, ?> pair : registriesList) {
registries.put(pair.getFirst().getKey(), pair.getFirst());
for (RegistryLoader.class_9158<?> entry : registriesList) {
registries.put(entry.registry().getKey(), entry.registry());
}
DynamicRegistrySetupCallback.EVENT.invoker().onRegistrySetup(new DynamicRegistryViewImpl(registries));

View file

@ -16,13 +16,11 @@
package net.fabricmc.fabric.mixin.registry.sync;
import java.util.stream.Stream;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.SerializableRegistries;
@ -32,17 +30,13 @@ import net.fabricmc.fabric.impl.registry.sync.DynamicRegistriesImpl;
// Implements skipping empty dynamic registries with the SKIP_WHEN_EMPTY sync option.
@Mixin(SerializableRegistries.class)
abstract class SerializableRegistriesMixin {
@Shadow
private static Stream<DynamicRegistryManager.Entry<?>> stream(DynamicRegistryManager dynamicRegistryManager) {
return null;
}
@Dynamic("method_45961: Stream.filter in stream")
@Inject(method = "method_56601", at = @At("HEAD"), cancellable = true)
private static void filterNonSyncedEntries(DynamicRegistryManager.Entry<?> entry, CallbackInfoReturnable<Boolean> cir) {
boolean canSkip = DynamicRegistriesImpl.SKIP_EMPTY_SYNC_REGISTRIES.contains(entry.key());
@Dynamic("method_45961: Codec.xmap in createDynamicRegistryManagerCodec")
@Redirect(method = "method_45961", at = @At(value = "INVOKE", target = "Lnet/minecraft/registry/SerializableRegistries;stream(Lnet/minecraft/registry/DynamicRegistryManager;)Ljava/util/stream/Stream;"))
private static Stream<DynamicRegistryManager.Entry<?>> filterNonSyncedEntries(DynamicRegistryManager drm) {
return stream(drm).filter(entry -> {
boolean canSkip = DynamicRegistriesImpl.SKIP_EMPTY_SYNC_REGISTRIES.contains(entry.key());
return !canSkip || entry.value().size() > 0;
});
if (canSkip && entry.value().size() == 0) {
cir.setReturnValue(false);
}
}
}

View file

@ -43,6 +43,7 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.registry.MutableRegistry;
@ -57,7 +58,6 @@ import net.fabricmc.fabric.api.event.EventFactory;
import net.fabricmc.fabric.api.event.registry.RegistryAttribute;
import net.fabricmc.fabric.api.event.registry.RegistryAttributeHolder;
import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback;
import net.fabricmc.fabric.api.event.registry.RegistryEntryRemovedCallback;
import net.fabricmc.fabric.api.event.registry.RegistryIdRemapCallback;
import net.fabricmc.fabric.impl.registry.sync.ListenableRegistry;
import net.fabricmc.fabric.impl.registry.sync.RegistrySyncManager;
@ -84,8 +84,6 @@ public abstract class SimpleRegistryMixin<T> implements MutableRegistry<T>, Rema
@Shadow
@Final
private Map<RegistryKey<T>, RegistryEntry.Reference<T>> keyToEntry;
@Shadow
private int nextId;
@Shadow
public abstract Optional<RegistryKey<T>> getKey(T entry);
@ -100,31 +98,10 @@ public abstract class SimpleRegistryMixin<T> implements MutableRegistry<T>, Rema
private static final Logger FABRIC_LOGGER = LoggerFactory.getLogger(SimpleRegistryMixin.class);
@Unique
private final Event<RegistryEntryAddedCallback<T>> fabric_addObjectEvent = EventFactory.createArrayBacked(RegistryEntryAddedCallback.class,
(callbacks) -> (rawId, id, object) -> {
for (RegistryEntryAddedCallback<T> callback : callbacks) {
callback.onEntryAdded(rawId, id, object);
}
}
);
private Event<RegistryEntryAddedCallback<T>> fabric_addObjectEvent;
@Unique
private final Event<RegistryEntryRemovedCallback<T>> fabric_removeObjectEvent = EventFactory.createArrayBacked(RegistryEntryRemovedCallback.class,
(callbacks) -> (rawId, id, object) -> {
for (RegistryEntryRemovedCallback<T> callback : callbacks) {
callback.onEntryRemoved(rawId, id, object);
}
}
);
@Unique
private final Event<RegistryIdRemapCallback<T>> fabric_postRemapEvent = EventFactory.createArrayBacked(RegistryIdRemapCallback.class,
(callbacks) -> (a) -> {
for (RegistryIdRemapCallback<T> callback : callbacks) {
callback.onRemap(a);
}
}
);
private Event<RegistryIdRemapCallback<T>> fabric_postRemapEvent;
@Unique
private Object2IntMap<Identifier> fabric_prevIndexedEntries;
@ -136,39 +113,31 @@ public abstract class SimpleRegistryMixin<T> implements MutableRegistry<T>, Rema
return fabric_addObjectEvent;
}
@Override
public Event<RegistryEntryRemovedCallback<T>> fabric_getRemoveObjectEvent() {
return fabric_removeObjectEvent;
}
@Override
public Event<RegistryIdRemapCallback<T>> fabric_getRemapEvent() {
return fabric_postRemapEvent;
}
// The rest of the registry isn't thread-safe, so this one need not be either.
@Unique
private boolean fabric_isObjectNew = false;
@Inject(method = "add", at = @At("RETURN"))
private <V extends T> void add(RegistryKey<Registry<T>> registryKey, V entry, Lifecycle lifecycle, CallbackInfoReturnable<V> info) {
onChange(registryKey);
}
@Inject(method = "set", at = @At("RETURN"))
private <V extends T> void set(int rawId, RegistryKey<Registry<T>> registryKey, V entry, Lifecycle lifecycle, CallbackInfoReturnable<RegistryEntry<T>> info) {
// We need to restore the 1.19 behavior of binding the value to references immediately.
// Unfrozen registries cannot be interacted with otherwise, because the references would throw when
// trying to access their values.
if (info.getReturnValue() instanceof RegistryEntry.Reference<T> reference) {
reference.setValue(entry);
}
onChange(registryKey);
@Inject(method = "<init>(Lnet/minecraft/registry/RegistryKey;Lcom/mojang/serialization/Lifecycle;Z)V", at = @At("RETURN"))
private void init(RegistryKey key, Lifecycle lifecycle, boolean intrusive, CallbackInfo ci) {
fabric_addObjectEvent = EventFactory.createArrayBacked(RegistryEntryAddedCallback.class,
(callbacks) -> (rawId, id, object) -> {
for (RegistryEntryAddedCallback<T> callback : callbacks) {
callback.onEntryAdded(rawId, id, object);
}
}
);
fabric_postRemapEvent = EventFactory.createArrayBacked(RegistryIdRemapCallback.class,
(callbacks) -> (a) -> {
for (RegistryIdRemapCallback<T> callback : callbacks) {
callback.onRemap(a);
}
}
);
}
@Unique
private void onChange(RegistryKey<Registry<T>> registryKey) {
private void onChange(RegistryKey<T> registryKey) {
if (RegistrySyncManager.postBootstrap || !VANILLA_NAMESPACES.contains(registryKey.getValue().getNamespace())) {
RegistryAttributeHolder holder = RegistryAttributeHolder.get(getKey());
@ -180,39 +149,15 @@ public abstract class SimpleRegistryMixin<T> implements MutableRegistry<T>, Rema
}
}
@Inject(method = "set", at = @At("HEAD"))
public void setPre(int id, RegistryKey<T> registryId, T object, Lifecycle lifecycle, CallbackInfoReturnable<RegistryEntry<T>> info) {
int indexedEntriesId = entryToRawId.getInt(object);
@Inject(method = "add", at = @At("RETURN"))
private void set(RegistryKey<T> key, T entry, Lifecycle lifecycle, CallbackInfoReturnable<RegistryEntry.Reference<T>> info) {
// We need to restore the 1.19 behavior of binding the value to references immediately.
// Unfrozen registries cannot be interacted with otherwise, because the references would throw when
// trying to access their values.
info.getReturnValue().setValue(entry);
if (indexedEntriesId >= 0) {
throw new RuntimeException("Attempted to register object " + object + " twice! (at raw IDs " + indexedEntriesId + " and " + id + " )");
}
if (!idToEntry.containsKey(registryId.getValue())) {
fabric_isObjectNew = true;
} else {
RegistryEntry.Reference<T> oldObject = idToEntry.get(registryId.getValue());
if (oldObject != null && oldObject.value() != null && oldObject.value() != object) {
int oldId = entryToRawId.getInt(oldObject.value());
if (oldId != id) {
throw new RuntimeException("Attempted to register ID " + registryId + " at different raw IDs (" + oldId + ", " + id + ")! If you're trying to override an item, use .set(), not .register()!");
}
fabric_removeObjectEvent.invoker().onEntryRemoved(oldId, registryId.getValue(), oldObject.value());
fabric_isObjectNew = true;
} else {
fabric_isObjectNew = false;
}
}
}
@Inject(method = "set", at = @At("RETURN"))
public void setPost(int id, RegistryKey<T> registryId, T object, Lifecycle lifecycle, CallbackInfoReturnable<RegistryEntry<T>> info) {
if (fabric_isObjectNew) {
fabric_addObjectEvent.invoker().onEntryAdded(id, registryId.getValue(), object);
}
fabric_addObjectEvent.invoker().onEntryAdded(entryToRawId.getInt(entry), key.getValue(), entry);
onChange(key);
}
@Override
@ -367,7 +312,6 @@ public abstract class SimpleRegistryMixin<T> implements MutableRegistry<T>, Rema
// entries was handled above, if it was necessary.
rawIdToEntry.clear();
entryToRawId.clear();
nextId = 0;
List<Identifier> orderedRemoteEntries = new ArrayList<>(remoteIndexedEntries.keySet());
orderedRemoteEntries.sort(Comparator.comparingInt(remoteIndexedEntries::getInt));
@ -389,14 +333,11 @@ public abstract class SimpleRegistryMixin<T> implements MutableRegistry<T>, Rema
continue;
}
// Add the new object, increment nextId to match.
// Add the new object
rawIdToEntry.size(Math.max(this.rawIdToEntry.size(), id + 1));
assert rawIdToEntry.get(id) == null;
rawIdToEntry.set(id, object);
entryToRawId.put(object.value(), id);
if (nextId <= id) {
nextId = id + 1;
}
}
fabric_getRemapEvent().invoker().onRemap(new RemapStateImpl<>(this, oldIdMap, idMap));

View file

@ -4,7 +4,7 @@ accessible field net/minecraft/registry/SimpleRegistry frozen Z
accessible method net/minecraft/registry/entry/RegistryEntry$Reference setValue (Ljava/lang/Object;)V
accessible method net/minecraft/registry/Registries init ()V
accessible class net/minecraft/registry/SerializableRegistries$Info
accessible method net/minecraft/registry/SerializableRegistries$Info <init> (Lnet/minecraft/registry/RegistryKey;Lcom/mojang/serialization/Codec;)V
accessible field net/minecraft/registry/SerializableRegistries REGISTRIES Ljava/util/Map;
mutable field net/minecraft/registry/SerializableRegistries REGISTRIES Ljava/util/Map;
accessible field net/minecraft/registry/RegistryLoader field_48709 Ljava/util/List;
mutable field net/minecraft/registry/RegistryLoader field_48709 Ljava/util/List;
accessible class net/minecraft/registry/RegistryLoader$class_9158

View file

@ -27,7 +27,7 @@ import net.minecraft.world.World;
public final class DebugMessages {
public static String forGlobalPos(@Nullable World world, BlockPos pos) {
String dimension = world != null ? world.getDimensionKey().getValue().toString() : "<no dimension>";
String dimension = world != null ? world.getDimensionEntry().getIdAsString() : "<no dimension>";
return dimension + "@" + pos.toShortString();
}

View file

@ -40,7 +40,7 @@ transitive-accessible class net/minecraft/village/TradeOffers$SellMapFactory
transitive-accessible class net/minecraft/village/TradeOffers$SellDyedArmorFactory
# Registering custom entity spawn restrictions
transitive-accessible method net/minecraft/entity/SpawnRestriction register (Lnet/minecraft/entity/EntityType;Lnet/minecraft/entity/SpawnRestriction$Location;Lnet/minecraft/world/Heightmap$Type;Lnet/minecraft/entity/SpawnRestriction$SpawnPredicate;)V
transitive-accessible method net/minecraft/entity/SpawnRestriction register (Lnet/minecraft/entity/EntityType;Lnet/minecraft/class_9168;Lnet/minecraft/world/Heightmap$Type;Lnet/minecraft/entity/SpawnRestriction$SpawnPredicate;)V
# Item usage context constructors
transitive-accessible method net/minecraft/item/ItemUsageContext <init> (Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/hit/BlockHitResult;)V

View file

@ -35,7 +35,7 @@ transitive-accessible class net/minecraft/village/TradeOffers$SellMapFactory
transitive-accessible class net/minecraft/village/TradeOffers$SellDyedArmorFactory
# Registering custom entity spawn restrictions
transitive-accessible method net/minecraft/entity/SpawnRestriction register (Lnet/minecraft/entity/EntityType;Lnet/minecraft/entity/SpawnRestriction$Location;Lnet/minecraft/world/Heightmap$Type;Lnet/minecraft/entity/SpawnRestriction$SpawnPredicate;)V
transitive-accessible method net/minecraft/entity/SpawnRestriction register (Lnet/minecraft/entity/EntityType;Lnet/minecraft/class_9168;Lnet/minecraft/world/Heightmap$Type;Lnet/minecraft/entity/SpawnRestriction$SpawnPredicate;)V
# Item usage context constructors
transitive-accessible method net/minecraft/item/ItemUsageContext <init> (Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/item/ItemStack;Lnet/minecraft/util/hit/BlockHitResult;)V

View file

@ -2,9 +2,9 @@ org.gradle.jvmargs=-Xmx2560M
org.gradle.parallel=true
fabric.loom.multiProjectOptimisation=true
version=0.95.1
minecraft_version=24w03b
yarn_version=+build.6
version=0.95.2
minecraft_version=24w04a
yarn_version=+build.1
loader_version=0.15.6
installer_version=0.11.1
@ -13,7 +13,7 @@ curseforge_minecraft_version=1.20.5-Snapshot
# Do not manually update, use the bumpversions task:
fabric-api-base-version=0.4.38
fabric-api-lookup-api-v1-version=1.6.49
fabric-api-lookup-api-v1-version=1.6.50
fabric-biome-api-v1-version=13.0.18
fabric-block-api-v1-version=1.0.17
fabric-block-view-api-v2-version=1.0.6
@ -21,31 +21,31 @@ fabric-blockrenderlayer-v1-version=1.1.48
fabric-command-api-v1-version=1.2.43
fabric-command-api-v2-version=2.2.22
fabric-commands-v0-version=0.2.60
fabric-content-registries-v0-version=6.0.2
fabric-content-registries-v0-version=6.0.3
fabric-crash-report-info-v1-version=0.2.25
fabric-data-attachment-api-v1-version=1.0.1
fabric-data-generation-api-v1-version=14.0.4
fabric-data-attachment-api-v1-version=1.0.2
fabric-data-generation-api-v1-version=14.0.5
fabric-dimensions-v1-version=2.1.63
fabric-entity-events-v1-version=1.6.1
fabric-events-interaction-v0-version=0.7.2
fabric-events-lifecycle-v0-version=0.2.74
fabric-events-lifecycle-v0-version=0.2.75
fabric-game-rule-api-v1-version=1.0.48
fabric-gametest-api-v1-version=1.3.2
fabric-item-api-v1-version=4.0.0
fabric-item-group-api-v1-version=4.0.23
fabric-key-binding-api-v1-version=1.0.43
fabric-keybindings-v0-version=0.2.41
fabric-lifecycle-events-v1-version=2.2.32
fabric-lifecycle-events-v1-version=2.2.33
fabric-loot-api-v2-version=2.1.7
fabric-message-api-v1-version=6.0.7
fabric-mining-level-api-v1-version=2.1.62
fabric-mining-level-api-v1-version=2.1.63
fabric-model-loading-api-v1-version=1.0.10
fabric-models-v0-version=0.4.9
fabric-networking-api-v1-version=4.0.0
fabric-object-builder-api-v1-version=13.0.11
fabric-object-builder-api-v1-version=14.0.0
fabric-particles-v1-version=2.0.0
fabric-recipe-api-v1-version=3.0.0
fabric-registry-sync-v0-version=4.0.18
fabric-registry-sync-v0-version=5.0.0
fabric-renderer-api-v1-version=3.2.6
fabric-renderer-indigo-version=1.5.6
fabric-renderer-registries-v1-version=3.2.53
@ -56,9 +56,9 @@ fabric-rendering-v1-version=3.0.15
fabric-resource-conditions-api-v1-version=2.3.16
fabric-resource-loader-v0-version=0.11.18
fabric-screen-api-v1-version=2.0.19
fabric-screen-handler-api-v1-version=1.3.55
fabric-screen-handler-api-v1-version=1.3.56
fabric-sound-api-v1-version=1.0.19
fabric-transfer-api-v1-version=4.0.10
fabric-transitive-access-wideners-v1-version=6.0.2
fabric-transfer-api-v1-version=4.0.11
fabric-transitive-access-wideners-v1-version=6.0.3
fabric-convention-tags-v1-version=1.5.12
fabric-client-tags-api-v1-version=1.1.9