Skip to content

Commit

Permalink
24w04a
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Jan 24, 2024
1 parent 3945d7a commit 9bfa344
Show file tree
Hide file tree
Showing 19 changed files with 87 additions and 232 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ private void onClearWorld(CallbackInfo ci) {
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -422,7 +423,7 @@ public EntityType<T> build() {
* @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;

Expand Down Expand Up @@ -535,8 +536,8 @@ public FabricEntityTypeBuilder.Mob<T> defaultAttributes(Supplier<DefaultAttribut
*
* @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;
Expand All @@ -547,7 +548,7 @@ public EntityType<T> build() {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public static <T> void registerSynced(RegistryKey<? extends Registry<T>> key, Co
* @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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +28,6 @@
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;

Expand All @@ -52,7 +50,7 @@ private 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");

Expand All @@ -63,22 +61,22 @@ public static <T> void register(RegistryKey<? extends Registry<T>> key, Codec<T>
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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

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;
Expand Down Expand Up @@ -78,14 +77,4 @@ public <T> void registerEntryAdded(RegistryKey<? extends Registry<? extends T>>
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@
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<>();
Expand All @@ -42,7 +41,6 @@ public static <V, OV> void register(Registry<V> registry, String name, IdList<OV
IdListTracker<V, OV> updater = new IdListTracker<>(name, mappers);
RegistryEntryAddedCallback.event(registry).register(updater);
RegistryIdRemapCallback.event(registry).register(updater);
RegistryEntryRemovedCallback.event(registry).register(updater);
}

@Override
Expand All @@ -57,13 +55,4 @@ public void onEntryAdded(int rawId, Identifier id, V object) {
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,9 @@
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;
Expand All @@ -50,7 +49,6 @@ public static <V, OV> void register(Registry<V> registry, String name, Int2Objec
Int2ObjectMapTracker<V, OV> updater = new Int2ObjectMapTracker<>(name, mappers);
RegistryEntryAddedCallback.event(registry).register(updater);
RegistryIdRemapCallback.event(registry).register(updater);
RegistryEntryRemovedCallback.event(registry).register(updater);
}

@Override
Expand Down Expand Up @@ -91,13 +89,4 @@ public void onRemap(RemapState<V> state) {
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,17 @@
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;
Expand All @@ -43,19 +40,18 @@
@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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,17 +30,13 @@
// 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);
}
}
}
Loading

0 comments on commit 9bfa344

Please sign in to comment.