Skip to content

Polymer support, add support for using translated names as filename #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 1.21.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ base {

repositories {
maven { url "https://maven.wispforest.io/releases/" }
maven { url 'https://maven.nucleoid.xyz' }
}

loom {
Expand All @@ -35,6 +36,10 @@ dependencies {

modImplementation "io.wispforest:owo-lib:${project.owo_version}"
include "io.wispforest:owo-sentinel:${project.owo_version}"


modCompileOnly("eu.pb4:polymer-core:0.11.8+1.21.4")

}

processResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import net.minecraft.command.argument.*;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.Registries;
Expand Down Expand Up @@ -100,7 +102,13 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
.then(literal("enable")
.executes(IsorenderCommand::enableUnsafe))
.then(literal("disable")
.executes(IsorenderCommand::disableUnsafe))));
.executes(IsorenderCommand::disableUnsafe)))

.then(literal("translated_names")
.then(literal("enable")
.executes(IsorenderCommand::enableTranslatedNames))
.then(literal("disable")
.executes(IsorenderCommand::disableTranslatedNames))));
}

private static int showRootNodeHelp(CommandContext<FabricClientCommandSource> context) {
Expand Down Expand Up @@ -128,6 +136,18 @@ private static int enableUnsafe(CommandContext<FabricClientCommandSource> contex
return 0;
}

private static int disableTranslatedNames(CommandContext<FabricClientCommandSource> context) {
GlobalProperties.translatedNames.set(false);
Translate.commandFeedback(context, "translated_names_disabled");
return 0;
}

private static int enableTranslatedNames(CommandContext<FabricClientCommandSource> context) {
GlobalProperties.translatedNames.set(true);
Translate.commandFeedback(context, "translated_names_enabled");
return 0;
}

private static int renderPlayerWithNbt(CommandContext<FabricClientCommandSource> context) {
final var server = MinecraftClient.getInstance().getServer();
if (server == null) {
Expand Down Expand Up @@ -331,7 +351,7 @@ private static int renderAreaSelection(CommandContext<FabricClientCommandSource>
private static <S> void withItemGroupFromContext(CommandContext<S> context, BiConsumer<List<ItemStack>, String> action) {
final var itemGroup = ItemGroupArgumentType.getItemGroup("itemgroup", context);
final var stacks = new ArrayList<>(itemGroup.getDisplayStacks());
action.accept(stacks, "creative-tab_" + Registries.ITEM_GROUP.getId(itemGroup).toShortTranslationKey());
action.accept(stacks, "creative-tab_" + ItemGroupArgumentType.getGroupId(itemGroup).toShortTranslationKey());
}

public static BlockPos getPosFromArgument(DefaultPosArgument argument, FabricClientCommandSource source) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.glisco.isometricrenders.command;

import com.glisco.isometricrenders.compatibility.PolymerSupport;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
Expand All @@ -13,6 +14,7 @@
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;

import java.util.Objects;
import java.util.concurrent.CompletableFuture;

public class ItemGroupArgumentType implements ArgumentType<ItemGroup> {
Expand All @@ -32,11 +34,21 @@ public static <S> ItemGroup getItemGroup(String name, CommandContext<S> context)
@Override
public ItemGroup parse(StringReader reader) throws CommandSyntaxException {
var id = Identifier.fromCommandInput(reader);
return ItemGroups.getGroups().stream().filter(itemGroup -> Registries.ITEM_GROUP.getId(itemGroup).equals(id)).findAny().orElseThrow(() -> NO_ITEMGROUP.create(id));
return ItemGroups.getGroups().stream().filter(itemGroup -> id.equals(getGroupId(itemGroup))).findAny().orElseThrow(() -> NO_ITEMGROUP.create(id));
}

@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
return CommandSource.suggestIdentifiers(ItemGroups.getGroups().stream().map(Registries.ITEM_GROUP::getId), builder);
return CommandSource.suggestIdentifiers(ItemGroups.getGroups().stream().map(ItemGroupArgumentType::getGroupId).filter(Objects::nonNull), builder);
}


public static Identifier getGroupId(ItemGroup group) {
var id = Registries.ITEM_GROUP.getId(group);
if (id != null) {
return id;
}

return PolymerSupport.getPolymerId(group);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.glisco.isometricrenders.compatibility;

import eu.pb4.polymer.core.api.item.PolymerItemGroupUtils;
import eu.pb4.polymer.core.api.item.PolymerItemUtils;
import eu.pb4.polymer.core.impl.client.InternalClientItemGroup;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

public interface PolymerSupport {
boolean HAS_POLYMER_CORE = FabricLoader.getInstance().isModLoaded("polymer-core");

@Nullable
static Identifier getPolymerId(ItemStack stack) {
if (HAS_POLYMER_CORE) {
return PolymerItemUtils.getServerIdentifier(stack);
}
return null;
}

@Nullable
static Identifier getPolymerId(ItemGroup itemGroup) {
if (HAS_POLYMER_CORE) {
//noinspection UnstableApiUsage
if (itemGroup instanceof InternalClientItemGroup internal) {
//noinspection UnstableApiUsage
return internal.getIdentifier();
}
return PolymerItemGroupUtils.getId(itemGroup);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class GlobalProperties {
public static Property<Boolean> unsafe = Property.of(false);
public static Property<Boolean> saveIntoRoot = Property.of(true);
public static Property<Boolean> overwriteLatest = Property.of(false);
public static Property<Boolean> translatedNames = Property.of(false);

public static int exportResolution = 1000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,9 @@ public ParticleRestriction<?> particleRestriction() {

@Override
public ExportPathSpec exportPath() {
return ExportPathSpec.ofIdentified(
return ExportPathSpec.ofIdentifiedAndNamed(
Registries.BLOCK.getId(this.state.getBlock()),
this.state.getBlock().getName(),
"block"
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ public ParticleRestriction<?> particleRestriction() {

@Override
public ExportPathSpec exportPath() {
return ExportPathSpec.ofIdentified(
return ExportPathSpec.ofIdentifiedAndNamed(
Registries.ENTITY_TYPE.getId(this.entity.getType()),
this.entity.getName(),
"entity"
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.glisco.isometricrenders.render;

import com.glisco.isometricrenders.compatibility.PolymerSupport;
import com.glisco.isometricrenders.mixin.access.ItemRenderStateAccessor;
import com.glisco.isometricrenders.property.DefaultPropertyBundle;
import com.glisco.isometricrenders.util.ExportPathSpec;
Expand Down Expand Up @@ -78,8 +79,10 @@ public DefaultPropertyBundle properties() {

@Override
public ExportPathSpec exportPath() {
return ExportPathSpec.ofIdentified(
Registries.ITEM.getId(this.stack.getItem()),
var id = PolymerSupport.getPolymerId(this.stack);
return ExportPathSpec.ofIdentifiedAndNamed(
id != null ? id : Registries.ITEM.getId(this.stack.getItem()),
this.stack.getName(),
"item"
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.glisco.isometricrenders.property.GlobalProperties;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.io.File;
Expand All @@ -21,6 +22,10 @@ public static ExportPathSpec ofIdentified(Identifier id, String type) {
return new ExportPathSpec(id.getNamespace() + "/" + type, id.getPath(), false);
}

public static ExportPathSpec ofIdentifiedAndNamed(Identifier id, Text name, String type) {
return new ExportPathSpec(id.getNamespace() + "/" + type, GlobalProperties.translatedNames.get() ? name.getString() : id.getPath(), false);
}

// -----

public Path resolveOffset() {
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/isometric-renders/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@
"message.isometric-renders.lighting_profile_updated": "§aLighting profile updated",
"message.isometric-renders.unsafe_enabled": "Unsafe mode §cenabled§7. Tread lightly",
"message.isometric-renders.unsafe_disabled": "Unsafe mode §adisabled§7",
"message.isometric-renders.translated_names_enabled": "Translated filenames §aenabled§7",
"message.isometric-renders.translated_names_disabled": "Translated filenames §cdisabled§7",

"message.isometric-renders.version": "Running Isometric Renders v%s",
"message.isometric-renders.command_hint": "Hint: Check the wiki to see the subcommands and what they do",
Expand Down