Skip to content
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

1.21 beta update #60

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
33 changes: 17 additions & 16 deletions src/main/java/com/HiWord9/RPRenames/RPRenames.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.ItemEnchantmentsComponent;
import net.minecraft.component.type.NbtComponent;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.text.Text;
Expand Down Expand Up @@ -53,7 +53,7 @@ public void onInitializeClient() {
});
}

registerItemGroup();
//TODO registerItemGroup();

RenamesManager.parsers.add(new CITParser());
RenamesManager.parsers.add(new CEMParser());
Expand All @@ -62,7 +62,7 @@ public void onInitializeClient() {
}

public static Identifier asId(String path) {
return new Identifier(MOD_ID, path);
return Identifier.of(MOD_ID, path);
}

public static void registerCommand(CommandDispatcher<FabricClientCommandSource> dispatcher, CommandRegistryAccess registryAccess) {
Expand All @@ -72,32 +72,33 @@ public static void registerCommand(CommandDispatcher<FabricClientCommandSource>
public static void registerItemGroup() {
Registry.register(
Registries.ITEM_GROUP,
new Identifier(MOD_ID, "item_group"),
Identifier.of(MOD_ID, "item_group"),
FabricItemGroup.builder()
.displayName(Text.translatable("rprenames.item_group"))
.icon(RPRenames::getItemGroupIcon)
.type(ItemGroup.Type.SEARCH)
.texture("item_search.png")
//TODO .texture(Identifier.tryParse("item_search.png"))
.build()
);
}

private static ItemStack getItemGroupIcon() {
ItemStack stack = new ItemStack(Items.KNOWLEDGE_BOOK);
stack.getOrCreateNbt();
assert stack.getNbt() != null;
if (!stack.getNbt().contains("Enchantments", 9)) {
stack.getNbt().put("Enchantments", new NbtList());
stack.getOrDefault(DataComponentTypes.CUSTOM_NAME, Text.empty());
assert stack.getComponents() != null;
if (stack.getEnchantments().getEnchantments() == null) {
stack.getOrDefault(DataComponentTypes.ENCHANTMENTS, ItemEnchantmentsComponent.DEFAULT);
}
NbtList nbtList = stack.getNbt().getList("Enchantments", NbtElement.COMPOUND_TYPE);
nbtList.add(EnchantmentHelper.createNbt(new Identifier("mending"), 1));
stack.getOrCreateSubNbt(MOD_ID);
ItemEnchantmentsComponent enchantments = stack.getEnchantments();
//TODO nbtList.add(EnchantmentHelper.createNbt(new Identifier("mending"), 1));
stack.getOrDefault(DataComponentTypes.CUSTOM_DATA, MOD_ID);
return stack;
}

public static boolean verifyItemGroup(ItemGroup itemGroup) {
ItemStack icon = itemGroup.getIcon();
icon.getOrCreateNbt();
return icon.getSubNbt(MOD_ID) != null;
icon.getOrDefault(DataComponentTypes.CUSTOM_DATA, MOD_ID);
boolean ccontains = icon.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT).contains(MOD_ID);
return ccontains;
}
}
16 changes: 3 additions & 13 deletions src/main/java/com/HiWord9/RPRenames/RPRenamesCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.command.argument.ItemStackArgumentType;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.text.ClickEvent;
Expand Down Expand Up @@ -234,21 +235,10 @@ private static AbstractRename getMatch(ArrayList<AbstractRename> renames, ItemSt
private static void printRenameList(ArrayList<AbstractRename> renames, FabricClientCommandSource source) {
for (AbstractRename r : renames) {
ItemStack itemStack = r.toStack();

assert itemStack.getNbt() != null;
String nbt = itemStack.getNbt().toString();
if (nbt.contains("Damage:0")) {
nbt = nbt.replace("Damage:0", "");
if (nbt.startsWith("{,")) {
nbt = "{" + nbt.substring(2);
} else if (nbt.endsWith(",}")) {
nbt = nbt.substring(0, nbt.length() - 2) + "}";
}
}
assert itemStack.getComponents() != null;

String giveCommand = "/give @s "
+ ParserHelper.getIdAndPath(itemStack.getItem())
+ nbt
+ (r instanceof CITRename citRename ?
(citRename.getStackSize() == 1 ? "" : " " + citRename.getStackSize()) : "");

Expand All @@ -258,7 +248,7 @@ private static void printRenameList(ArrayList<AbstractRename> renames, FabricCli
.fillStyle(Style.EMPTY
.withColor(Formatting.GRAY)
.withClickEvent(runGive)
.withInsertion(giveCommand)
.withInsertion(giveCommand)
.withHoverEvent(new HoverEvent(
HoverEvent.Action.SHOW_TEXT,
Text.translatable("rprenames.command.list.runGive")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ private boolean stacksEqual(ItemStack stack1, ItemStack stack2) {
}
if (!stack1.isOf(stack2.getItem())) return false;
if (stack1.getCount() != stack2.getCount()) return false;
if (stack1.getNbt() == null || stack2.getNbt() == null) {
return stack1.getNbt() == stack2.getNbt();
if (stack1.getComponents() == null || stack2.getComponents() == null) {
return stack1.getComponents() == stack2.getComponents();
}
return stack1.getNbt().toString().equals(stack2.getNbt().toString());
return stack1.getComponents().toString().equals(stack2.getComponents().toString());
}

@Inject(at = @At("HEAD"), method = "onSlotUpdate", cancellable = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
Expand All @@ -27,7 +28,7 @@
@Mixin(CreativeInventoryScreen.class)
public abstract class CreativeInventoryScreenMixin {

@Shadow @Final private static String CUSTOM_CREATIVE_LOCK_KEY;
//TODO @Shadow @Final private static String CUSTOM_CREATIVE_LOCK_KEY;

@Shadow private TextFieldWidget searchBox;

Expand Down Expand Up @@ -107,15 +108,15 @@ private static ArrayList<ItemStack> searchStacks(ArrayList<ItemStack> renamedIte

private ItemStack getNoRenamesFoundItem() {
ItemStack itemStack = new ItemStack(Items.PAPER);
itemStack.getOrCreateSubNbt(CUSTOM_CREATIVE_LOCK_KEY);
itemStack.setCustomName(Text.translatable("rprenames.gui.noRenamesFound"));
//TODO itemStack.getOrCreateSubNbt(CUSTOM_CREATIVE_LOCK_KEY);
itemStack.set(DataComponentTypes.CUSTOM_NAME, Text.translatable("rprenames.gui.noRenamesFound"));
return itemStack;
}

private ItemStack getFavoriteItem() {
ItemStack itemStack = new ItemStack(Items.PAPER);
itemStack.getOrCreateSubNbt(CUSTOM_CREATIVE_LOCK_KEY);
itemStack.setCustomName(Text.translatable("rprenames.gui.tabs.tooltip.FAVORITE"));
//TODO itemStack.getOrCreateSubNbt(CUSTOM_CREATIVE_LOCK_KEY);
itemStack.set(DataComponentTypes.CUSTOM_NAME, Text.translatable("rprenames.gui.tabs.tooltip.FAVORITE"));
return itemStack;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.HiWord9.RPRenames.util.rename.RenamesManager;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.render.model.BlockStatesLoader;
import net.minecraft.client.render.model.ModelLoader;
import net.minecraft.client.render.model.json.JsonUnbakedModel;
import net.minecraft.util.Identifier;
Expand All @@ -21,7 +22,7 @@ public class ModelLoaderMixin {
private static final ModConfig config = ModConfig.INSTANCE;

@Inject(method = "<init>", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/util/profiler/Profiler;push(Ljava/lang/String;)V"))
private void loadRenames(BlockColors blockColors, Profiler profiler, Map<Identifier, JsonUnbakedModel> jsonUnbakedModels, Map<Identifier, List<ModelLoader.SourceTrackedData>> blockStates, CallbackInfo ci) {
private void loadRenames(BlockColors blockColors, Profiler profiler, Map<Identifier, JsonUnbakedModel> jsonUnbakedModels, Map<Identifier, List<BlockStatesLoader.SourceTrackedData>> blockStates, CallbackInfo ci) {
if (!config.updateConfig) return;
RenamesManager.updateRenames(MinecraftClient.getInstance().getResourceManager(), profiler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static Screen create(Screen parent) {

ConfigBuilder builder = ConfigBuilder.create()
.setParentScreen(parent)
.setDefaultBackgroundTexture(new Identifier("minecraft", "textures/block/bookshelf.png"))
.setDefaultBackgroundTexture(Identifier.of("minecraft", "textures/block/bookshelf.png"))
.setTitle(Text.translatable("rprenames.config.title"))
.setSavingRunnable(currentConfig::write);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.HiWord9.RPRenames.RPRenames;
import com.HiWord9.RPRenames.util.rename.type.CITRename;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.Item;
import net.minecraft.text.MutableText;
import net.minecraft.text.Style;
Expand Down Expand Up @@ -312,7 +313,7 @@ public static ArrayList<String> splitList(String list) {
}

public static int parseDamagePercent(int percent, Item item) {
int maxDamage = item.getMaxDamage();
int maxDamage = item.getComponents().get(DataComponentTypes.MAX_DAMAGE);
return maxDamage * percent / 100;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ public void parse(ResourceManager resourceManager, Profiler profiler) {
}

private static void parseRawPropertyFile(ResourceManager resourceManager, String texturePath, int textureNum) throws IOException {
Identifier identifier = new Identifier(Identifier.DEFAULT_NAMESPACE, texturePath + CEMList.textures[textureNum] + PROP_EXTENSION);
Identifier identifier = Identifier.of(Identifier.DEFAULT_NAMESPACE, texturePath + CEMList.textures[textureNum] + PROP_EXTENSION);
Optional<Resource> optionalResource = resourceManager.getResource(identifier);
if (optionalResource.isEmpty()) {
identifier = new Identifier(Identifier.DEFAULT_NAMESPACE, texturePath + getLastPathPart(CEMList.textures[textureNum]) + PROP_EXTENSION);
identifier = Identifier.of(Identifier.DEFAULT_NAMESPACE, texturePath + getLastPathPart(CEMList.textures[textureNum]) + PROP_EXTENSION);
optionalResource = resourceManager.getResource(identifier);
if (optionalResource.isEmpty()) return;
}
Resource resource = optionalResource.get();

String packName = ParserHelper.validatePackName(resource.getResourcePackName());
String packName = ParserHelper.validatePackName(resource.getPack().getId());
String path = ParserHelper.getFullPathFromIdentifier(packName, identifier);
if (checked.contains(path)) return;

Expand All @@ -123,7 +123,7 @@ private static void parseRawPropertyFile(ResourceManager resourceManager, String
}

private static void parseTextureSourceFile(ResourceManager resourceManager, String fileWithTextureName, String fileName, String texturePath) throws IOException {
Optional<Resource> optionalResourceJpm = resourceManager.getResource(new Identifier(Identifier.DEFAULT_NAMESPACE, CEM_PATH + "/" + fileWithTextureName));
Optional<Resource> optionalResourceJpm = resourceManager.getResource(Identifier.of(Identifier.DEFAULT_NAMESPACE, CEM_PATH + "/" + fileWithTextureName));
if (optionalResourceJpm.isEmpty()) return;

Resource resourceJpm = optionalResourceJpm.get();
Expand All @@ -132,13 +132,13 @@ private static void parseTextureSourceFile(ResourceManager resourceManager, Stri

String textureName = prepareTexturePath(textures.get(0));

Identifier propId = new Identifier(Identifier.DEFAULT_NAMESPACE, texturePath + textureName + PROP_EXTENSION);
Identifier propId = Identifier.of(Identifier.DEFAULT_NAMESPACE, texturePath + textureName + PROP_EXTENSION);
Optional<Resource> optionalResourceProp = resourceManager.getResource(propId);
if (optionalResourceProp.isEmpty()) return;

Resource resourceProp = optionalResourceProp.get();

String packName = ParserHelper.validatePackName(resourceProp.getResourcePackName());
String packName = ParserHelper.validatePackName(resourceProp.getPack().getId());
String path = ParserHelper.getFullPathFromIdentifier(packName, propId);
checked.add(path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void parse(ResourceManager resourceManager, Profiler profiler) {
for (String root : ROOTS) {
for (Map.Entry<Identifier, Resource> entry : resourceManager.findResources(root + "/cit", s -> s.getPath().endsWith(".properties")).entrySet()) {
try {
String packName = ParserHelper.validatePackName(entry.getValue().getResourcePackName());
String packName = ParserHelper.validatePackName(entry.getValue().getPack().getId());
CITParser.propertiesToRename(
ParserHelper.getPropFromResource(entry.getValue()),
packName,
Expand Down Expand Up @@ -83,8 +83,8 @@ private static void propertiesToRename(Properties p, String packName, String pat
Identifier enchantment = null;
if (enchantIdProp != null) {
String firstEnchantId = PropertiesHelper.getFirstValueInList(enchantIdProp);
enchantment = new Identifier(firstEnchantId);
if (Registries.ENCHANTMENT.get(enchantment) == null) {
enchantment = Identifier.of(firstEnchantId);
if (Registries.ENCHANTMENT_EFFECT_COMPONENT_TYPE.get(enchantment) == null) {
RPRenames.LOGGER.warn("Could not get valid enchantment {} for {}", enchantment, path);
enchantment = null;
}
Expand Down Expand Up @@ -150,7 +150,7 @@ private static ArrayList<String> splitMatchItems(String matchItems) {
private static ArrayList<Item> itemsFromMatchList(ArrayList<String> matchItemsList) {
ArrayList<Item> items = new ArrayList<>();
for (String matchItem : matchItemsList) {
Item item = Registries.ITEM.get(new Identifier(matchItem));
Item item = Registries.ITEM.get(Identifier.of(matchItem));
if (item == Items.AIR) continue;
items.add(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static String getIdAndPath(Item item) {
}

public static Item itemFromName(String id) {
return Registries.ITEM.get(new Identifier(id));
return Registries.ITEM.get(Identifier.of(id));
}

public static String idFromItem(Item item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public class MultiItemTooltipComponent implements TooltipComponent {
private static final ModConfig config = ModConfig.INSTANCE;

static final Identifier SLOT = new Identifier(RPRenames.MOD_ID, "textures/gui/slot.png");
static final Identifier SLOT = Identifier.of(RPRenames.MOD_ID, "textures/gui/slot.png");

public final ArrayList<TooltipItem> items;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

public class RPRWidget implements Drawable, Element/*, Widget*/ {
protected ModConfig config = ModConfig.INSTANCE;
protected static Identifier MENU_TEXTURE = new Identifier(RPRenames.MOD_ID, "textures/gui/menu.png");
protected static Identifier MENU_TEXTURE = Identifier.of(RPRenames.MOD_ID, "textures/gui/menu.png");

public static final int MENU_TEXTURE_WIDTH = 147;
public static final int MENU_TEXTURE_HEIGHT = 166;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
public class PageButton extends ClickableWidget {
private static final ModConfig config = ModConfig.INSTANCE;

private static final Identifier TEXTURE = new Identifier(RPRenames.MOD_ID, "textures/gui/page_arrows.png");
private static final Identifier TEXTURE = Identifier.of(RPRenames.MOD_ID, "textures/gui/page_arrows.png");

RPRWidget rprWidget;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import net.minecraft.util.Identifier;

public class RandomButton extends ClickableWidget {
public static final Identifier TEXTURE = new Identifier(RPRenames.MOD_ID, "textures/gui/dice.png");
public static final Identifier TEXTURE = Identifier.of(RPRenames.MOD_ID, "textures/gui/dice.png");
static final String TOOLTIP_KEY = "rprenames.gui.randomButton.tooltip";

RPRWidget rprWidget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class RenameButton extends ClickableWidget {
private static final ModConfig config = ModConfig.INSTANCE;
final int highlightColor = config.getSlotHighlightRGBA();

private static final Identifier TEXTURE = new Identifier(RPRenames.MOD_ID, "textures/gui/button.png");
private static final Identifier TEXTURE = Identifier.of(RPRenames.MOD_ID, "textures/gui/button.png");

RPRWidget rprWidget;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.List;

public class TabButton extends ClickableWidget {
private static final Identifier TEXTURE = new Identifier(RPRenames.MOD_ID, "textures/gui/tabs.png");
private static final Identifier TEXTURE = Identifier.of(RPRenames.MOD_ID, "textures/gui/tabs.png");
private static final String TRANSLATION_PREFIX = "rprenames.gui.tabs.tooltip.";

RPRWidget rprWidget;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.minecraft.util.Identifier;

public class FavoriteButton extends ClickableWidget {
public static final Identifier TEXTURE = new Identifier(RPRenames.MOD_ID, "textures/gui/favorite_button.png");
public static final Identifier TEXTURE = Identifier.of(RPRenames.MOD_ID, "textures/gui/favorite_button.png");

RPRWidget rprWidget;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import net.minecraft.util.Identifier;

public class OpenerButton extends ClickableWidget {
private static final Identifier TEXTURE = new Identifier(RPRenames.MOD_ID, "textures/gui/opener.png");
private static final Identifier TEXTURE = Identifier.of(RPRenames.MOD_ID, "textures/gui/opener.png");

RPRWidget rprWidget;

Expand Down
Loading
Loading