Properly wrap non vanilla argument types (ArclightPowered/lightfall#7)

This commit is contained in:
IzzelAliz 2021-05-06 21:22:20 +08:00
parent 840d2bb33e
commit 80b90887a5

View File

@ -11,8 +11,14 @@ import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow; 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 javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@Mixin(ArgumentTypes.class) @Mixin(ArgumentTypes.class)
public abstract class ArgumentTypesMixin { public abstract class ArgumentTypesMixin {
@ -20,8 +26,26 @@ public abstract class ArgumentTypesMixin {
// @formatter:off // @formatter:off
@Shadow @Final private static Logger LOGGER; @Shadow @Final private static Logger LOGGER;
@Shadow @Nullable private static ArgumentTypes.Entry<?> get(ArgumentType<?> type) { return null; } @Shadow @Nullable private static ArgumentTypes.Entry<?> get(ArgumentType<?> type) { return null; }
@Shadow @Final private static Map<ResourceLocation, ArgumentTypes.Entry<?>> ID_TYPE_MAP;
// @formatter:on // @formatter:on
private static final Set<ResourceLocation> INTERNAL_TYPES = new HashSet<>();
@Inject(method = "registerArgumentTypes", at = @At("HEAD"))
private static void arclight$beginRegister(CallbackInfo ci) {
INTERNAL_TYPES.addAll(ID_TYPE_MAP.keySet());
}
@Inject(method = "registerArgumentTypes", at = @At("RETURN"))
private static void arclight$endRegister(CallbackInfo ci) {
HashSet<ResourceLocation> set = new HashSet<>(ID_TYPE_MAP.keySet());
set.removeAll(INTERNAL_TYPES);
INTERNAL_TYPES.clear();
INTERNAL_TYPES.addAll(set);
INTERNAL_TYPES.add(new ResourceLocation("forge", "enum"));
INTERNAL_TYPES.add(new ResourceLocation("forge", "modid"));
}
/** /**
* @author IzzelAliz * @author IzzelAliz
* @reason * @reason
@ -33,8 +57,7 @@ public abstract class ArgumentTypesMixin {
LOGGER.error("Could not serialize {} ({}) - will not be sent to client!", type, type.getClass()); LOGGER.error("Could not serialize {} ({}) - will not be sent to client!", type, type.getClass());
buffer.writeResourceLocation(new ResourceLocation("")); buffer.writeResourceLocation(new ResourceLocation(""));
} else { } else {
String namespace = entry.id.getNamespace(); boolean wrap = SpigotConfig.bungee && !INTERNAL_TYPES.contains(entry.id);
boolean wrap = SpigotConfig.bungee && !(namespace.equals("minecraft") || namespace.equals("forge") || namespace.equals("brigadier"));
if (wrap) { if (wrap) {
buffer.writeString("arclight:wrapped"); buffer.writeString("arclight:wrapped");
} }