aboutsummaryrefslogtreecommitdiff
path: root/defaults
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2022-06-10 08:57:05 +0300
committerSHsuperCM <shsupercm@gmail.com>2022-06-10 08:57:05 +0300
commit0935c49b8432f80350b4dd6c5a4d29e7626ccff7 (patch)
treecdea4d92ce25491a64d2cf8c9c43d9fb1c6144b3 /defaults
parentffa0e186440249e1657268d036ec3036974b9fe9 (diff)
downloadCITResewn-0935c49b8432f80350b4dd6c5a4d29e7626ccff7.tar.gz
CITResewn-0935c49b8432f80350b4dd6c5a4d29e7626ccff7.tar.bz2
CITResewn-0935c49b8432f80350b4dd6c5a4d29e7626ccff7.zip
Updated target version to 1.19
Using combined input from PRs #152 and #155 Thank you so much for your help @HarvelsX and @MeeniMc Co-Authored-By: MeeniMc <68366846+MeeniMC@users.noreply.github.com> Co-Authored-By: HarvelsX <90945793+harvelsx@users.noreply.github.com>
Diffstat (limited to 'defaults')
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java21
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/config/CITResewnDefaultsConfigScreenFactory.java11
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/common/ModelLoaderMixin.java8
-rw-r--r--defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ModelLoaderMixin.java2
4 files changed, 14 insertions, 28 deletions
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java
index fe0bafb..d442559 100644
--- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java
+++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/types/TypeItem.java
@@ -14,8 +14,6 @@ import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.item.Item;
-import net.minecraft.item.Items;
-import net.minecraft.resource.Resource;
import net.minecraft.resource.ResourceManager;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
@@ -185,7 +183,7 @@ public class TypeItem extends CITType {
overrideConditions.put(new Identifier(itemIdentifier.getNamespace(), "item/" + itemIdentifier.getPath()), Collections.emptyList());
Identifier itemModelIdentifier = new Identifier(itemIdentifier.getNamespace(), "models/item/" + itemIdentifier.getPath() + ".json");
- try (Resource itemModelResource = resourceManager.getResource(itemModelIdentifier); Reader resourceReader = new InputStreamReader(itemModelResource.getInputStream())) {
+ try (Reader resourceReader = new InputStreamReader(resourceManager.getResource(itemModelIdentifier).orElseThrow().getInputStream())) {
JsonUnbakedModel itemModelJson = JsonUnbakedModel.deserialize(resourceReader);
if (itemModelJson.getOverrides() != null && !itemModelJson.getOverrides().isEmpty())
@@ -263,7 +261,7 @@ public class TypeItem extends CITType {
overrideConditions.put(new Identifier(itemIdentifier.getNamespace(), "item/" + itemIdentifier.getPath()), Collections.emptyList());
Identifier itemModelIdentifier = new Identifier(itemIdentifier.getNamespace(), "models/item/" + itemIdentifier.getPath() + ".json");
- try (Resource itemModelResource = resourceManager.getResource(itemModelIdentifier); Reader resourceReader = new InputStreamReader(itemModelResource.getInputStream())) {
+ try (Reader resourceReader = new InputStreamReader( resourceManager.getResource(itemModelIdentifier).orElseThrow().getInputStream())) {
JsonUnbakedModel itemModelJson = JsonUnbakedModel.deserialize(resourceReader);
if (itemModelJson.getOverrides() != null && !itemModelJson.getOverrides().isEmpty())
@@ -305,10 +303,8 @@ public class TypeItem extends CITType {
}
JsonUnbakedModel json;
if (identifier.getPath().endsWith(".json")) {
- InputStream is = null;
- Resource resource = null;
- try {
- json = JsonUnbakedModel.deserialize(IOUtils.toString(is = (resource = resourceManager.getResource(identifier)).getInputStream(), StandardCharsets.UTF_8));
+ try (InputStream is = resourceManager.getResource(identifier).orElseThrow().getInputStream()) {
+ json = JsonUnbakedModel.deserialize(IOUtils.toString(is, StandardCharsets.UTF_8));
json.id = assetIdentifier.toString();
json.id = json.id.substring(0, json.id.length() - 5);
@@ -368,8 +364,6 @@ public class TypeItem extends CITType {
});
return json;
- } finally {
- IOUtils.closeQuietly(is, resource);
}
} else if (identifier.getPath().endsWith(".png")) {
json = getModelForFirstItemType(resourceManager);
@@ -419,9 +413,8 @@ public class TypeItem extends CITType {
private JsonUnbakedModel getModelForFirstItemType(ResourceManager resourceManager) {
Identifier firstItemIdentifier = Registry.ITEM.getId(this.items.iterator().next()), firstItemModelIdentifier = new Identifier(firstItemIdentifier.getNamespace(), "models/item/" + firstItemIdentifier.getPath() + ".json");
- Resource itemModelResource = null;
- try {
- JsonUnbakedModel json = JsonUnbakedModel.deserialize(IOUtils.toString((itemModelResource = resourceManager.getResource(firstItemModelIdentifier)).getInputStream(), StandardCharsets.UTF_8));
+ try (InputStream is = resourceManager.getResource(firstItemModelIdentifier).orElseThrow().getInputStream()) {
+ JsonUnbakedModel json = JsonUnbakedModel.deserialize(IOUtils.toString(is, StandardCharsets.UTF_8));
if (!GENERATED_SUB_CITS_SEEN.add(firstItemModelIdentifier)) // cit generated duplicate
firstItemModelIdentifier = new Identifier(firstItemModelIdentifier.getNamespace(), GENERATED_SUB_CITS_PREFIX + GENERATED_SUB_CITS_SEEN.size() + "_" + firstItemModelIdentifier.getPath());
@@ -432,8 +425,6 @@ public class TypeItem extends CITType {
return json;
} catch (Exception e) {
return null;
- } finally {
- IOUtils.closeQuietly(itemModelResource);
}
}
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/config/CITResewnDefaultsConfigScreenFactory.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/config/CITResewnDefaultsConfigScreenFactory.java
index 95b0579..b25b773 100644
--- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/config/CITResewnDefaultsConfigScreenFactory.java
+++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/config/CITResewnDefaultsConfigScreenFactory.java
@@ -5,8 +5,7 @@ import me.shedaniel.clothconfig2.api.ConfigBuilder;
import me.shedaniel.clothconfig2.api.ConfigCategory;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.minecraft.client.gui.screen.Screen;
-import net.minecraft.text.LiteralText;
-import net.minecraft.text.TranslatableText;
+import net.minecraft.text.Text;
import shcm.shsupercm.fabric.citresewn.config.CITResewnConfigScreenFactory;
public class CITResewnDefaultsConfigScreenFactory {
@@ -16,14 +15,14 @@ public class CITResewnDefaultsConfigScreenFactory {
ConfigBuilder builder = ConfigBuilder.create()
.setParentScreen(parent)
- .setTitle(new TranslatableText("config.citresewn-defaults.title"))
+ .setTitle(Text.translatable("config.citresewn-defaults.title"))
.setSavingRunnable(currentConfig::write);
- ConfigCategory category = builder.getOrCreateCategory(new LiteralText(""));
+ ConfigCategory category = builder.getOrCreateCategory(Text.empty());
ConfigEntryBuilder entryBuilder = builder.entryBuilder();
- category.addEntry(entryBuilder.startFloatField(new TranslatableText("config.citresewn-defaults.type_enchantment_scroll_multiplier.title"), currentConfig.type_enchantment_scroll_multiplier)
- .setTooltip(new TranslatableText("config.citresewn-defaults.type_enchantment_scroll_multiplier.tooltip"))
+ category.addEntry(entryBuilder.startFloatField(Text.translatable("config.citresewn-defaults.type_enchantment_scroll_multiplier.title"), currentConfig.type_enchantment_scroll_multiplier)
+ .setTooltip(Text.translatable("config.citresewn-defaults.type_enchantment_scroll_multiplier.tooltip"))
.setSaveConsumer(newConfig -> currentConfig.type_enchantment_scroll_multiplier = newConfig)
.setDefaultValue(defaultConfig.type_enchantment_scroll_multiplier)
.build());
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/common/ModelLoaderMixin.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/common/ModelLoaderMixin.java
index 8ed0e20..333ad6c 100644
--- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/common/ModelLoaderMixin.java
+++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/common/ModelLoaderMixin.java
@@ -35,10 +35,8 @@ public class ModelLoaderMixin {
@Inject(method = "loadModelFromJson", cancellable = true, at = @At("HEAD"))
public void citresewn$forceLiteralResewnModelIdentifier(Identifier id, CallbackInfoReturnable<JsonUnbakedModel> cir) {
if (id instanceof ResewnItemModelIdentifier) {
- InputStream is = null;
- Resource resource = null;
- try {
- JsonUnbakedModel json = JsonUnbakedModel.deserialize(IOUtils.toString(is = (resource = resourceManager.getResource(id)).getInputStream(), StandardCharsets.UTF_8));
+ try (InputStream is = resourceManager.getResource(id).orElseThrow().getInputStream()) {
+ JsonUnbakedModel json = JsonUnbakedModel.deserialize(IOUtils.toString(is, StandardCharsets.UTF_8));
json.id = id.toString();
json.id = json.id.substring(0, json.id.length() - 5);
@@ -79,8 +77,6 @@ public class ModelLoaderMixin {
cir.setReturnValue(json);
} catch (Exception ignored) {
- } finally {
- IOUtils.closeQuietly(is, resource);
}
}
}
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ModelLoaderMixin.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ModelLoaderMixin.java
index 93bab6a..4a9da85 100644
--- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ModelLoaderMixin.java
+++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/mixin/types/item/ModelLoaderMixin.java
@@ -89,7 +89,7 @@ public class ModelLoaderMixin {
}
@ModifyArg(method = "loadModelFromJson", at =
- @At(value = "INVOKE", target = "Lnet/minecraft/resource/ResourceManager;getResource(Lnet/minecraft/util/Identifier;)Lnet/minecraft/resource/Resource;"))
+ @At(value = "INVOKE", target = "Lnet/minecraft/resource/ResourceManager;openAsReader(Lnet/minecraft/util/Identifier;)Ljava/io/BufferedReader;"))
public Identifier citresewn$fixDuplicatePrefixSuffix(Identifier original) {
if (CONTAINER.active() && original.getPath().startsWith("models/models/") && original.getPath().endsWith(".json.json") && original.getPath().contains("cit"))
return new Identifier(original.getNamespace(), original.getPath().substring(7, original.getPath().length() - 5));