diff options
Diffstat (limited to 'defaults/src/main')
5 files changed, 17 insertions, 36 deletions
diff --git a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionHand.java b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionHand.java index 0405cbc..d76c90f 100644 --- a/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionHand.java +++ b/defaults/src/main/java/shcm/shsupercm/fabric/citresewn/defaults/cit/conditions/ConditionHand.java @@ -1,6 +1,7 @@ package shcm.shsupercm.fabric.citresewn.defaults.cit.conditions; import io.shcm.shsupercm.fabric.fletchingtable.api.Entrypoint; +import net.minecraft.util.Hand; import shcm.shsupercm.fabric.citresewn.api.CITConditionContainer; import shcm.shsupercm.fabric.citresewn.cit.CITContext; import shcm.shsupercm.fabric.citresewn.cit.builtin.conditions.EnumCondition; @@ -16,18 +17,12 @@ public class ConditionHand extends EnumCondition<ConditionHand.Hand> { @Override protected Hand getValue(CITContext context) { - if (context.entity.getMainHandStack() == context.stack) - return Hand.MAINHAND; - if (context.entity.getOffHandStack() == context.stack) - return Hand.OFFHAND; - - return null; + return context.entity != null && context.entity.getOffHandStack() == context.stack ? Hand.OFFHAND : Hand.MAINHAND; } @Override public boolean test(CITContext context) { - Hand hand = getValue(context); - return this.value == hand || (this.value == Hand.ANY && hand != null); + return this.value == Hand.ANY || this.value == getValue(context); } protected enum Hand implements EnumCondition.Aliased { 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)); |