Skip to content

Commit

Permalink
Misc fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Oct 19, 2022
1 parent 2fdb1ee commit 61a2483
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
package net.fabricmc.fabric.mixin.command.client;

import com.mojang.brigadier.CommandDispatcher;

import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.impl.command.client.ClientCommandInternals;
import org.spongepowered.asm.mixin.Final;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import net.minecraft.class_7701;
import net.minecraft.client.network.ClientCommandSource;
Expand All @@ -30,13 +33,9 @@
import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;

import org.spongepowered.asm.mixin.Final;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.impl.command.client.ClientCommandInternals;

@Mixin(ClientPlayNetworkHandler.class)
abstract class ClientPlayNetworkHandlerMixin {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,19 @@
package net.fabricmc.fabric.mixin.registry.sync;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
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.util.registry.DynamicRegistryManager;

import net.fabricmc.fabric.api.event.registry.DynamicRegistrySetupCallback;
import net.fabricmc.fabric.impl.registry.sync.DynamicRegistrySync;

@Mixin(DynamicRegistryManager.class)
public interface DynamicRegistryManagerMixin {
@Inject(method = "createAndLoad", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/dynamic/EntryLoader$Impl;<init>()V"), locals = LocalCapture.CAPTURE_FAILHARD)
private static void onCreateImpl(CallbackInfoReturnable<DynamicRegistryManager.Mutable> cir, DynamicRegistryManager.Mutable registryManager) {
DynamicRegistrySetupCallback.EVENT.invoker().onRegistrySetup(registryManager);
}

/**
* Ensures that any registrations made into {@link net.minecraft.util.registry.BuiltinRegistries} after
* {@link DynamicRegistryManager} has been class-loaded are still propagated.
*/
@Inject(method = "method_40327", at = @At(value = "RETURN"))
private static void setupBuiltInSync(CallbackInfoReturnable<DynamicRegistryManager.Immutable> cir) {
DynamicRegistrySync.setupSync(cir.getReturnValue());
}
/* TODO 22w42a not needed?
@Inject(method = "method_40327", at = @At(value = "RETURN"))
private static void setupBuiltInSync(CallbackInfoReturnable<DynamicRegistryManager.Immutable> cir) {
DynamicRegistrySync.setupSync(cir.getReturnValue());
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ private void onChange(RegistryKey<Registry<T>> registryKey) {
}
}

@Inject(method = "set(ILnet/minecraft/util/registry/RegistryKey;Ljava/lang/Object;Lcom/mojang/serialization/Lifecycle;Z)Lnet/minecraft/util/registry/RegistryEntry;", at = @At("HEAD"))
public void setPre(int id, RegistryKey<T> registryId, T object, Lifecycle lifecycle, boolean checkDuplicateKeys, CallbackInfoReturnable<T> info) {
@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);

if (indexedEntriesId >= 0) {
Expand All @@ -188,7 +188,7 @@ public void setPre(int id, RegistryKey<T> registryId, T object, Lifecycle lifecy
if (oldObject != null && oldObject.value() != null && oldObject.value() != object) {
int oldId = entryToRawId.getInt(oldObject.value());

if (oldId != id && checkDuplicateKeys) {
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()!");
}

Expand All @@ -200,8 +200,8 @@ public void setPre(int id, RegistryKey<T> registryId, T object, Lifecycle lifecy
}
}

@Inject(method = "set(ILnet/minecraft/util/registry/RegistryKey;Ljava/lang/Object;Lcom/mojang/serialization/Lifecycle;Z)Lnet/minecraft/util/registry/RegistryEntry;", at = @At("RETURN"))
public void setPost(int id, RegistryKey<T> registryId, T object, Lifecycle lifecycle, boolean checkDuplicateKeys, CallbackInfoReturnable<T> info) {
@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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.fabricmc.fabric.mixin.registry.sync;

import java.util.List;

import org.spongepowered.asm.mixin.Final;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.class_7780;
import net.minecraft.util.registry.DynamicRegistryManager;

import net.fabricmc.fabric.api.event.registry.DynamicRegistrySetupCallback;

@Mixin(class_7780.class)
public class class_7780Mixin {
@Shadow
@Final
private DynamicRegistryManager.Immutable field_40583;

@Inject(method = "<init>(Ljava/util/List;Ljava/util/List;)V", at = @At("RETURN"))
private void init(List list, List list2, CallbackInfo ci) {
DynamicRegistrySetupCallback.EVENT.invoker().onRegistrySetup(this.field_40583);
}
}
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ include 'fabric-lifecycle-events-v1'
include 'fabric-networking-api-v1'
//include 'fabric-object-builder-api-v1'
//include 'fabric-particles-v1'
//include 'fabric-registry-sync-v0'
include 'fabric-registry-sync-v0'
//include 'fabric-renderer-api-v1'
//include 'fabric-renderer-indigo'
//
Expand Down

0 comments on commit 61a2483

Please sign in to comment.