mirror of
https://github.com/GeyserMC/Rainbow.git
synced 2025-12-19 14:59:16 +00:00
Change models using the "minecraft" namespace to use the "geyser_mc" namespace, "experimental" auto generate command
This commit is contained in:
@@ -1,16 +1,23 @@
|
||||
package org.geysermc.packgenerator;
|
||||
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType;
|
||||
import com.mojang.brigadier.suggestion.Suggestion;
|
||||
import com.mojang.logging.LogUtils;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
|
||||
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.ServerboundChatCommandPacket;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GeyserMappingsGenerator implements ClientModInitializer {
|
||||
|
||||
@@ -18,6 +25,9 @@ public class GeyserMappingsGenerator implements ClientModInitializer {
|
||||
public static final String MOD_NAME = "Geyser Mappings Generator";
|
||||
public static final Logger LOGGER = LogUtils.getLogger();
|
||||
|
||||
private final List<String> pendingPackCommands = new ArrayList<>();
|
||||
private boolean waitingOnItem = false;
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
// TODO do the exceptions properly
|
||||
@@ -68,7 +78,67 @@ public class GeyserMappingsGenerator implements ClientModInitializer {
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
.then(ClientCommandManager.literal("auto")
|
||||
.then(ClientCommandManager.argument("namespace", StringArgumentType.word())
|
||||
.executes(context -> {
|
||||
String namespace = StringArgumentType.getString(context, "namespace");
|
||||
|
||||
// Duplicated code, this is just to try this out
|
||||
try {
|
||||
PackManager.getInstance().startPack(namespace);
|
||||
} catch (IOException exception) {
|
||||
throw new SimpleCommandExceptionType(Component.literal(exception.getMessage())).create();
|
||||
}
|
||||
context.getSource().sendFeedback(Component.literal("Created pack with name " + namespace));
|
||||
|
||||
// hack
|
||||
CommandContext<?> suggestionsContext = new CommandContext<>(null,
|
||||
"loot give @s loot " + namespace + ":",
|
||||
null, null, null, null, null, null, null, false);
|
||||
context.getSource().getClient().getConnection().getSuggestionsProvider()
|
||||
.customSuggestion(suggestionsContext)
|
||||
.whenComplete((suggestions, throwable) -> pendingPackCommands.addAll(suggestions.getList().stream().map(Suggestion::getText).toList()));
|
||||
return 0;
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
ClientTickEvents.START_CLIENT_TICK.register(client -> {
|
||||
if (!pendingPackCommands.isEmpty() || waitingOnItem) {
|
||||
if (!waitingOnItem) {
|
||||
String command = pendingPackCommands.removeFirst();
|
||||
client.getConnection().send(new ServerboundChatCommandPacket("loot give @s loot " + command));
|
||||
waitingOnItem = true;
|
||||
} else {
|
||||
if (!client.player.getInventory().isEmpty()) {
|
||||
int mapped = 0;
|
||||
for (ItemStack stack : client.player.getInventory()) {
|
||||
try {
|
||||
if (PackManager.getInstance().map(stack, false)) {
|
||||
mapped++;
|
||||
}
|
||||
} catch (Exception exception) {
|
||||
client.player.displayClientMessage(Component.literal("Failed to map item " + exception.getMessage()), false);
|
||||
}
|
||||
}
|
||||
client.player.displayClientMessage(Component.literal("Mapped " + mapped + " items from your inventory"), false);
|
||||
|
||||
client.getConnection().send(new ServerboundChatCommandPacket("clear"));
|
||||
|
||||
waitingOnItem = false;
|
||||
if (pendingPackCommands.isEmpty()) {
|
||||
try {
|
||||
PackManager.getInstance().finish();
|
||||
} catch (IOException | CommandSyntaxException exception) {
|
||||
throw new RuntimeException(exception);
|
||||
}
|
||||
client.player.displayClientMessage(Component.literal("Wrote pack to disk"), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,9 @@ public class GeyserItemMapper {
|
||||
switch (model) {
|
||||
case BlockModelWrapper modelWrapper -> {
|
||||
ResourceLocation itemModel = ((BlockModelWrapperLocationAccessor) modelWrapper).geyser_mappings_generator$getModelOrigin();
|
||||
if (itemModel.getNamespace().equals(ResourceLocation.DEFAULT_NAMESPACE)) {
|
||||
itemModel = ResourceLocation.fromNamespaceAndPath("geyser_mc", itemModel.getPath());
|
||||
}
|
||||
return Stream.of(context.create(itemModel));
|
||||
}
|
||||
case ConditionalItemModel conditional -> {
|
||||
|
||||
@@ -10,7 +10,4 @@ public interface SelectItemModelAccessor<T> {
|
||||
|
||||
@Accessor
|
||||
SelectItemModelProperty<T> getProperty();
|
||||
|
||||
@Accessor
|
||||
SelectItemModel.ModelSelector<T> getModels();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user