diff options
author | SHsuperCM <shsupercm@gmail.com> | 2022-01-21 14:21:23 +0200 |
---|---|---|
committer | SHsuperCM <shsupercm@gmail.com> | 2022-01-21 14:21:23 +0200 |
commit | 897172bde9128da47181a6db6c1ff4885081ba8d (patch) | |
tree | 462e0c45eddaf727596a77b6a17d41560fa4796e /src/main/java/shcm/shsupercm/fabric | |
parent | c3c547c6f950ebbc047cd31672f6a794483a9d0e (diff) | |
download | CITResewn-897172bde9128da47181a6db6c1ff4885081ba8d.tar.gz CITResewn-897172bde9128da47181a6db6c1ff4885081ba8d.tar.bz2 CITResewn-897172bde9128da47181a6db6c1ff4885081ba8d.zip |
Re(moved) most of the old sources
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric')
43 files changed, 19 insertions, 2906 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java deleted file mode 100644 index 8d56a35..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/ActiveCITs.java +++ /dev/null @@ -1,187 +0,0 @@ -package shcm.shsupercm.fabric.citresewn; - -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.util.Hand; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.World; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; -import shcm.shsupercm.fabric.citresewn.pack.CITPack; -import shcm.shsupercm.fabric.citresewn.pack.cits.*; - -import java.util.*; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -public class ActiveCITs { - public final List<CITPack> packs; - public final CITPack effectiveGlobalProperties = new CITPack(null); - - public final List<CIT> cits; - - public final Map<Item, List<CITItem>> citItems = new HashMap<>(); - public final Map<ArmorItem, List<CITArmor>> citArmor = new HashMap<>(); - public final List<CITElytra> citElytra = new ArrayList<>(); - public final List<List<CITEnchantment>> citEnchantments = new ArrayList<>(); - - - public ActiveCITs(List<CITPack> packs, List<CIT> cits) { - this.packs = packs; - this.cits = cits; - - for (CITPack pack : packs) - effectiveGlobalProperties.loadGlobalProperties(pack); - for (CITPack pack : packs) - pack.loadGlobalProperties(effectiveGlobalProperties); - - Map<Integer, List<CITEnchantment>> citEnchantmentLayers = new TreeMap<>(); // order citEnchantments by layers - - for (CIT cit : cits.stream().sorted(Comparator.<CIT>comparingInt(cit -> cit.weight).reversed().thenComparing(cit -> cit.propertiesIdentifier.toString())).collect(Collectors.toList())) { - if (cit instanceof CITItem item) - for (Item type : item.items) - citItems.computeIfAbsent(type, t -> new ArrayList<>()).add(item); - else if (cit instanceof CITArmor armor) - for (Item type : armor.items) - if (type instanceof ArmorItem armorType) - citArmor.computeIfAbsent(armorType, t -> new ArrayList<>()).add(armor); - else - CITResewn.logErrorLoading("Ignoring item type: " + Registry.ITEM.getId(type) + " is not armor in " + cit.pack.resourcePack.getName() + " -> " + cit.propertiesIdentifier.toString()); - else if (cit instanceof CITElytra elytra) - citElytra.add(elytra); - else if (cit instanceof CITEnchantment enchantment) - citEnchantmentLayers.computeIfAbsent(enchantment.layer, l -> new ArrayList<>()).add(enchantment); - } - - for (List<CITEnchantment> layer : citEnchantmentLayers.values()) { - for (CITEnchantment enchantment : layer) - enchantment.activate(); - citEnchantments.add(layer); - } - } - - public void dispose() { - for (CIT cit : cits) - cit.dispose(); - cits.clear(); - citItems.clear(); - citArmor.clear(); - citElytra.clear(); - citEnchantments.clear(); - } - - public CITItem getCITItem(ItemStack stack, World world, LivingEntity entity) { - Hand hand = entity != null && stack == entity.getOffHandStack() ? Hand.OFF_HAND : Hand.MAIN_HAND; - - ((CITItem.Cached) (Object) stack).citresewn_setMojankCIT(false); - - List<CITItem> citItems = this.citItems.get(stack.getItem()); - if (citItems != null) - for (CITItem citItem : citItems) - if (citItem.test(stack, hand, world, entity, true)) { - if (stack.isOf(Items.TRIDENT) || stack.isOf(Items.SPYGLASS)) - ((CITItem.Cached) (Object) stack).citresewn_setMojankCIT(true); - return citItem; - } - return null; - } - - public CITElytra getCITElytra(ItemStack stack, World world, LivingEntity livingEntity) { - for (CITElytra citElytra : citElytra) - if (citElytra.test(stack, Hand.MAIN_HAND, world, livingEntity, true)) - return citElytra; - return null; - } - - public CITArmor getCITArmor(ItemStack stack, World world, LivingEntity livingEntity) { - Item item = stack.getItem(); - if (item instanceof ArmorItem) { - List<CITArmor> citArmor = this.citArmor.get(item); - if (citArmor != null) - for (CITArmor armor : citArmor) - if (armor.test(stack, null, world, livingEntity, true)) - return armor; - } - return null; - } - - public List<CITEnchantment> getCITEnchantment(ItemStack stack, World world, LivingEntity livingEntity) { - Hand hand = livingEntity != null && stack == livingEntity.getOffHandStack() ? Hand.OFF_HAND : Hand.MAIN_HAND; - - List<CITEnchantment> applied = new ArrayList<>(); - - for (List<CITEnchantment> layer : this.citEnchantments) - for (CITEnchantment cit : layer) - if (cit.test(stack, hand, world, livingEntity, false)) { - applied.add(cit); - break; - } - - return applied; - } - - public BakedModel getItemModelCached(ItemStack stack, World world, LivingEntity entity, int seed) { - BakedModel bakedModel = null; - - Supplier<CITItem> realtime = () -> getCITItem(stack, world, entity); - - //noinspection ConstantConditions - CITItem citItem = CITResewnConfig.INSTANCE().cache_ms == 0 ? realtime.get() : ((CITItem.Cached) (Object) stack).citresewn_getCachedCITItem(realtime); - - if (citItem != null) - bakedModel = citItem.getItemModel(stack, (ClientWorld) world, entity, seed); - - return bakedModel; - } - - public Identifier getElytraTextureCached(ItemStack stack, World world, LivingEntity livingEntity) { - Supplier<CITElytra> realtime = () -> getCITElytra(stack, world, livingEntity); - - //noinspection ConstantConditions - CITElytra citElytra = CITResewnConfig.INSTANCE().cache_ms == 0 ? realtime.get() : ((CITElytra.Cached) (Object) stack).citresewn_getCachedCITElytra(realtime); - - if (citElytra != null) - return citElytra.textureIdentifier; - - return null; - } - - public Map<String, Identifier> getArmorTexturesCached(ItemStack stack, World world, LivingEntity livingEntity) { - Supplier<CITArmor> realtime = () -> getCITArmor(stack, world, livingEntity); - - //noinspection ConstantConditions - CITArmor citArmor = CITResewnConfig.INSTANCE().cache_ms == 0 ? realtime.get() : ((CITArmor.Cached) (Object) stack).citresewn_getCachedCITArmor(realtime); - - if (citArmor != null) - return citArmor.textures; - - return null; - } - - public void setEnchantmentAppliedContextCached(ItemStack stack, World world, LivingEntity entity) { - if (stack == null) { - CITEnchantment.appliedContext = null; - return; - } - - Supplier<List<CITEnchantment>> realtime = () -> getCITEnchantment(stack, world, entity); - - //noinspection ConstantConditions - List<CITEnchantment> citEnchantments = CITResewnConfig.INSTANCE().cache_ms == 0 ? realtime.get() : ((CITEnchantment.Cached) (Object) stack).citresewn_getCachedCITEnchantment(realtime); - - if (citEnchantments == null || citEnchantments.isEmpty()) { - CITEnchantment.appliedContext = null; - return; - } - - if (effectiveGlobalProperties.method != null) - effectiveGlobalProperties.method.applyMethod(citEnchantments, stack); - - CITEnchantment.appliedContext = citEnchantments; - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java index e53ba52..4ebfff8 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewn.java @@ -12,20 +12,11 @@ public class CITResewn implements ClientModInitializer { public static final Logger LOG = LogManager.getLogger("CITResewn"); public static CITResewn INSTANCE; - public ActiveCITs activeCITs = null; - - public CITResewnConfig config = null; - - public boolean processingBrokenPaths = false; @Override public void onInitializeClient() { INSTANCE = this; - - config = CITResewnConfig.read(); - - CITResewnCommand.register(); } public static void info(String message) { @@ -33,13 +24,13 @@ public class CITResewn implements ClientModInitializer { } public static void logWarnLoading(String message) { - if (CITResewnConfig.INSTANCE().mute_warns) + if (CITResewnConfig.INSTANCE.mute_warns) return; LOG.error("[citresewn] " + message); } public static void logErrorLoading(String message) { - if (CITResewnConfig.INSTANCE().mute_errors) + if (CITResewnConfig.INSTANCE.mute_errors) return; LOG.error("{citresewn} " + message); } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewnCommand.java b/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewnCommand.java deleted file mode 100644 index 483cbfb..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/CITResewnCommand.java +++ /dev/null @@ -1,33 +0,0 @@ -package shcm.shsupercm.fabric.citresewn; - -import net.fabricmc.fabric.api.client.command.v1.ClientCommandManager; -import net.fabricmc.loader.api.FabricLoader; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; - -import static net.fabricmc.fabric.api.client.command.v1.ClientCommandManager.literal; -import static net.minecraft.text.Text.of; - -public class CITResewnCommand { - public static boolean openConfig = false; - - public static void register() { - ClientCommandManager.DISPATCHER.register(literal("citresewn") - .executes(context -> { - context.getSource().sendFeedback(of("CIT Resewn v" + FabricLoader.getInstance().getModContainer("citresewn").get().getMetadata().getVersion() + ":")); - boolean active = CITResewnConfig.INSTANCE().enabled && CITResewn.INSTANCE.activeCITs != null; - context.getSource().sendFeedback(of(" Active: " + (active ? "yes" : "no"))); - if (active) { - context.getSource().sendFeedback(of(" Loaded: " + CITResewn.INSTANCE.activeCITs.cits.size() + " CITs from " + CITResewn.INSTANCE.activeCITs.packs.size() + " resourcepacks")); - } - context.getSource().sendFeedback(of(" ")); - - return 1; - }) - .then(literal("config") - .executes(context -> { - openConfig = true; - - return 1; - }))); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/OptionalCompat.java b/src/main/java/shcm/shsupercm/fabric/citresewn/OptionalCompat.java deleted file mode 100644 index 580aef5..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/OptionalCompat.java +++ /dev/null @@ -1,69 +0,0 @@ -package shcm.shsupercm.fabric.citresewn; - -import io.github.apace100.cosmetic_armor.CosmeticArmor; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.screen.NoticeScreen; -import net.minecraft.client.gui.screen.Screen; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.text.Text; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfigScreenFactory; - -import java.util.function.Function; -import java.util.function.Predicate; - -public final class OptionalCompat { - private static final OptionalCompat INSTANCE = new OptionalCompat(s -> FabricLoader.getInstance().isModLoaded(s)); - - public final CompatClothConfig compatClothConfig; - - public final CompatCosmeticArmor compatCosmeticArmor; - - private OptionalCompat(Predicate<String> isLoaded) { - compatClothConfig = isLoaded.test("cloth-config2") ? CompatClothConfig.impl() : null; - compatCosmeticArmor = isLoaded.test("cosmetic-armor") ? CompatCosmeticArmor.impl() : null; - } - - public static Function<Screen, Screen> getModConfigScreenFactory() { - if (INSTANCE.compatClothConfig != null) { - return INSTANCE.compatClothConfig.getModConfigScreenFactory(); - } - - return parent -> new NoticeScreen(() -> MinecraftClient.getInstance().setScreen(parent), Text.of("CIT Resewn"), Text.of("CIT Resewn requires Cloth Config 2 to be able to show the config.")); - } - - public static ItemStack getCosmeticArmor(ItemStack original, LivingEntity entity, EquipmentSlot slot, boolean elytra) { - if (INSTANCE.compatCosmeticArmor != null) { - ItemStack stackInCosmeticSlot = INSTANCE.compatCosmeticArmor.getStackInCosmeticSlot(entity, slot); - if (!stackInCosmeticSlot.isEmpty() && (!elytra || stackInCosmeticSlot.isOf(Items.ELYTRA))) - return stackInCosmeticSlot; - } - - return original; - } - - /** - * Compatibility with 'cloth-config2': Custom gui for CITResewn's config - */ - public interface CompatClothConfig { - private static CompatClothConfig impl() { - return () -> CITResewnConfigScreenFactory::create; - } - - Function<Screen, Screen> getModConfigScreenFactory(); - } - - /** - * Compatibility with 'cosmetic-armor': Display cits for cosmetic armors instead of equipped armors - */ - public interface CompatCosmeticArmor { - private static CompatCosmeticArmor impl() { - return CosmeticArmor::getCosmeticArmor; - } - - ItemStack getStackInCosmeticSlot(LivingEntity entity, EquipmentSlot slot); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfig.java b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfig.java index 04b3166..2f051f0 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfig.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfig.java @@ -4,8 +4,6 @@ import com.google.gson.Gson; import com.google.gson.stream.JsonWriter; import org.apache.commons.io.IOUtils; import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.pack.CITParser; -import shcm.shsupercm.fabric.citresewn.pack.cits.CITItem; import java.io.*; @@ -13,14 +11,12 @@ public class CITResewnConfig { public boolean enabled = true; public boolean mute_errors = false; public boolean mute_warns = false; - public float citenchantment_scroll_multiplier = 8f; public int cache_ms = 50; public boolean broken_paths = false; private static final File FILE = new File("config/citresewn.json"); - public static CITResewnConfig INSTANCE() { - return CITResewn.INSTANCE.config; - } + + public static final CITResewnConfig INSTANCE = read(); public static CITResewnConfig read() { if (!FILE.exists()) diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java index 055c976..33f4950 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnConfigScreenFactory.java @@ -11,7 +11,7 @@ import net.minecraft.util.Formatting; public class CITResewnConfigScreenFactory { public static Screen create(Screen parent) { - CITResewnConfig currentConfig = CITResewnConfig.INSTANCE(), defaultConfig = new CITResewnConfig(); + CITResewnConfig currentConfig = CITResewnConfig.INSTANCE, defaultConfig = new CITResewnConfig(); ConfigBuilder builder = ConfigBuilder.create() .setParentScreen(parent) @@ -44,13 +44,6 @@ public class CITResewnConfigScreenFactory { .setDefaultValue(defaultConfig.mute_warns) .build()); - category.addEntry(entryBuilder.startFloatField(new TranslatableText("config.citresewn.citenchantment_scroll_multiplier.title"), currentConfig.citenchantment_scroll_multiplier) - .setTooltip(new TranslatableText("config.citresewn.citenchantment_scroll_multiplier.tooltip")) - .setSaveConsumer(newConfig -> currentConfig.citenchantment_scroll_multiplier = newConfig) - .setDefaultValue(defaultConfig.citenchantment_scroll_multiplier) - .setMin(0f) - .build()); - category.addEntry(entryBuilder.startIntSlider(new TranslatableText("config.citresewn.cache_ms.title"), currentConfig.cache_ms / 50, 0, 5 * 20) .setTooltip(new TranslatableText("config.citresewn.cache_ms.tooltip")) .setSaveConsumer(newConfig -> currentConfig.cache_ms = newConfig * 50) diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java index 7a4954c..cf6d9bd 100644 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java +++ b/src/main/java/shcm/shsupercm/fabric/citresewn/config/CITResewnModMenu.java @@ -3,11 +3,23 @@ package shcm.shsupercm.fabric.citresewn.config; import com.terraformersmc.modmenu.api.ConfigScreenFactory; import com.terraformersmc.modmenu.api.ModMenuApi; import net.fabricmc.loader.api.FabricLoader; -import shcm.shsupercm.fabric.citresewn.OptionalCompat; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.NoticeScreen; +import net.minecraft.text.Text; public class CITResewnModMenu implements ModMenuApi { @Override public ConfigScreenFactory<?> getModConfigScreenFactory() { - return OptionalCompat.getModConfigScreenFactory()::apply; + if (FabricLoader.getInstance().isModLoaded("cloth-config2")) + return new ClothConfigOpenImpl().getModConfigScreenFactory(); + + return parent -> new NoticeScreen(() -> MinecraftClient.getInstance().setScreen(parent), Text.of("CIT Resewn"), Text.of("CIT Resewn requires Cloth Config to be able to show the config.")); + } + + private static class ClothConfigOpenImpl implements ModMenuApi { + @Override + public ConfigScreenFactory<?> getModConfigScreenFactory() { + return CITResewnConfigScreenFactory::create; + } } } diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ex/CITLoadException.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ex/CITLoadException.java deleted file mode 100644 index c40bc80..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/ex/CITLoadException.java +++ /dev/null @@ -1,13 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.ex; - -import net.minecraft.resource.ResourcePack; -import net.minecraft.util.Identifier; - -/** - * Thrown when a cit failed to be loaded - */ -public class CITLoadException extends Exception { - public CITLoadException(ResourcePack resourcePack, Identifier identifier, String message) { - super("Couldn't load CIT: " + message + " in " + resourcePack.getName() + " -> " + identifier.toString()); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/ex/CITParseException.java b/src/main/java/shcm/shsupercm/fabric/citresewn/ex/CITParseException.java deleted file mode 100644 index 95bc386..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/ex/CITParseException.java +++ /dev/null @@ -1,13 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.ex; - -import net.minecraft.resource.ResourcePack; -import net.minecraft.util.Identifier; - -/** - * Thrown when a cit failed to be parsed - */ -public class CITParseException extends Exception { - public CITParseException(ResourcePack resourcePack, Identifier identifier, String message) { - super("Skipped CIT: " + message + " in " + resourcePack.getName() + " -> " + identifier.toString()); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/AbstractFileResourcePackMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/AbstractFileResourcePackMixin.java deleted file mode 100644 index 281150b..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/AbstractFileResourcePackMixin.java +++ /dev/null @@ -1,49 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.broken_paths; - -import net.minecraft.resource.AbstractFileResourcePack; -import net.minecraft.resource.DirectoryResourcePack; -import net.minecraft.resource.ResourcePack; -import net.minecraft.resource.ZipResourcePack; -import net.minecraft.resource.metadata.PackResourceMetadata; -import net.minecraft.resource.metadata.ResourceMetadataReader; -import net.minecraft.util.Identifier; -import net.minecraft.util.InvalidIdentifierException; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.zip.ZipFile; - -/* if (CITResewnConfig.read().broken_paths) */ @Mixin(AbstractFileResourcePack.class) -public abstract class AbstractFileResourcePackMixin implements ResourcePack { - @Shadow @Final protected File base; - - @SuppressWarnings({"unchecked", "ConstantConditions", "EqualsBetweenInconvertibleTypes"}) - @Inject(method = "parseMetadata(Lnet/minecraft/resource/metadata/ResourceMetadataReader;)Ljava/lang/Object;", cancellable = true, at = @At("RETURN")) - public <T extends PackResourceMetadata> void parseMetadata(ResourceMetadataReader<T> metaReader, CallbackInfoReturnable<T> cir) { - if (cir.getReturnValue() != null) - try { - if (this.getClass().equals(ZipResourcePack.class)) { - try (ZipFile zipFile = new ZipFile(base)) { - zipFile.stream() - .forEach(entry -> { - if (entry.getName().startsWith("assets")) - new Identifier("minecraft", entry.getName()); - }); - } - } else if (this.getClass().equals(DirectoryResourcePack.class)) { - final Path assets = new File(base, "assets").toPath(); - Files.walk(assets) - .forEach(path -> new Identifier("minecraft", assets.relativize(path).toString().replace('\\', '/'))); - } - } catch (InvalidIdentifierException e) { - cir.setReturnValue((T) new PackResourceMetadata(cir.getReturnValue().getDescription(), Integer.MAX_VALUE - 53)); - } catch (Exception ignored) {} - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/IdentifierMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/IdentifierMixin.java deleted file mode 100644 index da9888f..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/IdentifierMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.broken_paths; - -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import shcm.shsupercm.fabric.citresewn.CITResewn; - -/* if (CITResewnConfig.read().broken_paths) */ @Mixin(Identifier.class) -public class IdentifierMixin { - @Inject(method = "isPathValid", cancellable = true, at = @At("HEAD")) - private static void processBrokenPaths(String path, CallbackInfoReturnable<Boolean> cir) { - if (CITResewn.INSTANCE != null && CITResewn.INSTANCE.processingBrokenPaths) - cir.setReturnValue(true); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ReloadableResourceManagerImplMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ReloadableResourceManagerImplMixin.java deleted file mode 100644 index e2b193a..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ReloadableResourceManagerImplMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.broken_paths; - -import net.minecraft.resource.ReloadableResourceManagerImpl; -import net.minecraft.resource.ResourcePack; -import net.minecraft.resource.ResourceReload; -import net.minecraft.resource.ResourceType; -import net.minecraft.util.Unit; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import shcm.shsupercm.fabric.citresewn.CITResewn; - -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Executor; - -/* if (CITResewnConfig.read().broken_paths) */ @Mixin(ReloadableResourceManagerImpl.class) -public class ReloadableResourceManagerImplMixin { - @Shadow @Final private ResourceType type; - - @Inject(method = "reload", at = @At("RETURN")) - public void onReload(Executor prepareExecutor, Executor applyExecutor, CompletableFuture<Unit> initialStage, List<ResourcePack> packs, CallbackInfoReturnable<ResourceReload> cir) { - if (CITResewn.INSTANCE.processingBrokenPaths = this.type == ResourceType.CLIENT_RESOURCES) { - CITResewn.LOG.error("[citresewn] Caution! Broken paths is enabled!"); - cir.getReturnValue().whenComplete().thenRun(() -> CITResewn.INSTANCE.processingBrokenPaths = false); - } - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ResourcePackCompatibilityMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ResourcePackCompatibilityMixin.java deleted file mode 100644 index f62221b..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/broken_paths/ResourcePackCompatibilityMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.broken_paths; - -import net.minecraft.resource.ResourcePackCompatibility; -import net.minecraft.resource.ResourceType; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -/* if (CITResewnConfig.read().broken_paths) */ @Mixin(ResourcePackCompatibility.class) -public abstract class ResourcePackCompatibilityMixin { - private static final ResourcePackCompatibility BROKEN_PATHS = ResourcePackCompatibility("BROKEN_PATHS", -1, "broken_paths"); - - @SuppressWarnings("InvokerTarget") - @Invoker("<init>") - public static ResourcePackCompatibility ResourcePackCompatibility(String internalName, int internalId, String translationSuffix) { - throw new AssertionError(); - } - - @Inject(method = "from(ILnet/minecraft/resource/ResourceType;)Lnet/minecraft/resource/ResourcePackCompatibility;", cancellable = true, at = @At("HEAD")) - private static void redirectBrokenPathsCompatibility(int packVersion, ResourceType type, CallbackInfoReturnable<ResourcePackCompatibility> cir) { - if (packVersion == Integer.MAX_VALUE - 53) - cir.setReturnValue(BROKEN_PATHS); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citarmor/ArmorFeatureRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citarmor/ArmorFeatureRendererMixin.java deleted file mode 100644 index 72a0ade..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citarmor/ArmorFeatureRendererMixin.java +++ /dev/null @@ -1,59 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.citarmor; - -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.feature.ArmorFeatureRenderer; -import net.minecraft.client.render.entity.model.BipedEntityModel; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ArmorItem; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.OptionalCompat; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; - -import java.lang.ref.WeakReference; -import java.util.Map; - -@Mixin(ArmorFeatureRenderer.class) -public class ArmorFeatureRendererMixin<T extends LivingEntity, M extends BipedEntityModel<T>, A extends BipedEntityModel<T>> { - private WeakReference<Map<String, Identifier>> armorTexturesCached = null; - - @Inject(method = "renderArmor", at = @At("HEAD")) - private void renderArmor(MatrixStack matrices, VertexConsumerProvider vertexConsumers, T entity, EquipmentSlot armorSlot, int light, A model, CallbackInfo ci) { - if (!CITResewnConfig.INSTANCE().enabled || CITResewn.INSTANCE.activeCITs == null) - return; - - ItemStack itemStack = entity.getEquippedStack(armorSlot); - - //compat Cosmetic Armor - itemStack = OptionalCompat.getCosmeticArmor(itemStack, entity, armorSlot, false); - - Map<String, Identifier> armorTextures = CITResewn.INSTANCE.activeCITs.getArmorTexturesCached(itemStack, entity.world, entity); - if (armorTextures != null) { - armorTexturesCached = new WeakReference<>(armorTextures); - return; - } - - armorTexturesCached = null; - } - - @Inject(method = "getArmorTexture", cancellable = true, at = @At("HEAD")) - private void getArmorTexture(ArmorItem item, boolean legs, String overlay, CallbackInfoReturnable<Identifier> cir) { - if (armorTexturesCached == null) - return; - Map<String, Identifier> armorTextures = armorTexturesCached.get(); - if (armorTextures == null) - return; - - Identifier identifier = armorTextures.get(item.getMaterial().getName() + "_layer_" + (legs ? "2" : "1") + (overlay == null ? "" : "_" + overlay)); - if (identifier != null) - cir.setReturnValue(identifier); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citarmor/ItemStackMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citarmor/ItemStackMixin.java deleted file mode 100644 index 6041c9b..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citarmor/ItemStackMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.citarmor; - -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; -import shcm.shsupercm.fabric.citresewn.pack.cits.CITArmor; - -import java.lang.ref.WeakReference; -import java.util.function.Supplier; - -@Mixin(ItemStack.class) -public class ItemStackMixin implements CITArmor.Cached { - private WeakReference<CITArmor> citresewn_cachedCITArmor = new WeakReference<>(null); - private long citresewn_cacheTimeCITArmor = 0; - - @Override - public CITArmor citresewn_getCachedCITArmor(Supplier<CITArmor> realtime) { - if (System.currentTimeMillis() - citresewn_cacheTimeCITArmor >= CITResewnConfig.INSTANCE().cache_ms) { - citresewn_cachedCITArmor = new WeakReference<>(realtime.get()); - citresewn_cacheTimeCITArmor = System.currentTimeMillis(); - } - - return citresewn_cachedCITArmor.get(); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citelytra/ElytraFeatureRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citelytra/ElytraFeatureRendererMixin.java deleted file mode 100644 index b4151f8..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citelytra/ElytraFeatureRendererMixin.java +++ /dev/null @@ -1,60 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.citelytra; - -import net.minecraft.client.render.RenderLayer; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.feature.ElytraFeatureRenderer; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.OptionalCompat; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; - -import java.lang.ref.WeakReference; - -@Mixin(ElytraFeatureRenderer.class) -public class ElytraFeatureRendererMixin { - private WeakReference<ItemStack> elytraItemCached = new WeakReference<>(null); - private WeakReference<LivingEntity> livingEntityCached = new WeakReference<>(null); - - @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = - @At("HEAD")) - private void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, LivingEntity livingEntity, float f, float g, float h, float j, float k, float l, CallbackInfo ci) { - if (!CITResewnConfig.INSTANCE().enabled || CITResewn.INSTANCE.activeCITs == null) - return; - - ItemStack itemStack = livingEntity.getEquippedStack(EquipmentSlot.CHEST); - - //compat Cosmetic Armor - itemStack = OptionalCompat.getCosmeticArmor(itemStack, livingEntity, EquipmentSlot.CHEST, true); - - this.elytraItemCached = new WeakReference<>(itemStack); - this.livingEntityCached = new WeakReference<>(livingEntity); - } - - @ModifyArg(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = - @At(value = "INVOKE", target = "Lnet/minecraft/client/render/item/ItemRenderer;getArmorGlintConsumer(Lnet/minecraft/client/render/VertexConsumerProvider;Lnet/minecraft/client/render/RenderLayer;ZZ)Lnet/minecraft/client/render/VertexConsumer;"), index = 1) - private RenderLayer getArmorCutoutNoCull(RenderLayer original) { - if (CITResewnConfig.INSTANCE().enabled && CITResewn.INSTANCE.activeCITs != null) { - ItemStack itemStack = this.elytraItemCached.get(); - LivingEntity livingEntity = this.livingEntityCached.get(); - if (itemStack != null && itemStack.isOf(Items.ELYTRA) && livingEntity != null) { - Identifier elytraTexture = CITResewn.INSTANCE.activeCITs.getElytraTextureCached(itemStack, livingEntity.world, livingEntity); - this.elytraItemCached = new WeakReference<>(null); - this.livingEntityCached = new WeakReference<>(null); - if (elytraTexture != null) - return RenderLayer.getArmorCutoutNoCull(elytraTexture); - } - } - - return original; - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citelytra/ItemStackMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citelytra/ItemStackMixin.java deleted file mode 100644 index aaf4037..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citelytra/ItemStackMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.citelytra; - -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; -import shcm.shsupercm.fabric.citresewn.pack.cits.CITElytra; - -import java.lang.ref.WeakReference; -import java.util.function.Supplier; - -@Mixin(ItemStack.class) -public class ItemStackMixin implements CITElytra.Cached { - private WeakReference<CITElytra> citresewn_cachedCITElytra = new WeakReference<>(null); - private long citresewn_cacheTimeCITElytra = 0; - - @Override - public CITElytra citresewn_getCachedCITElytra(Supplier<CITElytra> realtime) { - if (System.currentTimeMillis() - citresewn_cacheTimeCITElytra >= CITResewnConfig.INSTANCE().cache_ms) { - citresewn_cachedCITElytra = new WeakReference<>(realtime.get()); - citresewn_cacheTimeCITElytra = System.currentTimeMillis(); - } - - return citresewn_cachedCITElytra.get(); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ArmorFeatureRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ArmorFeatureRendererMixin.java deleted file mode 100644 index b4d81c7..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ArmorFeatureRendererMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.citenchantment; - -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.feature.ArmorFeatureRenderer; -import net.minecraft.client.render.entity.model.BipedEntityModel; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.LivingEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; -import shcm.shsupercm.fabric.citresewn.pack.cits.CITEnchantment; - -@Mixin(ArmorFeatureRenderer.class) -public class ArmorFeatureRendererMixin<T extends LivingEntity, M extends BipedEntityModel<T>, A extends BipedEntityModel<T>> { - @Inject(method = "renderArmor", at = @At("HEAD")) - private void setAppliedContextAndStartApplyingArmor(MatrixStack matrices, VertexConsumerProvider vertexConsumers, T livingEntity, EquipmentSlot armorSlot, int light, A model, CallbackInfo ci) { - if (CITResewnConfig.INSTANCE().enabled && CITResewn.INSTANCE.activeCITs != null) { - CITResewn.INSTANCE.activeCITs.setEnchantmentAppliedContextCached(livingEntity.getEquippedStack(armorSlot), livingEntity.world, livingEntity); - CITEnchantment.shouldApply = true; - } - } - - @Inject(method = "renderArmor", at = @At("RETURN")) - private void stopApplyingArmor(MatrixStack matrices, VertexConsumerProvider vertexConsumers, T livingEntity, EquipmentSlot armorSlot, int light, A model, CallbackInfo ci) { - CITEnchantment.shouldApply = false; - if (CITResewn.INSTANCE.activeCITs != null) - CITResewn.INSTANCE.activeCITs.setEnchantmentAppliedContextCached(null, null, null); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/BufferBuilderStorageAccessor.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/BufferBuilderStorageAccessor.java deleted file mode 100644 index 619a82d..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/BufferBuilderStorageAccessor.java +++ /dev/null @@ -1,15 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.citenchantment; - -import net.minecraft.client.render.BufferBuilder; -import net.minecraft.client.render.BufferBuilderStorage; -import net.minecraft.client.render.RenderLayer; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.SortedMap; - -@Mixin(BufferBuilderStorage.class) -public interface BufferBuilderStorageAccessor { - @Accessor("entityBuilders") - SortedMap<RenderLayer, BufferBuilder> entityBuilders(); -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ElytraFeatureRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ElytraFeatureRendererMixin.java deleted file mode 100644 index 03fb4c0..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ElytraFeatureRendererMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.citenchantment; - -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.entity.feature.ElytraFeatureRenderer; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; -import shcm.shsupercm.fabric.citresewn.pack.cits.CITEnchantment; - -@Mixin(ElytraFeatureRenderer.class) -public class ElytraFeatureRendererMixin { - @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = @At("HEAD")) - private void setAppliedContextAndStartApplyingElytra(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, LivingEntity livingEntity, float f, float g, float h, float j, float k, float l, CallbackInfo ci) { - if (CITResewnConfig.INSTANCE().enabled && CITResewn.INSTANCE.activeCITs != null) { - CITResewn.INSTANCE.activeCITs.setEnchantmentAppliedContextCached(livingEntity.getEquippedStack(EquipmentSlot.CHEST), livingEntity.world, livingEntity); - CITEnchantment.shouldApply = true; - } - } - - @Inject(method = "render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;ILnet/minecraft/entity/LivingEntity;FFFFFF)V", at = @At("RETURN")) - private void stopApplyingElytra(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, LivingEntity livingEntity, float f, float g, float h, float j, float k, float l, CallbackInfo ci) { - CITEnchantment.shouldApply = false; - if (CITResewn.INSTANCE.activeCITs != null) - CITResewn.INSTANCE.activeCITs.setEnchantmentAppliedContextCached(null, null, null); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ItemRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ItemRendererMixin.java deleted file mode 100644 index 13d91c7..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ItemRendererMixin.java +++ /dev/null @@ -1,86 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.citenchantment; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.*; -import net.minecraft.client.render.item.ItemRenderer; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.render.model.json.ModelTransformation; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; -import shcm.shsupercm.fabric.citresewn.pack.cits.CITEnchantment; - -@Mixin(ItemRenderer.class) -public class ItemRendererMixin { - @Inject(method = "getModel", at = @At("TAIL")) - private void setAppliedContext(ItemStack stack, World world, LivingEntity entity, int seed, CallbackInfoReturnable<BakedModel> cir) { - if (CITResewnConfig.INSTANCE().enabled && CITResewn.INSTANCE.activeCITs != null) - CITResewn.INSTANCE.activeCITs.setEnchantmentAppliedContextCached(stack, world, entity); - } - - @Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformation$Mode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", at = @At("HEAD")) - private void startApplyingItem(ItemStack stack, ModelTransformation.Mode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci) { - if (CITResewnConfig.INSTANCE().enabled) - CITEnchantment.shouldApply = true; - } - - @Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformation$Mode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", at = @At("TAIL")) - private void stopApplyingItem(ItemStack stack, ModelTransformation.Mode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci) { - CITEnchantment.shouldApply = false; - if (CITResewn.INSTANCE.activeCITs != null) - CITResewn.INSTANCE.activeCITs.setEnchantmentAppliedContextCached(null, null, null); - } - - @Inject(method = "getArmorGlintConsumer", cancellable = true, at = @At("RETURN")) - private static void getArmorGlintConsumer(VertexConsumerProvider provider, RenderLayer layer, boolean solid, boolean glint, CallbackInfoReturnable<VertexConsumer> cir) { - if (!CITEnchantment.shouldApply) - return; - VertexConsumer vertexConsumer = solid ? CITEnchantment.GlintRenderLayer.ARMOR_GLINT.tryApply(cir.getReturnValue(), layer, provider) : CITEnchantment.GlintRenderLayer.ARMOR_ENTITY_GLINT.tryApply(cir.getReturnValue(), layer, provider); - if (vertexConsumer != null) - cir.setReturnValue(vertexConsumer); - } - - @Inject(method = "getCompassGlintConsumer", cancellable = true, at = @At("RETURN")) - private static void getCompassGlintConsumer(VertexConsumerProvider provider, RenderLayer layer, MatrixStack.Entry entry, CallbackInfoReturnable<VertexConsumer> cir) { - if (!CITEnchantment.shouldApply) - return; - VertexConsumer vertexConsumer = CITEnchantment.GlintRenderLayer.GLINT.tryApply(null, layer, provider); - if (vertexConsumer != null) - cir.setReturnValue(VertexConsumers.union(new OverlayVertexConsumer(vertexConsumer, entry.getPositionMatrix(), entry.getNormalMatrix()), cir.getReturnValue())); - } - - @Inject(method = "getDirectCompassGlintConsumer", cancellable = true, at = @At("RETURN")) - private static void getDirectCompassGlintConsumer(VertexConsumerProvider provider, RenderLayer layer, MatrixStack.Entry entry, CallbackInfoReturnable<VertexConsumer> cir) { - if (!CITEnchantment.shouldApply) - return; - VertexConsumer vertexConsumer = CITEnchantment.GlintRenderLayer.DIRECT_GLINT.tryApply(null, layer, provider); - if (vertexConsumer != null) - cir.setReturnValue(VertexConsumers.union(new OverlayVertexConsumer(vertexConsumer, entry.getPositionMatrix(), entry.getNormalMatrix()), cir.getReturnValue())); - } - - @Inject(method = "getItemGlintConsumer", cancellable = true, at = @At("RETURN")) - private static void getItemGlintConsumer(VertexConsumerProvider provider, RenderLayer layer, boolean solid, boolean glint, CallbackInfoReturnable<VertexConsumer> cir) { - if (!CITEnchantment.shouldApply) - return; - VertexConsumer vertexConsumer = MinecraftClient.isFabulousGraphicsOrBetter() && layer == TexturedRenderLayers.getItemEntityTranslucentCull() ? CITEnchantment.GlintRenderLayer.GLINT_TRANSLUCENT.tryApply(cir.getReturnValue(), layer, provider) : (solid ? CITEnchantment.GlintRenderLayer.GLINT.tryApply(cir.getReturnValue(), layer, provider) : CITEnchantment.GlintRenderLayer.ENTITY_GLINT.tryApply(cir.getReturnValue(), layer, provider)); - if (vertexConsumer != null) - cir.setReturnValue(vertexConsumer); - } - - @Inject(method = "getDirectItemGlintConsumer", cancellable = true, at = @At("RETURN")) - private static void getDirectItemGlintConsumer(VertexConsumerProvider provider, RenderLayer layer, boolean solid, boolean glint, CallbackInfoReturnable<VertexConsumer> cir) { - if (!CITEnchantment.shouldApply) - return; - VertexConsumer vertexConsumer = solid ? CITEnchantment.GlintRenderLayer.DIRECT_GLINT.tryApply(cir.getReturnValue(), layer, provider) : CITEnchantment.GlintRenderLayer.DIRECT_ENTITY_GLINT.tryApply(cir.getReturnValue(), layer, provider); - if (vertexConsumer != null) - cir.setReturnValue(vertexConsumer); - } -}
\ No newline at end of file diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ItemStackMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ItemStackMixin.java deleted file mode 100644 index 033bf8e..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/ItemStackMixin.java +++ /dev/null @@ -1,36 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.citenchantment; - -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; -import shcm.shsupercm.fabric.citresewn.pack.cits.CITEnchantment; - -import java.lang.ref.WeakReference; -import java.util.List; -import java.util.function.Supplier; - -@Mixin(ItemStack.class) -public class ItemStackMixin implements CITEnchantment.Cached { - private WeakReference<List<CITEnchantment>> citresewn_cachedCITEnchantment = new WeakReference<>(null); - private long citresewn_cacheTimeCITEnchantment = 0; - - @Override - public List<CITEnchantment> citresewn_getCachedCITEnchantment(Supplier<List<CITEnchantment>> realtime) { - if (System.currentTimeMillis() - citresewn_cacheTimeCITEnchantment >= CITResewnConfig.INSTANCE().cache_ms) { - citresewn_cachedCITEnchantment = new WeakReference<>(realtime.get()); - citresewn_cacheTimeCITEnchantment = System.currentTimeMillis(); - } - - return citresewn_cachedCITEnchantment.get(); - } - - @Inject(method = "hasGlint", cancellable = true, at = @At("HEAD")) - private void disableDefaultGlint(CallbackInfoReturnable<Boolean> cir) { - if (CITResewn.INSTANCE.activeCITs != null && ((!CITResewn.INSTANCE.activeCITs.effectiveGlobalProperties.useGlint) || (CITEnchantment.appliedContext != null && CITEnchantment.shouldApply && !CITEnchantment.appliedContext.get(0).useGlint))) - cir.setReturnValue(false); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/MinecraftClientMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/MinecraftClientMixin.java deleted file mode 100644 index a9bea56..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/MinecraftClientMixin.java +++ /dev/null @@ -1,17 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.citenchantment; - -import net.minecraft.client.MinecraftClient; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import static shcm.shsupercm.fabric.citresewn.pack.cits.CITEnchantment.MergeMethod.ticks; - -@Mixin(MinecraftClient.class) -public class MinecraftClientMixin { - @Inject(method = "tick", at = @At("HEAD")) - public void onTick(CallbackInfo ci) { - ticks++; - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/RenderPhaseAccessor.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/RenderPhaseAccessor.java deleted file mode 100644 index 24e7c3c..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/citenchantment/RenderPhaseAccessor.java +++ /dev/null @@ -1,21 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.citenchantment; - -import net.minecraft.client.render.RenderPhase; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(RenderPhase.class) -public interface RenderPhaseAccessor { - @Accessor("ARMOR_GLINT_SHADER") static RenderPhase.Shader ARMOR_GLINT_SHADER() { throw new RuntimeException(); } - @Accessor("ARMOR_ENTITY_GLINT_SHADER") static RenderPhase.Shader ARMOR_ENTITY_GLINT_SHADER() { throw new RuntimeException(); } - @Accessor("TRANSLUCENT_GLINT_SHADER") static RenderPhase.Shader TRANSLUCENT_GLINT_SHADER() { throw new RuntimeException(); } - @Accessor("GLINT_SHADER") static RenderPhase.Shader GLINT_SHADER() { throw new RuntimeException(); } - @Accessor("DIRECT_GLINT_SHADER") static RenderPhase.Shader DIRECT_GLINT_SHADER() { throw new RuntimeException(); } - @Accessor("ENTITY_GLINT_SHADER") static RenderPhase.Shader ENTITY_GLINT_SHADER() { throw new RuntimeException(); } - @Accessor("DIRECT_ENTITY_GLINT_SHADER") static RenderPhase.Shader DIRECT_ENTITY_GLINT_SHADER() { throw new RuntimeException(); } - @Accessor("DISABLE_CULLING") static RenderPhase.Cull DISABLE_CULLING() { throw new RuntimeException(); } - @Accessor("EQUAL_DEPTH_TEST") static RenderPhase.DepthTest EQUAL_DEPTH_TEST() { throw new RuntimeException(); } - @Accessor("COLOR_MASK") static RenderPhase.WriteMaskState COLOR_MASK() { throw new RuntimeException(); } - @Accessor("VIEW_OFFSET_Z_LAYERING") static RenderPhase.Layering VIEW_OFFSET_Z_LAYERING() { throw new RuntimeException(); } - @Accessor("ITEM_TARGET") static RenderPhase.Target ITEM_TARGET() { throw new RuntimeException(); } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ItemRendererMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ItemRendererMixin.java deleted file mode 100644 index 2cb5662..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ItemRendererMixin.java +++ /dev/null @@ -1,69 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.cititem; - -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.item.ItemModels; -import net.minecraft.client.render.item.ItemRenderer; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.render.model.json.ModelTransformation; -import net.minecraft.client.util.ModelIdentifier; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyVariable; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; -import shcm.shsupercm.fabric.citresewn.pack.cits.CITItem; - -import java.lang.ref.WeakReference; - -@Mixin(ItemRenderer.class) -public class ItemRendererMixin { - @Shadow @Final private ItemModels models; - - private static WeakReference<BakedModel> mojankCITModel = null; - - @Inject(method = "getModel", cancellable = true, at = @At("HEAD")) - private void getItemModel(ItemStack stack, World world, LivingEntity entity, int seed, CallbackInfoReturnable<BakedModel> cir) { - if (!CITResewnConfig.INSTANCE().enabled || CITResewn.INSTANCE.activeCITs == null) - return; - - BakedModel citModel = CITResewn.INSTANCE.activeCITs.getItemModelCached(stack, world == null ? MinecraftClient.getInstance().world : world, entity, seed); - if (citModel != null) - cir.setReturnValue(citModel); - } - - @Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformation$Mode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", at = @At("HEAD")) - private void fixMojankCITsContext(ItemStack stack, ModelTransformation.Mode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci) { - mojankCITModel = null; - if (((CITItem.Cached) (Object) stack).citresewn_isMojankCIT()) { - boolean bl = renderMode == ModelTransformation.Mode.GUI || renderMode == ModelTransformation.Mode.GROUND || renderMode == ModelTransformation.Mode.FIXED; - if (bl) - mojankCITModel = new WeakReference<>(model); - else { // rendered in hand model of trident/spyglass - if (stack.isOf(Items.TRIDENT)) - mojankCITModel = new WeakReference<>(this.models.getModelManager().getModel(new ModelIdentifier("minecraft:trident_in_hand#inventory"))); - else if (stack.isOf(Items.SPYGLASS)) - mojankCITModel = new WeakReference<>(this.models.getModelManager().getModel(new ModelIdentifier("minecraft:spyglass_in_hand#inventory"))); - } - } else - mojankCITModel = null; - } - - @ModifyVariable(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformation$Mode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", at = @At(value = "LOAD", ordinal = 0, target = "Lnet/minecraft/client/render/model/BakedModel;getTransformation()Lnet/minecraft/client/render/model/json/ModelTransformation;"), argsOnly = true) - private BakedModel fixMojankCITs(BakedModel original) { - if (mojankCITModel != null) - return mojankCITModel.get(); - - return original; - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ItemStackMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ItemStackMixin.java deleted file mode 100644 index 4c888d8..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ItemStackMixin.java +++ /dev/null @@ -1,40 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.cititem; - -import net.minecraft.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; -import shcm.shsupercm.fabric.citresewn.pack.cits.CITItem; - -import java.lang.ref.WeakReference; -import java.util.function.Supplier; - -@Mixin(ItemStack.class) -public class ItemStackMixin implements CITItem.Cached { - private WeakReference<CITItem> citresewn_cachedCITItem = new WeakReference<>(null); - private long citresewn_cacheTimeCITItem = 0; - - /** - * Used by tridents and spy glasses to force their unique overrides to be applied correctly - */ - private boolean citresewn_mojankCIT = false; - - @Override - public CITItem citresewn_getCachedCITItem(Supplier<CITItem> realtime) { - if (System.currentTimeMillis() - citresewn_cacheTimeCITItem >= CITResewnConfig.INSTANCE().cache_ms) { - citresewn_cachedCITItem = new WeakReference<>(realtime.get()); - citresewn_cacheTimeCITItem = System.currentTimeMillis(); - } - - return citresewn_cachedCITItem.get(); - } - - @Override - public boolean citresewn_isMojankCIT() { - return citresewn_mojankCIT; - } - - @Override - public void citresewn_setMojankCIT(boolean mojankCIT) { - citresewn_mojankCIT = mojankCIT; - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/JsonUnbakedModelAccessor.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/JsonUnbakedModelAccessor.java deleted file mode 100644 index f997d3e..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/JsonUnbakedModelAccessor.java +++ /dev/null @@ -1,22 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.cititem; - -import com.mojang.datafixers.util.Either; -import net.minecraft.client.render.model.json.JsonUnbakedModel; -import net.minecraft.client.util.SpriteIdentifier; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.Map; - -@Mixin(JsonUnbakedModel.class) -public interface JsonUnbakedModelAccessor { - @Accessor - Map<String, Either<SpriteIdentifier, String>> getTextureMap(); - - @Accessor - Identifier getParentId(); - - @Accessor - void setParentId(Identifier parentId); -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ModelLoaderMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ModelLoaderMixin.java deleted file mode 100644 index ec04910..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/cititem/ModelLoaderMixin.java +++ /dev/null @@ -1,165 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.cititem; - -import com.mojang.datafixers.util.Either; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.render.model.ModelLoader; -import net.minecraft.client.render.model.SpriteAtlasManager; -import net.minecraft.client.render.model.UnbakedModel; -import net.minecraft.client.render.model.json.JsonUnbakedModel; -import net.minecraft.client.render.model.json.ModelOverride; -import net.minecraft.client.texture.TextureManager; -import net.minecraft.client.util.ModelIdentifier; -import net.minecraft.client.util.SpriteIdentifier; -import net.minecraft.resource.Resource; -import net.minecraft.resource.ResourceManager; -import net.minecraft.util.Identifier; -import net.minecraft.util.profiler.Profiler; -import org.apache.commons.io.IOUtils; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.pack.ResewnItemModelIdentifier; -import shcm.shsupercm.fabric.citresewn.pack.ResewnTextureIdentifier; -import shcm.shsupercm.fabric.citresewn.pack.cits.CIT; -import shcm.shsupercm.fabric.citresewn.pack.cits.CITItem; - -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.stream.Collectors; - -import static shcm.shsupercm.fabric.citresewn.CITResewn.info; - -@Mixin(ModelLoader.class) -public class ModelLoaderMixin { - @Shadow @Final private ResourceManager resourceManager; - @Shadow @Final private Set<Identifier> modelsToLoad; - @Shadow @Final private Map<Identifier, UnbakedModel> modelsToBake; - @Shadow @Final private Map<Identifier, UnbakedModel> unbakedModels; - @Shadow @Final private Map<Identifier, BakedModel> bakedModels; - - @Inject(method = "addModel", at = @At("TAIL")) - public void addCITItemModels(ModelIdentifier eventModelId, CallbackInfo ci) { if (eventModelId != ModelLoader.MISSING_ID) return; - if (CITResewn.INSTANCE.activeCITs == null) - return; - - info("Loading CITItem models..."); - CITResewn.INSTANCE.activeCITs.citItems.values().stream() - .flatMap(Collection::stream) - .distinct() - .forEach(citItem -> { - try { - citItem.loadUnbakedAssets(resourceManager); - - for (JsonUnbakedModel unbakedModel : citItem.unbakedAssets.values()) { - ResewnItemModelIdentifier id = new ResewnItemModelIdentifier(unbakedModel.id); - this.unbakedModels.put(id, unbakedModel); - this.modelsToLoad.addAll(unbakedModel.getModelDependencies()); - this.modelsToBake.put(id, unbakedModel); - } - } catch (Exception e) { - CITResewn.logErrorLoading(e.getMessage()); - } - }); - - CITItem.GENERATED_SUB_CITS_SEEN.clear(); - } - - @Inject(method = "upload", at = @At("RETURN")) - public void linkBakedCITItemModels(TextureManager textureManager, Profiler profiler, CallbackInfoReturnable<SpriteAtlasManager> cir) { - if (CITResewn.INSTANCE.activeCITs == null) - return; - - profiler.push("citresewn_linking"); - info("Linking baked models to CITItems..."); - - if (CITResewn.INSTANCE.activeCITs != null) { - for (CITItem citItem : CITResewn.INSTANCE.activeCITs.citItems.values().stream().flatMap(Collection::stream).distinct().collect(Collectors.toList())) { - for (Map.Entry<List<ModelOverride.Condition>, JsonUnbakedModel> citModelEntry : citItem.unbakedAssets.entrySet()) { - if (citModelEntry.getKey() == null) { - citItem.bakedModel = this.bakedModels.get(new ResewnItemModelIdentifier(citModelEntry.getValue().id)); - } else { - BakedModel bakedModel = bakedModels.get(new ResewnItemModelIdentifier(citModelEntry.getValue().id)); - - if (bakedModel == null) - CITResewn.logWarnLoading("Skipping sub cit: Failed loading model for \"" + citModelEntry.getValue().id + "\" in " + citItem.pack.resourcePack.getName() + " -> " + citItem.propertiesIdentifier.getPath()); - else - citItem.bakedSubModels.override(citModelEntry.getKey(), bakedModel); - } - } - citItem.unbakedAssets = null; - } - } - - profiler.pop(); - } - - - @Inject(method = "loadModelFromJson", cancellable = true, at = @At("HEAD")) - public void 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)); - json.id = id.toString(); - json.id = json.id.substring(0, json.id.length() - 5); - - ((JsonUnbakedModelAccessor) json).getTextureMap().replaceAll((layer, original) -> { - Optional<SpriteIdentifier> left = original.left(); - if (left.isPresent()) { - String originalPath = left.get().getTextureId().getPath(); - String[] split = originalPath.split("/"); - if (originalPath.startsWith("./") || (split.length > 2 && split[1].equals("cit"))) { - Identifier resolvedIdentifier = CIT.resolvePath(id, originalPath, ".png", identifier -> resourceManager.containsResource(identifier)); - if (resolvedIdentifier != null) - return Either.left(new SpriteIdentifier(left.get().getAtlasId(), new ResewnTextureIdentifier(resolvedIdentifier))); - } - } - return original; - }); - - Identifier parentId = ((JsonUnbakedModelAccessor) json).getParentId(); - if (parentId != null) { - String[] parentIdPathSplit = parentId.getPath().split("/"); - if (parentId.getPath().startsWith("./") || (parentIdPathSplit.length > 2 && parentIdPathSplit[1].equals("cit"))) { - parentId = CIT.resolvePath(id, parentId.getPath(), ".json", identifier -> resourceManager.containsResource(identifier)); - if (parentId != null) - ((JsonUnbakedModelAccessor) json).setParentId(new ResewnItemModelIdentifier(parentId)); - } - } - - json.getOverrides().replaceAll(override -> { - String[] modelIdPathSplit = override.getModelId().getPath().split("/"); - if (override.getModelId().getPath().startsWith("./") || (modelIdPathSplit.length > 2 && modelIdPathSplit[1].equals("cit"))) { - Identifier resolvedOverridePath = CIT.resolvePath(id, override.getModelId().getPath(), ".json", identifier -> resourceManager.containsResource(identifier)); - if (resolvedOverridePath != null) - return new ModelOverride(new ResewnItemModelIdentifier(resolvedOverridePath), override.streamConditions().collect(Collectors.toList())); - } - - return override; - }); - - cir.setReturnValue(json); - } catch (Exception ignored) { - } finally { - IOUtils.closeQuietly(is, resource); - } - } - } - - @ModifyArg(method = "loadModelFromJson", at = - @At(value = "INVOKE", target = "Lnet/minecraft/resource/ResourceManager;getResource(Lnet/minecraft/util/Identifier;)Lnet/minecraft/resource/Resource;")) - public Identifier fixDuplicatePrefixSuffix(Identifier original) { - if (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)); - - return original; - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/ChatScreenMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/ChatScreenMixin.java deleted file mode 100644 index cdd9eb1..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/ChatScreenMixin.java +++ /dev/null @@ -1,23 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.core; - -import net.minecraft.client.gui.screen.ChatScreen; -import net.minecraft.client.gui.screen.Screen; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArg; -import shcm.shsupercm.fabric.citresewn.OptionalCompat; - -import static shcm.shsupercm.fabric.citresewn.CITResewnCommand.openConfig; - -@Mixin(ChatScreen.class) -public class ChatScreenMixin { - @ModifyArg(method = "keyPressed", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/MinecraftClient;setScreen(Lnet/minecraft/client/gui/screen/Screen;)V")) - public Screen redirectConfigScreen(Screen original) { - if (original == null && openConfig) { - openConfig = false; - return OptionalCompat.getModConfigScreenFactory().apply(null); - } - - return original; - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/GroupResourcePackAccessor.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/GroupResourcePackAccessor.java deleted file mode 100644 index 7ab1c16..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/GroupResourcePackAccessor.java +++ /dev/null @@ -1,14 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.core; - -import net.fabricmc.fabric.api.resource.ModResourcePack; -import net.fabricmc.fabric.impl.resource.loader.GroupResourcePack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.List; - -/* if (FabricLoader.getInstance().isModLoaded("fabric-resource-loader-v0")) */ @Mixin(GroupResourcePack.class) -public interface GroupResourcePackAccessor { - @Accessor - List<ModResourcePack> getPacks(); -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/ModelLoaderMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/ModelLoaderMixin.java deleted file mode 100644 index d65ffb8..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/ModelLoaderMixin.java +++ /dev/null @@ -1,51 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.core; - -import net.minecraft.client.render.model.ModelLoader; -import net.minecraft.client.util.ModelIdentifier; -import net.minecraft.resource.ResourceManager; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import shcm.shsupercm.fabric.citresewn.ActiveCITs; -import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; -import shcm.shsupercm.fabric.citresewn.pack.CITPack; -import shcm.shsupercm.fabric.citresewn.pack.CITParser; -import shcm.shsupercm.fabric.citresewn.pack.cits.CIT; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - -import static shcm.shsupercm.fabric.citresewn.CITResewn.info; - -@Mixin(value = ModelLoader.class, priority = 999) -public abstract class ModelLoaderMixin { - @Shadow @Final private ResourceManager resourceManager; - - @Inject(method = "addModel", at = @At("TAIL")) - public void initCITs(ModelIdentifier eventModelId, CallbackInfo ci) { if (eventModelId != ModelLoader.MISSING_ID) return; - if (CITResewn.INSTANCE.activeCITs != null) { - info("Clearing active CITs.."); - CITResewn.INSTANCE.activeCITs.dispose(); - CITResewn.INSTANCE.activeCITs = null; - } - - if (!CITResewnConfig.INSTANCE().enabled) - return; - - info("Parsing CITs..."); - List<CITPack> parsedPacks = CITParser.parseCITs(resourceManager.streamResourcePacks().collect(Collectors.toCollection(ArrayList::new))); - List<CIT> parsed = parsedPacks.stream().flatMap(pack -> pack.cits.stream()).collect(Collectors.toCollection(ArrayList::new)); - - if (parsed.size() > 0) { - info("Activating CITs..."); - CITResewn.INSTANCE.activeCITs = new ActiveCITs(parsedPacks, parsed); - } else - info("No cit packs found."); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/NbtCompoundAccessor.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/NbtCompoundAccessor.java deleted file mode 100644 index 8ced305..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/NbtCompoundAccessor.java +++ /dev/null @@ -1,14 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.core; - -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtElement; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -import java.util.Map; - -@Mixin(NbtCompound.class) -public interface NbtCompoundAccessor { - @Accessor - Map<String, NbtElement> getEntries(); -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/SpriteAtlasTextureMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/SpriteAtlasTextureMixin.java deleted file mode 100644 index 8cc195b..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/SpriteAtlasTextureMixin.java +++ /dev/null @@ -1,18 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.core; - -import net.minecraft.client.texture.SpriteAtlasTexture; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import shcm.shsupercm.fabric.citresewn.pack.ResewnTextureIdentifier; - -@Mixin(SpriteAtlasTexture.class) -public class SpriteAtlasTextureMixin { - @Inject(method = "getTexturePath", cancellable = true, at = @At("HEAD")) - public void forceLiteralResewnTextureIdentifier(Identifier id, CallbackInfoReturnable<Identifier> cir) { - if (id instanceof ResewnTextureIdentifier) - cir.setReturnValue(id); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/ZipResourcePackMixin.java b/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/ZipResourcePackMixin.java deleted file mode 100644 index 7acbcb7..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/mixin/core/ZipResourcePackMixin.java +++ /dev/null @@ -1,60 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.mixin.core; - -import com.google.common.collect.Lists; -import net.minecraft.resource.ResourceType; -import net.minecraft.resource.ZipResourcePack; -import net.minecraft.util.Identifier; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; - -import java.io.IOException; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; -import java.util.function.Predicate; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -@Mixin(ZipResourcePack.class) -public abstract class ZipResourcePackMixin { - @Shadow protected abstract ZipFile getZipFile() throws IOException; - - @Inject(method = "findResources", cancellable = true, at = @At("HEAD")) - public void fixDepthBug(ResourceType type, String namespace, String prefix, int maxDepth, Predicate<String> pathFilter, CallbackInfoReturnable<Collection<Identifier>> cir) { - if (maxDepth != Integer.MAX_VALUE - 53) - return; - - ZipFile zipFile2; - try { - zipFile2 = this.getZipFile(); - } catch (IOException var15) { - cir.setReturnValue(Collections.emptySet()); return; - } - - Enumeration<? extends ZipEntry> enumeration = zipFile2.entries(); - List<Identifier> list = Lists.newArrayList(); - String var10000 = type.getDirectory(); - String string = var10000 + "/" + namespace + "/"; - String string2 = string + prefix + "/"; - - while(enumeration.hasMoreElements()) { - ZipEntry zipEntry = enumeration.nextElement(); - if (!zipEntry.isDirectory()) { - String string3 = zipEntry.getName(); - if (!string3.endsWith(".mcmeta") && string3.startsWith(string2)) { - String string4 = string3.substring(string.length()); - String[] strings = string4.split("/"); - if (pathFilter.test(strings[strings.length - 1])) { - list.add(new Identifier(namespace, string4)); - } - } - } - } - - cir.setReturnValue(list); return; - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java deleted file mode 100644 index aadf518..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITPack.java +++ /dev/null @@ -1,65 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack; - -import net.minecraft.resource.ResourcePack; -import shcm.shsupercm.fabric.citresewn.pack.cits.CIT; -import shcm.shsupercm.fabric.citresewn.pack.cits.CITEnchantment; - -import java.util.*; - -public class CITPack { - public final ResourcePack resourcePack; - public final Collection<CIT> cits = new ArrayList<>(); - - public CITEnchantment.MergeMethod method = CITEnchantment.MergeMethod.AVERAGE; - public Integer cap = 8; - public Float fade = 0.5f; - public Boolean useGlint = true; - - public CITPack(ResourcePack resourcePack) { - this.resourcePack = resourcePack; - } - - public void loadGlobalProperties(Properties properties) throws Exception { - try { - this.method = properties.containsKey("method") ? CITEnchantment.MergeMethod.valueOf(properties.getProperty("method").toUpperCase(Locale.ENGLISH)) : null; - - if (properties.containsKey("cap")) { - this.cap = Integer.parseInt(properties.getProperty("cap")); - if (this.cap < 0) - throw new Exception("cap cannot be negative"); - } else - this.cap = null; - - if (properties.containsKey("fade")) { - this.fade = Float.parseFloat(properties.getProperty("fade")); - if (this.fade < 0f) - throw new Exception("fade cannot be negative"); - } else - this.fade = null; - - this.useGlint = properties.containsKey("useGlint") ? switch (properties.getProperty("useGlint").toLowerCase(Locale.ENGLISH)) { - case "true" -> true; - case "false" -> false; - default -> throw new Exception("useGlint is not a boolean"); - } : null; - } catch (Exception e) { - this.method = null; - this.cap = null; - this.fade = null; - this.useGlint = null; - throw e; - } - } - - public void loadGlobalProperties(CITPack properties) { - if (properties.method != null) - this.method = properties.method; - if (properties.cap != null) - this.cap = properties.cap; - if (properties.fade != null) - this.fade = properties.fade; - if (properties.useGlint != null) - this.useGlint = properties.useGlint; - } - -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java deleted file mode 100644 index 974d2ec..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java +++ /dev/null @@ -1,119 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack; - -import net.fabricmc.fabric.impl.resource.loader.GroupResourcePack; -import net.minecraft.resource.ResourcePack; -import net.minecraft.resource.ResourceType; -import net.minecraft.util.Identifier; -import org.apache.commons.lang3.StringUtils; -import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.ex.CITParseException; -import shcm.shsupercm.fabric.citresewn.mixin.core.GroupResourcePackAccessor; -import shcm.shsupercm.fabric.citresewn.pack.cits.*; - -import java.io.InputStream; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -/** - * Parses cits from resourcepacks - */ -public final class CITParser { private CITParser() {} - /** - * CIT type registry. - */ - public static final Map<String, CITConstructor> REGISTRY = new HashMap<>(); - static { - REGISTRY.put("item", CITItem::new); - REGISTRY.put("armor", CITArmor::new); - REGISTRY.put("elytra", CITElytra::new); - REGISTRY.put("enchantment", CITEnchantment::new); - } - - /** - * Parses cit entries from an ordered collection of resourcepacks. - * @param packs packs to parse - * @return a collection of parsed CITs - */ - public static List<CITPack> parseCITs(Collection<ResourcePack> packs) { - return packs.stream() - .map(CITParser::parse) - .flatMap(Collection::stream) - .collect(Collectors.toList()); - } - - /** - * Parses a resourcepack into a possible collection of citpacks that are contained within. - * @param resourcePack pack to parse - * @return a collection of CITPacks or an empty collection if resourcepack contains none - */ - public static Collection<CITPack> parse(ResourcePack resourcePack) { - if (resourcePack instanceof GroupResourcePack) - return ((GroupResourcePackAccessor) resourcePack).getPacks().stream() - .map(CITParser::parse) - .flatMap(Collection::stream) - .collect(Collectors.toList()); - - final CITPack citPack = new CITPack(resourcePack); - - Collection<Identifier> packProperties = new ArrayList<>(); - for (String namespace : resourcePack.getNamespaces(ResourceType.CLIENT_RESOURCES)) - if (Identifier.isValid(namespace)) - for (String citRoot : new String[] { "citresewn", "optifine", "mcpatcher" }) { - packProperties.addAll(resourcePack.findResources(ResourceType.CLIENT_RESOURCES, namespace, citRoot + "/cit", Integer.MAX_VALUE - 53, s -> s.endsWith(".properties"))); - Identifier global = new Identifier(namespace, citRoot + "/cit.properties"); - if (resourcePack.contains(ResourceType.CLIENT_RESOURCES, global)) - packProperties.add(global); - } - - boolean readGlobalProperties = false; - for (Iterator<Identifier> iterator = packProperties.iterator(); iterator.hasNext(); ) { - Identifier propertiesIdentifier = iterator.next(); - try { - if (StringUtils.countMatches(propertiesIdentifier.getPath(), '/') <= 2 && propertiesIdentifier.getPath().endsWith("cit.properties")) { - iterator.remove(); - if (!readGlobalProperties) - try (InputStream is = resourcePack.open(ResourceType.CLIENT_RESOURCES, propertiesIdentifier)) { - Properties citProperties = new Properties(); - citProperties.load(is); - citPack.loadGlobalProperties(citProperties); - readGlobalProperties = true; - } - } - } catch (Exception e) { - CITResewn.logErrorLoading("Skipped global properties: " + e.getMessage() + " in " + resourcePack.getName() + " -> " + propertiesIdentifier); - } - } - - packProperties.stream() - .flatMap(citIdentifier -> { - try (InputStream is = resourcePack.open(ResourceType.CLIENT_RESOURCES, citIdentifier)) { - Properties citProperties = new Properties(); - citProperties.load(new InputStreamReader(is, StandardCharsets.UTF_8)); - - CITConstructor type = REGISTRY.get(citProperties.getProperty("type", "item")); - if (type == null) - throw new CITParseException(citPack.resourcePack, citIdentifier, "Unknown cit type \"" + citProperties.getProperty("type") + "\""); - - return Stream.of(type.cit(citPack, citIdentifier, citProperties)); - } catch (Exception e) { - CITResewn.logErrorLoading(e.getMessage()); - return Stream.empty(); - } - }) - .collect(Collectors.toCollection(() -> citPack.cits)); - - if (citPack.cits.isEmpty()) - return Collections.emptySet(); - else { - CITResewn.info("Found " + citPack.cits.size() + " CIT" + (citPack.cits.size() == 1 ? "" : "s") + " in " + resourcePack.getName()); - return Collections.singleton(citPack); - } - } - - public interface CITConstructor { - CIT cit(CITPack pack, Identifier identifier, Properties properties) throws CITParseException; - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ResewnItemModelIdentifier.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ResewnItemModelIdentifier.java deleted file mode 100644 index c531983..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ResewnItemModelIdentifier.java +++ /dev/null @@ -1,18 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack; - -import net.minecraft.util.Identifier; -import shcm.shsupercm.fabric.citresewn.mixin.core.ModelLoaderMixin; - -/** - * Marks models as cit item models. - * @see ModelLoaderMixin - */ -public class ResewnItemModelIdentifier extends Identifier { - public ResewnItemModelIdentifier(String id) { - super(id); - } - - public ResewnItemModelIdentifier(Identifier identifier) { - super(identifier.getNamespace(), identifier.getPath()); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ResewnTextureIdentifier.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ResewnTextureIdentifier.java deleted file mode 100644 index 033c567..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/ResewnTextureIdentifier.java +++ /dev/null @@ -1,14 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack; - -import net.minecraft.util.Identifier; -import shcm.shsupercm.fabric.citresewn.mixin.core.SpriteAtlasTextureMixin; - -/** - * Marks path identifiers as forced literal texture paths. - * @see SpriteAtlasTextureMixin - */ -public class ResewnTextureIdentifier extends Identifier { - public ResewnTextureIdentifier(Identifier identifier) { - super(identifier.getNamespace(), identifier.getPath()); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java deleted file mode 100644 index a58c946..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CIT.java +++ /dev/null @@ -1,435 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack.cits; - -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.EnchantedBookItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.nbt.*; -import net.minecraft.text.Text; -import net.minecraft.util.Hand; -import net.minecraft.util.Identifier; -import net.minecraft.util.Pair; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.World; -import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.ex.CITParseException; -import shcm.shsupercm.fabric.citresewn.mixin.core.NbtCompoundAccessor; -import shcm.shsupercm.fabric.citresewn.pack.CITPack; - -import java.util.*; -import java.util.function.Predicate; -import java.util.regex.Pattern; - -public abstract class CIT { - public final CITPack pack; - public final Identifier propertiesIdentifier; - - public final Set<Item> items = new HashSet<>(); - - public final int damageMin, damageMax; - public final boolean damageAny, damageRange, damagePercentage; - public final Integer damageMask; - - public final int stackMin, stackMax; - public final boolean stackAny, stackRange; - - public final Set<Identifier> enchantments = new HashSet<>(); - public final List<Pair<Integer, Integer>> enchantmentLevels = new ArrayList<>(); - public final boolean enchantmentsAny, enchantmentLevelsAny; - - public final Hand hand; - - public final Predicate<NbtCompound> nbt; - - public final int weight; - - public CIT(CITPack pack, Identifier identifier, Properties properties) throws CITParseException { - this.pack = pack; - this.propertiesIdentifier = identifier; - try { - for (String itemId : (properties.getProperty("items", properties.getProperty("matchItems", " "))).split(" ")) - if (!itemId.isEmpty()) { - Identifier itemIdentifier = new Identifier(itemId); - if (!Registry.ITEM.containsId(itemIdentifier)) - throw new Exception("Unknown item " + itemId); - this.items.add(Registry.ITEM.get(itemIdentifier)); - } - if (this.items.isEmpty()) - try { - String id = propertiesIdentifier.getPath().substring(0, propertiesIdentifier.getPath().length() - 11); - String[] split = id.split("/"); - id = split[split.length - 1]; - Identifier itemId = new Identifier(propertiesIdentifier.getNamespace(), id); - if (Registry.ITEM.containsId(itemId)) - this.items.add(Registry.ITEM.get(itemId)); - } catch (Exception ignored) { } - - String damage = properties.getProperty("damage"); - if (damageAny = damage == null) { - this.damageRange = false; - this.damagePercentage = false; - this.damageMin = 0; - this.damageMax = 0; - } else { - if (this.damagePercentage = damage.contains("%")) - damage = damage.replace("%", ""); - - if (damage.contains("-")) { - String[] split = damage.split("-"); - if (split.length > 2) - throw new Exception("damage range must have up to 2 numbers"); - - this.damageMin = split[0].isEmpty() ? Integer.MIN_VALUE : Integer.parseInt(split[0]); - this.damageMax = split.length == 1 ? Integer.MAX_VALUE : Integer.parseInt(split[1]); - - if (this.damageMin > this.damageMax) - throw new Exception("damage range min is higher than max"); - - this.damageRange = this.damageMin < this.damageMax; - } else { - this.damageRange = false; - this.damageMin = this.damageMax = Integer.parseInt(damage); - } - } - - this.damageMask = properties.containsKey("damageMask") ? Integer.parseInt(properties.getProperty("damageMask")) : null; - - String stackSize = properties.getProperty("stackSize"); - if (stackAny = stackSize == null) { - this.stackRange = false; - this.stackMin = 0; - this.stackMax = 0; - } else { - if (stackSize.contains("-")) { - String[] split = stackSize.split("-"); - if (split.length > 2) - throw new Exception("stackSize range must have up to 2 numbers"); - - this.stackMin = split[0].isEmpty() ? Integer.MIN_VALUE : Integer.parseInt(split[0]); - this.stackMax = split.length == 1 ? Integer.MAX_VALUE : Integer.parseInt(split[1]); - - if (this.stackMin > this.stackMax) - throw new Exception("stackSize range min is higher than max"); - - this.stackRange = this.stackMin < this.stackMax; - } else { - this.stackRange = false; - this.stackMin = this.stackMax = Integer.parseInt(stackSize); - } - } - - String enchantmentIDs = properties.getProperty("enchantments", properties.getProperty("enchantmentIDs")); - if (!(this.enchantmentsAny = enchantmentIDs == null)) { - for (String ench : enchantmentIDs.split(" ")) { - Identifier enchIdentifier = new Identifier(ench); - if (!Registry.ENCHANTMENT.containsId(enchIdentifier)) - CITResewn.logWarnLoading("CIT Warning: Unknown enchantment " + enchIdentifier); - this.enchantments.add(enchIdentifier); - } - } - - String enchantmentLevelsProp = properties.getProperty("enchantmentLevels"); - if (!(this.enchantmentLevelsAny = enchantmentLevelsProp == null)) { - for (String range : enchantmentLevelsProp.split(" ")) { - if (range.contains("-")) { - if (range.startsWith("-")) { - range = range.substring(1); - if (range.contains("-")) - throw new Exception("enchantmentLevels ranges must have up to 2 numbers each"); - this.enchantmentLevels.add(new Pair<>(0, Integer.parseInt(range))); - } else if (range.endsWith("-")) { - range = range.substring(0, range.length() - 1); - if (range.contains("-")) - throw new Exception("enchantmentLevels ranges must have up to 2 numbers each"); - this.enchantmentLevels.add(new Pair<>(Integer.parseInt(range), Integer.MAX_VALUE)); - } else { - String[] split = range.split("-"); - if (split.length != 2) - throw new Exception("enchantmentLevels ranges must have up to 2 numbers each"); - Pair<Integer, Integer> minMaxPair = new Pair<>(Integer.parseInt(split[0]), Integer.parseInt(split[1])); - if (minMaxPair.getLeft() > minMaxPair.getRight()) - throw new Exception("enchantmentLevels range min is higher than max"); - this.enchantmentLevels.add(minMaxPair); - } - } else { - int level = Integer.parseInt(range); - this.enchantmentLevels.add(new Pair<>(level, level)); - } - } - } - - this.hand = switch (properties.getProperty("hand", "any")) { - case "main" -> Hand.MAIN_HAND; - case "off" -> Hand.OFF_HAND; - default -> null; - }; - - List<Predicate<NbtCompound>> nbtPredicates = new ArrayList<>(); - for (Object o : properties.keySet()) - if (o instanceof String property && property.startsWith("nbt.")) { - String matchProperty = properties.getProperty(property); - final String[] path = property.substring(4).split("\\."); - final Predicate<String> match; - final boolean caseSensitive = !matchProperty.startsWith("i"); - - if (matchProperty.startsWith(caseSensitive ? "pattern:" : "ipattern:")) { - matchProperty = caseSensitive ? matchProperty.substring(8) : matchProperty.substring(9).toLowerCase(Locale.ENGLISH); - final String pattern = matchProperty; - match = s -> matchesPattern(caseSensitive ? s : s.toLowerCase(), pattern, 0, s.length(), 0, pattern.length()); - } else if (matchProperty.startsWith(caseSensitive ? "regex:" : "iregex:")) { - matchProperty = caseSensitive ? matchProperty.substring(6) : matchProperty.substring(7).toLowerCase(Locale.ENGLISH); - final Pattern pattern = Pattern.compile(matchProperty); - match = s -> pattern.matcher(caseSensitive ? s : s.toLowerCase()).matches(); - } else { - if (property.equals("nbt.display.color") && matchProperty.startsWith("#")) - try { - matchProperty = String.valueOf(Integer.parseInt(matchProperty.substring(1).toLowerCase(Locale.ENGLISH), 16)); - } catch (Exception ignored) { } - - final String pattern = matchProperty; - match = s -> s.equals(pattern); - } - - final boolean checkJson = (path[path.length - 1].equals("Name") || (path.length >= 2 && path[path.length - 2].equals("Lore"))) && !((matchProperty.startsWith("{") || matchProperty.startsWith("\\{")) && matchProperty.endsWith("}")); - - nbtPredicates.add(new Predicate<NbtCompound>() { - public boolean test(NbtElement nbtElement, int index) { - if (index >= path.length) { - if (nbtElement instanceof NbtString nbtString) { - String text = nbtString.asString(); - if (checkJson) - try { - //noinspection ConstantConditions - text = Text.Serializer.fromJson(text).getString(); - } catch (Exception ignored) { } - - return match.test(text); - } else if (nbtElement instanceof AbstractNbtNumber nbtNumber) - return match.test(String.valueOf(nbtNumber.numberValue())); - } else { - String name = path[index]; - if (name.equals("*")) { - if (nbtElement instanceof NbtCompound nbtCompound) { - for (NbtElement subElement : ((NbtCompoundAccessor) nbtCompound).getEntries().values()) - if (test(subElement, index + 1)) - return true; - } else if (nbtElement instanceof NbtList nbtList) { - for (NbtElement subElement : nbtList) - if (test(subElement, index + 1)) - return true; - } - } else { - if (nbtElement instanceof NbtCompound nbtCompound) { - NbtElement subElement = nbtCompound.get(name); - return subElement != null && test(subElement, index + 1); - } else if (nbtElement instanceof NbtList nbtList) { - try { - NbtElement subElement = nbtList.get(Integer.parseInt(name)); - return subElement != null && test(subElement, index + 1); - } catch (Exception ignored) { - return false; - } - } - } - } - return false; - } - - @Override - public boolean test(NbtCompound nbtCompound) { - return test(nbtCompound, 0); - } - }); - } - this.nbt = nbtCompound -> { - for (Predicate<NbtCompound> predicate : nbtPredicates) - if(!predicate.test(nbtCompound)) - return false; - return true; - }; - - this.weight = Integer.parseInt(properties.getProperty("weight", "0")); - } catch (Exception e) { - throw new CITParseException(pack.resourcePack, identifier, (e.getClass() == Exception.class ? "" : e.getClass().getSimpleName() + ": ") + e.getMessage()); - } - } - - public boolean test(ItemStack stack, Hand hand, World world, LivingEntity entity, boolean ignoreItemType) { - if (!ignoreItemType && !items.isEmpty() && !items.contains(stack.getItem())) - return false; - - if (!damageAny && stack.getItem().isDamageable()) { - int damage = stack.getDamage(); - if (damageMask != null) - damage &= damageMask; - if (damagePercentage) - damage = Math.round(100f * (float) stack.getDamage() / (float) stack.getMaxDamage()); - if (damageRange ? (damage < damageMin || damage > damageMax) : (damage != damageMin)) - return false; - } - - if (!stackAny) { - int count = stack.getCount(); - if (stackRange ? (count < stackMin || count > stackMax) : (count != stackMin)) - return false; - } - - if (this.hand != null && this.hand != hand) - return false; - - if (!enchantmentsAny) { - Map<Identifier, Integer> stackEnchantments = new LinkedHashMap<>(); - for (NbtElement nbtElement : stack.isOf(Items.ENCHANTED_BOOK) ? EnchantedBookItem.getEnchantmentNbt(stack) : stack.getEnchantments()) - stackEnchantments.put(EnchantmentHelper.getIdFromNbt((NbtCompound) nbtElement), EnchantmentHelper.getLevelFromNbt((NbtCompound) nbtElement)); - - boolean matches = false; - for (Identifier enchantment : enchantments) { - Integer level = stackEnchantments.get(enchantment); - if (level != null) - if (enchantmentLevelsAny) { - if (level > 0) { - matches = true; - break; - } - } else - for (Pair<Integer, Integer> levelRange : enchantmentLevels) - if (level >= levelRange.getLeft() && level <= levelRange.getRight()) { - matches = true; - break; - } - } - - if (!matches) - return false; - } else if (!enchantmentLevelsAny) { - Collection<Integer> levels = new ArrayList<>(); - levels.add(0); - for (NbtElement nbtElement : stack.isOf(Items.ENCHANTED_BOOK) ? EnchantedBookItem.getEnchantmentNbt(stack) : stack.getEnchantments()) - levels.add(EnchantmentHelper.getLevelFromNbt((NbtCompound) nbtElement)); - - boolean matches = false; - - l: for (Integer level : levels) { - for (Pair<Integer, Integer> levelRange : enchantmentLevels) { - if (level >= levelRange.getLeft() && level <= levelRange.getRight()) { - matches = true; - break l; - } - } - } - - if (!matches) - return false; - } - - return nbt == null || nbt.test(stack.getNbt()); - } - - public void dispose() { - //stub - } - - /** - * Takes a defined path and resolves it to an identifier pointing to the resourcepack's path of the specified extension(returns null if no path can be resolved).<br> - * If definedPath is null, will try to resolve a relative file with the same name as the propertyIdentifier with the extension, otherwise: <br> - * definedPath will be formatted to replace "\\" with "/" the extension will be appended if not there already. <br> - * It will first try using definedPath as an absolute path, if it cant resolve(or definedPath starts with ./), definedPath will be considered relative. <br> - * Relative paths support going to parent directories using "..". - */ - public static Identifier resolvePath(Identifier propertyIdentifier, String path, String extension, Predicate<Identifier> packContains) { - if (path == null) { - path = propertyIdentifier.getPath().substring(0, propertyIdentifier.getPath().length() - 11); - if (!path.endsWith(extension)) - path = path + extension; - Identifier pathIdentifier = new Identifier(propertyIdentifier.getNamespace(), path); - return packContains.test(pathIdentifier) ? pathIdentifier : null; - } - - Identifier pathIdentifier = new Identifier(path); - - path = pathIdentifier.getPath().replace('\\', '/'); - if (!path.endsWith(extension)) - path = path + extension; - - if (path.startsWith("./")) - path = path.substring(2); - else if (!path.contains("..")) { - pathIdentifier = new Identifier(pathIdentifier.getNamespace(), path); - if (packContains.test(pathIdentifier)) - return pathIdentifier; - else if (path.startsWith("assets/")) { - path = path.substring(7); - int sep = path.indexOf('/'); - pathIdentifier = new Identifier(path.substring(0, sep), path.substring(sep + 1)); - if (packContains.test(pathIdentifier)) - return pathIdentifier; - } - pathIdentifier = new Identifier(pathIdentifier.getNamespace(), switch (extension) { - case ".png" -> "textures/"; - case ".json" -> "models/"; - - /* UNREACHABLE FAILSAFE */ - default -> ""; - } + path); - if (packContains.test(pathIdentifier)) - return pathIdentifier; - } - - LinkedList<String> pathParts = new LinkedList<>(Arrays.asList(propertyIdentifier.getPath().split("/"))); - pathParts.removeLast(); - - if (path.contains("/")) { - for (String part : path.split("/")) { - if (part.equals("..")) { - if (pathParts.size() == 0) - return null; - pathParts.removeLast(); - } else - pathParts.addLast(part); - } - } else - pathParts.addLast(path); - path = String.join("/", pathParts); - - pathIdentifier = new Identifier(propertyIdentifier.getNamespace(), path); - - return packContains.test(pathIdentifier) ? pathIdentifier : null; - } - - /** - * Author: Paul "prupe" Rupe<br> - * Taken from MCPatcher under public domain licensing.<br> - * https://bitbucket.org/prupe/mcpatcher/src/1aa45839b2cd029143809edfa60ec59e5ef75f80/newcode/src/com/prupe/mcpatcher/mal/nbt/NBTRule.java#lines-269:301 - */ - public static boolean matchesPattern(String value, String pattern, int curV, int maxV, int curG, int maxG) { - for (; curG < maxG; curG++, curV++) { - char g = pattern.charAt(curG); - if (g == '*') { - while (true) { - if (matchesPattern(value, pattern, curV, maxV, curG + 1, maxG)) { - return true; - } - if (curV >= maxV) { - break; - } - curV++; - } - return false; - } else if (curV >= maxV) { - break; - } else if (g == '?') { - continue; - } - if (g == '\\' && curG + 1 < maxG) { - curG++; - g = pattern.charAt(curG); - } - - if (g != value.charAt(curV)) - return false; - } - return curG == maxG && curV == maxV; - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITArmor.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITArmor.java deleted file mode 100644 index e919a86..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITArmor.java +++ /dev/null @@ -1,42 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack.cits; - -import net.minecraft.item.ArmorItem; -import net.minecraft.item.Item; -import net.minecraft.resource.ResourceType; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; -import shcm.shsupercm.fabric.citresewn.ex.CITParseException; -import shcm.shsupercm.fabric.citresewn.pack.CITPack; - -import java.util.*; -import java.util.function.Supplier; - -public class CITArmor extends CIT { - public final Map<String, Identifier> textures = new HashMap<>(); - - public CITArmor(CITPack pack, Identifier identifier, Properties properties) throws CITParseException { - super(pack, identifier, properties); - try { - if (this.items.size() == 0) - throw new Exception("CIT must target at least one item type"); - for (Item item : this.items) - if (!(item instanceof ArmorItem)) - throw new Exception("Armor CIT must target armor items only(" + Registry.ITEM.getId(item) + " is not armor)"); - - for (Object o : properties.keySet()) - if (o instanceof String property && property.startsWith("texture.")) { - Identifier textureIdentifier = resolvePath(identifier, properties.getProperty(property), ".png", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id)); - if (textureIdentifier == null) - throw new Exception("Cannot resolve path for " + property); - - this.textures.put(property.substring(8), textureIdentifier); - } - } catch (Exception e) { - throw new CITParseException(pack.resourcePack, identifier, (e.getClass() == Exception.class ? "" : e.getClass().getSimpleName() + ": ") + e.getMessage()); - } - } - - public interface Cached { - CITArmor citresewn_getCachedCITArmor(Supplier<CITArmor> realtime); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java deleted file mode 100644 index 5c9aa1a..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITElytra.java +++ /dev/null @@ -1,28 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack.cits; - -import net.minecraft.resource.ResourceType; -import net.minecraft.util.Identifier; -import shcm.shsupercm.fabric.citresewn.ex.CITParseException; -import shcm.shsupercm.fabric.citresewn.pack.CITPack; - -import java.util.Properties; -import java.util.function.Supplier; - -public class CITElytra extends CIT { - public final Identifier textureIdentifier; - - public CITElytra(CITPack pack, Identifier identifier, Properties properties) throws CITParseException { - super(pack, identifier, properties); - try { - textureIdentifier = resolvePath(identifier, properties.getProperty("texture"), ".png", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id)); - if (textureIdentifier == null) - throw new Exception("Cannot resolve texture"); - } catch (Exception e) { - throw new CITParseException(pack.resourcePack, identifier, (e.getClass() == Exception.class ? "" : e.getClass().getSimpleName() + ": ") + e.getMessage()); - } - } - - public interface Cached { - CITElytra citresewn_getCachedCITElytra(Supplier<CITElytra> realtime); - } -} diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java deleted file mode 100644 index 7c4fa94..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITEnchantment.java +++ /dev/null @@ -1,371 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack.cits; - -import com.mojang.blaze3d.systems.RenderSystem; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.render.*; -import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.item.EnchantedBookItem; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtElement; -import net.minecraft.resource.ResourceType; -import net.minecraft.util.Identifier; -import net.minecraft.util.Util; -import net.minecraft.util.math.Matrix4f; -import net.minecraft.util.math.Vec3f; -import org.lwjgl.opengl.GL11; -import shcm.shsupercm.fabric.citresewn.config.CITResewnConfig; -import shcm.shsupercm.fabric.citresewn.ex.CITParseException; -import shcm.shsupercm.fabric.citresewn.mixin.citenchantment.BufferBuilderStorageAccessor; -import shcm.shsupercm.fabric.citresewn.mixin.citenchantment.RenderPhaseAccessor; -import shcm.shsupercm.fabric.citresewn.pack.CITPack; - -import java.util.*; -import java.util.function.Consumer; -import java.util.function.Supplier; - -import static org.lwjgl.opengl.GL11.*; -import static com.mojang.blaze3d.systems.RenderSystem.*; -import static shcm.shsupercm.util.logic.Loops.statelessFadingLoop; - -public class CITEnchantment extends CIT { - public static List<CITEnchantment> appliedContext = null; - public static boolean shouldApply = false; - - public final Identifier textureIdentifier; - public final float speed, rotation, duration, r, g, b, a; - public final int layer; - public final boolean useGlint, blur; - public final Blend blend; - - private final WrappedMethodIntensity methodIntensity = new WrappedMethodIntensity(); - - public final Map<GlintRenderLayer, RenderLayer> renderLayers = new EnumMap<>(GlintRenderLayer.class); - - public CITEnchantment(CITPack pack, Identifier identifier, Properties properties) throws CITParseException { - super(pack, identifier, properties); - try { - textureIdentifier = resolvePath(identifier, properties.getProperty("texture"), ".png", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id)); - if (textureIdentifier == null) - throw new Exception("Cannot resolve texture"); - - speed = Float.parseFloat(properties.getProperty("speed", "1")); - - rotation = Float.parseFloat(properties.getProperty("rotation", "0")); - - duration = Float.max(0f, Float.parseFloat(properties.getProperty("duration", "0"))); - - layer = Integer.parseInt(properties.getProperty("layer", "0")); - - r = Math.max(0f, Float.parseFloat(properties.getProperty("r", "1"))); - g = Math.max(0f, Float.parseFloat(properties.getProperty("g", "1"))); - b = Math.max(0f, Float.parseFloat(properties.getProperty("b", "1"))); - a = Math.max(0f, Float.parseFloat(properties.getProperty("a", "1"))); - - useGlint = switch (properties.getProperty("useGlint", "false").toLowerCase(Locale.ENGLISH)) { - case "true" -> true; - case "false" -> false; - default -> throw new Exception("useGlint is not a boolean"); - }; - - blur = switch (properties.getProperty("blur", "true").toLowerCase(Locale.ENGLISH)) { - case "true" -> true; - case "false" -> false; - default -> throw new Exception("blur is not a boolean"); - }; - - blend = Blend.getBlend(properties.getProperty("blend", "add")); - } catch (Exception e) { - throw new CITParseException(pack.resourcePack, identifier, (e.getClass() == Exception.class ? "" : e.getClass().getSimpleName() + ": ") + e.getMessage()); - } - } - - public void activate() { - for (GlintRenderLayer glintLayer : GlintRenderLayer.values()) { - RenderLayer renderLayer = glintLayer.build(this); - - renderLayers.put(glintLayer, renderLayer); - ((BufferBuilderStorageAccessor) MinecraftClient.getInstance().getBufferBuilders()).entityBuilders().put(renderLayer, new BufferBuilder(renderLayer.getExpectedBufferSize())); - } - } - - @Override - public void dispose() { - appliedContext = null; - for (RenderLayer renderLayer : renderLayers.values()) - ((BufferBuilderStorageAccessor) MinecraftClient.getInstance().getBufferBuilders()).entityBuilders().remove(renderLayer); - } - - public enum GlintRenderLayer { - ARMOR_GLINT("armor_glint", 8f, layer -> layer - .shader(RenderPhaseAccessor.ARMOR_GLINT_SHADER()) - .writeMaskState(RenderPhaseAccessor.COLOR_MASK()) - .cull(RenderPhaseAccessor.DISABLE_CULLING()) - .depthTest(RenderPhaseAccessor.EQUAL_DEPTH_TEST()) - .layering(RenderPhaseAccessor.VIEW_OFFSET_Z_LAYERING())), - ARMOR_ENTITY_GLINT("armor_entity_glint", 0.16f, layer -> layer - .shader(RenderPhaseAccessor.ARMOR_ENTITY_GLINT_SHADER()) - .writeMaskState(RenderPhaseAccessor.COLOR_MASK()) - .cull(RenderPhaseAccessor.DISABLE_CULLING()) - .depthTest(RenderPhaseAccessor.EQUAL_DEPTH_TEST()) - .layering(RenderPhaseAccessor.VIEW_OFFSET_Z_LAYERING())), - GLINT_TRANSLUCENT("glint_translucent", 8f, layer -> layer - .shader(RenderPhaseAccessor.TRANSLUCENT_GLINT_SHADER()) - .writeMaskState(RenderPhaseAccessor.COLOR_MASK()) - .cull(RenderPhaseAccessor.DISABLE_CULLING()) - .depthTest(RenderPhaseAccessor.EQUAL_DEPTH_TEST()) - .target(RenderPhaseAccessor.ITEM_TARGET())), - GLINT("glint", 8f, layer -> layer - .shader(RenderPhaseAccessor.GLINT_SHADER()) - .writeMaskState(RenderPhaseAccessor.COLOR_MASK()) - .cull(RenderPhaseAccessor.DISABLE_CULLING()) - .depthTest(RenderPhaseAccessor.EQUAL_DEPTH_TEST())), - DIRECT_GLINT("glint_direct", 8f, layer -> layer - .shader(RenderPhaseAccessor.DIRECT_GLINT_SHADER()) - .writeMaskState(RenderPhaseAccessor.COLOR_MASK()) - .cull(RenderPhaseAccessor.DISABLE_CULLING()) - .depthTest(RenderPhaseAccessor.EQUAL_DEPTH_TEST())), - ENTITY_GLINT("entity_glint", 0.16f, layer -> layer - .shader(RenderPhaseAccessor.ENTITY_GLINT_SHADER()) - .writeMaskState(RenderPhaseAccessor.COLOR_MASK()) - .cull(RenderPhaseAccessor.DISABLE_CULLING()) - .depthTest(RenderPhaseAccessor.EQUAL_DEPTH_TEST()) - .target(RenderPhaseAccessor.ITEM_TARGET())), - DIRECT_ENTITY_GLINT("entity_glint_direct", 0.16f, layer -> layer - .shader(RenderPhaseAccessor.DIRECT_ENTITY_GLINT_SHADER()) - .writeMaskState(RenderPhaseAccessor.COLOR_MASK()) - .cull(RenderPhaseAccessor.DISABLE_CULLING()) - .depthTest(RenderPhaseAccessor.EQUAL_DEPTH_TEST())); - - public final String name; - private final Consumer<RenderLayer.MultiPhaseParameters.Builder> setup; - private final float scale; - - GlintRenderLayer(String name, float scale, Consumer<RenderLayer.MultiPhaseParameters.Builder> setup) { - this.name = name; - this.scale = scale; - this.setup = setup; - } - - public RenderLayer build(CITEnchantment enchantment) { - final float speed = enchantment.speed, rotation = enchantment.rotation, r = enchantment.r, g = enchantment.g, b = enchantment.b, a = enchantment.a; - final WrappedMethodIntensity methodIntensity = enchantment.methodIntensity; - //noinspection ConstantConditions - RenderLayer.MultiPhaseParameters.Builder layer = RenderLayer.MultiPhaseParameters.builder() - .texture(new RenderPhase.Texture(enchantment.textureIdentifier, enchantment.blur, false)) - .texturing(new RenderPhase.Texturing("citresewn_glint_texturing", () -> { - float l = Util.getMeasuringTimeMs() * CITResewnConfig.INSTANCE().citenchantment_scroll_multiplier * speed; - float x = (l % 110000f) / 110000f; - float y = (l % 30000f) / 30000f; - Matrix4f matrix4f = Matrix4f.translate(-x, y, 0.0f); - matrix4f.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion(rotation + 10f)); - matrix4f.multiply(Matrix4f.scale(scale, scale, scale)); - setTextureMatrix(matrix4f); - - setShaderColor(r, g, b, a * methodIntensity.intensity); - }, () -> { - RenderSystem.resetTextureMatrix(); - - setShaderColor(1f, 1f, 1f, 1f); - })) - .transparency(enchantment.blend); - - this.setup.accept(layer); - - return RenderLayer.of("citresewn:enchantment_" + this.name + ":" + enchantment.propertiesIdentifier.toString(), - VertexFormats.POSITION_TEXTURE, - VertexFormat.DrawMode.QUADS, - 256, - layer.build(false)); - } - - public VertexConsumer tryApply(VertexConsumer base, RenderLayer baseLayer, VertexConsumerProvider provider) { - if (!shouldApply || appliedContext == null || appliedContext.size() == 0) - return null; - - VertexConsumer[] layers = new VertexConsumer[Math.min(appliedContext.size(), appliedContext.get(0).pack.cap)]; - - for (int i = 0; i < layers.length; i++) - layers[i] = provider.getBuffer(appliedContext.get(i).renderLayers.get(GlintRenderLayer.this)); - - provider.getBuffer(baseLayer); // refresh base layer for armor consumer - - return base == null ? VertexConsumers.union(layers) : VertexConsumers.union(VertexConsumers.union(layers), base); - } - } - - public static class Blend extends RenderPhase.Transparency { - private final int src, dst, srcAlpha, dstAlpha; - - private Blend(String name, int src, int dst, int srcAlpha, int dstAlpha) { - super(name + "_glint_transparency", null, null); - this.src = src; - this.dst = dst; - this.srcAlpha = srcAlpha; - this.dstAlpha = dstAlpha; - } - - private Blend(String name, int src, int dst) { - this(name, src, dst, GL_ZERO, GL_ONE); - } - - @Override - public void startDrawing() { - enableBlend(); - blendFuncSeparate(src, dst, srcAlpha, dstAlpha); - } - - @Override - public void endDrawing() { - defaultBlendFunc(); - disableBlend(); - } - - public static Blend getBlend(String blendString) throws BlendFormatException { - try { //check named blending function - return Named.valueOf(blendString.toUpperCase(Locale.ENGLISH)).blend; - } catch (IllegalArgumentException ignored) { // create custom blending function - try { - String[] split = blendString.split(" "); - int src, dst, srcAlpha, dstAlpha; - if (split.length == 2) { - src = parseGLConstant(split[0]); - dst = parseGLConstant(split[1]); - srcAlpha = GL_ZERO; - dstAlpha = GL_ONE; - } else if (split.length == 4) { - src = parseGLConstant(split[0]); - dst = parseGLConstant(split[1]); - srcAlpha = parseGLConstant(split[2]); - dstAlpha = parseGLConstant(split[3]); - } else - throw new Exception(); - - return new Blend("custom_" + src + "_" + dst + "_" + srcAlpha + "_" + dstAlpha, src, dst, srcAlpha, dstAlpha); - } catch (Exception e) { - throw new BlendFormatException(); - } - } - } - - private enum Named { - REPLACE(new Blend("replace", 0, 0) { - @Override - public void startDrawing() { - disableBlend(); - } - }), - GLINT(new Blend("glint", GL_SRC_COLOR, GL_ONE)), - ALPHA(new Blend("alpha", GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)), - ADD(new Blend("add", GL_SRC_ALPHA, GL_ONE)), - SUBTRACT(new Blend("subtract", GL_ONE_MINUS_DST_COLOR, GL_ZERO)), - MULTIPLY(new Blend("multiply", GL_DST_COLOR, GL_ONE_MINUS_SRC_ALPHA)), - DODGE(new Blend("dodge", GL_ONE, GL_ONE)), - BURN(new Blend("burn", GL_ZERO, GL_ONE_MINUS_SRC_COLOR)), - SCREEN(new Blend("screen", GL_ONE, GL_ONE_MINUS_SRC_COLOR)), - OVERLAY(new Blend("overlay", GL_DST_COLOR, GL_SRC_COLOR)); - - public final Blend blend; - - Named(Blend blend) { - this.blend = blend; - } - } - - private static int parseGLConstant(String s) throws Exception { - try { - return GL11.class.getDeclaredField(s).getInt(null); - } catch (NoSuchFieldException ignored) { } - - return s.startsWith("0x") ? Integer.parseInt(s.substring(2), 16) : Integer.parseInt(s); - } - - public static class BlendFormatException extends Exception { - public BlendFormatException() { - super("Not a valid blending method"); - } - } - } - - public enum MergeMethod { - AVERAGE { - @Override - public void applyIntensity(Map<Identifier, Integer> stackEnchantments, CITEnchantment cit) { - Identifier enchantment = null; - for (Identifier enchantmentMatch : cit.enchantments) - if (stackEnchantments.containsKey(enchantmentMatch)) { - enchantment = enchantmentMatch; - break; - } - - if (enchantment == null) { - cit.methodIntensity.intensity = 0f; - } else { - float sum = 0f; - for (Integer value : stackEnchantments.values()) - sum += value; - - cit.methodIntensity.intensity = (float) stackEnchantments.get(enchantment) / sum; - } - } - }, - LAYERED { - @Override - public void applyIntensity(Map<Identifier, Integer> stackEnchantments, CITEnchantment cit) { - Identifier enchantment = null; - for (Identifier enchantmentMatch : cit.enchantments) - if (stackEnchantments.containsKey(enchantmentMatch)) { - enchantment = enchantmentMatch; - break; - } - if (enchantment == null) { - cit.methodIntensity.intensity = 0f; - return; - } - - float max = 0f; - for (Integer value : stackEnchantments.values()) - if (value > max) - max = value; - - cit.methodIntensity.intensity = (float) stackEnchantments.get(enchantment) / max; - } - }, - CYCLE { - @Override - public void applyMethod(List<CITEnchantment> citEnchantments, ItemStack stack) { - List<Map.Entry<CITEnchantment, Float>> durations = new ArrayList<>(); - for (CITEnchantment cit : citEnchantments) - durations.add(new HashMap.SimpleEntry<>(cit, cit.duration)); - - for (Map.Entry<CITEnchantment, Float> intensity : statelessFadingLoop(durations, citEnchantments.get(0).pack.fade, ticks, 20).entrySet()) - intensity.getKey().methodIntensity.intensity = intensity.getValue(); - } - }; - - public static int ticks = 0; - - public void applyIntensity(Map<Identifier, Integer> stackEnchantments, CITEnchantment cit) { - cit.methodIntensity.intensity = 1f; - } - - public void applyMethod(List<CITEnchantment> citEnchantments, ItemStack stack) { - Map<Identifier, Integer> stackEnchantments = new LinkedHashMap<>(); - for (NbtElement nbtElement : stack.isOf(Items.ENCHANTED_BOOK) ? EnchantedBookItem.getEnchantmentNbt(stack) : stack.getEnchantments()) - stackEnchantments.put(EnchantmentHelper.getIdFromNbt((NbtCompound) nbtElement), EnchantmentHelper.getLevelFromNbt((NbtCompound) nbtElement)); - - for (CITEnchantment cit : citEnchantments) - if (!cit.enchantmentsAny) - applyIntensity(stackEnchantments, cit); - } - } - - private static class WrappedMethodIntensity { - public float intensity = 1f; - } - - public interface Cached { - List<CITEnchantment> citresewn_getCachedCITEnchantment(Supplier<List<CITEnchantment>> realtime); - } -}
\ No newline at end of file diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java deleted file mode 100644 index 2300f88..0000000 --- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/cits/CITItem.java +++ /dev/null @@ -1,463 +0,0 @@ -package shcm.shsupercm.fabric.citresewn.pack.cits; - -import com.google.common.collect.ImmutableMap; -import com.mojang.datafixers.util.Either; -import it.unimi.dsi.fastutil.objects.Object2IntMap; -import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.render.model.json.JsonUnbakedModel; -import net.minecraft.client.render.model.json.ModelOverride; -import net.minecraft.client.render.model.json.ModelOverrideList; -import net.minecraft.client.render.model.json.ModelTransformation; -import net.minecraft.client.texture.SpriteAtlasTexture; -import net.minecraft.client.util.SpriteIdentifier; -import net.minecraft.client.world.ClientWorld; -import net.minecraft.entity.LivingEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.resource.Resource; -import net.minecraft.resource.ResourceManager; -import net.minecraft.resource.ResourceType; -import net.minecraft.util.Identifier; -import net.minecraft.util.registry.Registry; -import org.apache.commons.io.IOUtils; -import shcm.shsupercm.fabric.citresewn.CITResewn; -import shcm.shsupercm.fabric.citresewn.ex.CITLoadException; -import shcm.shsupercm.fabric.citresewn.ex.CITParseException; -import shcm.shsupercm.fabric.citresewn.mixin.cititem.JsonUnbakedModelAccessor; -import shcm.shsupercm.fabric.citresewn.pack.CITPack; -import shcm.shsupercm.fabric.citresewn.pack.ResewnItemModelIdentifier; -import shcm.shsupercm.fabric.citresewn.pack.ResewnTextureIdentifier; - -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.Reader; -import java.nio.charset.StandardCharsets; -import java.util.*; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -@SuppressWarnings("deprecation") -public class CITItem extends CIT { - private static final String GENERATED_SUB_CITS_PREFIX = "sub_cititem_generated_"; - public static final Set<Identifier> GENERATED_SUB_CITS_SEEN = new HashSet<>(); - - public Map<Identifier, Identifier> assetIdentifiers = new LinkedHashMap<>(); - public Map<List<ModelOverride.Condition>, JsonUnbakedModel> unbakedAssets = new LinkedHashMap<>(); - private Map<String, Either<SpriteIdentifier, String>> textureOverrideMap = new HashMap<>(); - private boolean isTexture = false; - - public BakedModel bakedModel = null; - public CITOverrideList bakedSubModels = new CITOverrideList(); - - public CITItem(CITPack pack, Identifier identifier, Properties properties) throws CITParseException { - super(pack, identifier, properties); - try { - if (this.items.size() == 0) - throw new Exception("CIT must target at least one item type"); - - Identifier assetIdentifier; - boolean containsTexture = false; - String modelProp = properties.getProperty("model"); - if (modelProp == null) - for (Object o : properties.keySet()) - if (o instanceof String property && (property.startsWith("texture") || property.startsWith("tile"))) { - containsTexture = true; - break; - } - if (!containsTexture) { - assetIdentifier = resolvePath(identifier, modelProp, ".json", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id)); - if (assetIdentifier != null) - assetIdentifiers.put(null, assetIdentifier); - else if (modelProp != null) { - assetIdentifier = resolvePath(identifier, modelProp, ".json", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id)); - if (assetIdentifier != null) - assetIdentifiers.put(null, assetIdentifier); - } - } - - for (Object o : properties.keySet()) - if (o instanceof String property && property.startsWith("model.")) { - Identifier subIdentifier = resolvePath(identifier, properties.getProperty(property), ".json", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id)); - if (subIdentifier == null) - throw new Exception("Cannot resolve path for " + property); - - String subItem = property.substring(6); - Identifier subItemIdentifier = fixDeprecatedSubItem(subItem); - assetIdentifiers.put(subItemIdentifier == null ? new Identifier("minecraft", "item/" + subItem) : subItemIdentifier, subIdentifier); - } - - if (assetIdentifiers.size() == 0) { // attempt to load texture - isTexture = true; - String textureProp = properties.getProperty("texture"); - if (textureProp == null) - textureProp = properties.getProperty("tile"); - assetIdentifier = resolvePath(identifier, textureProp, ".png", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id)); - if (assetIdentifier != null) - assetIdentifiers.put(null, assetIdentifier); - - for (Object o : properties.keySet()) - if (o instanceof String property && property.startsWith("texture.")) { - Identifier subIdentifier = resolvePath(identifier, properties.getProperty(property), ".png", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id)); - if (subIdentifier == null) - throw new Exception("Cannot resolve path for " + property); - - String subItem = property.substring(8); - Identifier subItemIdentifier = fixDeprecatedSubItem(subItem); - assetIdentifiers.put(subItemIdentifier == null ? new Identifier("minecraft", "item/" + subItem) : subItemIdentifier, subIdentifier); - } - } else { // attempt to load textureOverrideMap from textures - String textureProp = properties.getProperty("texture"); - if (textureProp == null) - textureProp = properties.getProperty("tile"); - if (textureProp != null) { - assetIdentifier = resolvePath(identifier, textureProp, ".png", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id)); - if (assetIdentifier != null) - textureOverrideMap.put(null, Either.left(new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new ResewnTextureIdentifier(assetIdentifier)))); - else - throw new Exception("Cannot resolve path for texture"); - } - - for (Object o : properties.keySet()) - if (o instanceof String property && property.startsWith("texture.")) { - textureProp = properties.getProperty(property); - Identifier subIdentifier = resolvePath(identifier, textureProp, ".png", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id)); - if (subIdentifier == null) - throw new Exception("Cannot resolve path for " + property); - - textureOverrideMap.put(property.substring(8), Either.left(new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new ResewnTextureIdentifier(subIdentifier)))); - } - } - - if (assetIdentifiers.size() == 0) - throw new Exception("Cannot resolve path for model/texture"); - } catch (Exception e) { - throw new CITParseException(pack.resourcePack, identifier, (e.getClass() == Exception.class ? "" : e.getClass().getSimpleName() + ": ") + e.getMessage()); - } - } - - public void loadUnbakedAssets(ResourceManager resourceManager) throws CITLoadException { - try { - if (isTexture) { - JsonUnbakedModel itemJson = getModelForFirstItemType(resourceManager); - if (((JsonUnbakedModelAccessor) itemJson).getTextureMap().size() > 1) { // use(some/all of) the asset identifiers to build texture override in layered models - textureOverrideMap = ((JsonUnbakedModelAccessor) itemJson).getTextureMap(); - Identifier defaultAsset = assetIdentifiers.get(null); - textureOverrideMap.replaceAll((layerName, originalTextureEither) -> { - Identifier textureIdentifier = assetIdentifiers.remove(originalTextureEither.map(SpriteIdentifier::getTextureId, Identifier::new)); - if (textureIdentifier != null) - return Either.left(new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new ResewnTextureIdentifier(textureIdentifier))); - if (defaultAsset != null) - return Either.left(new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new ResewnTextureIdentifier(defaultAsset))); - return null; - }); - - if (assetIdentifiers.size() == 0 || (assetIdentifiers.size() == 1 && assetIdentifiers.containsKey(null))) { - unbakedAssets.put(null, itemJson); - return; - } - } - - Identifier baseIdentifier = assetIdentifiers.remove(null); - - if (baseIdentifier != null) - unbakedAssets.put(null, loadUnbakedAsset(resourceManager, baseIdentifier)); - - if (!assetIdentifiers.isEmpty()) { // contains sub models - LinkedHashMap<Identifier, List<ModelOverride.Condition>> overrideConditions = new LinkedHashMap<>(); - for (Item item : this.items) { - Identifier itemIdentifier = Registry.ITEM.getId(item); - 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())) { - JsonUnbakedModel itemModelJson = JsonUnbakedModel.deserialize(resourceReader); - - if (itemModelJson.getOverrides() != null && !itemModelJson.getOverrides().isEmpty()) - for (ModelOverride override : itemModelJson.getOverrides()) - overrideConditions.put(override.getModelId(), override.streamConditions().toList()); - } - } - - ArrayList<Identifier> overrideModels = new ArrayList<>(overrideConditions.keySet()); - Collections.reverse(overrideModels); - - for (Identifier overrideModel : overrideModels) { - Identifier replacement = assetIdentifiers.remove(overrideModel); - if (replacement == null) - continue; - - List<ModelOverride.Condition> conditions = overrideConditions.get(overrideModel); - unbakedAssets.put(conditions, loadUnbakedAsset(resourceManager, replacement)); - } - } - } else { // isModel - Identifier baseIdentifier = assetIdentifiers.remove(null); - - if (baseIdentifier != null) { - if (!GENERATED_SUB_CITS_SEEN.add(baseIdentifier)) // cit generated duplicate - baseIdentifier = new Identifier(baseIdentifier.getNamespace(), GENERATED_SUB_CITS_PREFIX + GENERATED_SUB_CITS_SEEN.size() + "_" + baseIdentifier.getPath()); - GENERATED_SUB_CITS_SEEN.add(baseIdentifier); - - JsonUnbakedModel model = loadUnbakedAsset(resourceManager, baseIdentifier); - unbakedAssets.put(null, model); - - if (model.getOverrides().size() > 0 && textureOverrideMap.size() > 0) { - LinkedHashMap<Identifier, List<ModelOverride.Condition>> overrideConditions = new LinkedHashMap<>(); - - for (ModelOverride override : model.getOverrides()) - overrideConditions.put(override.getModelId(), override.streamConditions().toList()); - - ArrayList<Identifier> overrideModels = new ArrayList<>(overrideConditions.keySet()); - Collections.reverse(overrideModels); - - for (Identifier overrideModel : overrideModels) { - Identifier replacement = resolvePath(baseIdentifier, overrideModel.toString(), ".json", resourceManager::containsResource); - if (replacement != null) { - String subTexturePath = replacement.toString().substring(0, replacement.toString().lastIndexOf('.')); - final String subTextureName = subTexturePath.substring(subTexturePath.lastIndexOf('/') + 1); - - replacement = baseIdentifier; - if (!GENERATED_SUB_CITS_SEEN.add(replacement)) // cit generated duplicate - replacement = new Identifier(replacement.getNamespace(), GENERATED_SUB_CITS_PREFIX + GENERATED_SUB_CITS_SEEN.size() + "_" + replacement.getPath()); - GENERATED_SUB_CITS_SEEN.add(replacement); - - JsonUnbakedModel jsonModel = loadUnbakedAsset(resourceManager, replacement); - jsonModel.getOverrides().clear(); - - ((JsonUnbakedModelAccessor) jsonModel).getTextureMap().replaceAll((layerName, texture) -> { - if (layerName != null) - try { - for (String subTexture : textureOverrideMap.keySet()) - if (subTextureName.equals(subTexture)) - return textureOverrideMap.get(subTexture); - } catch (Exception ignored) { } - return texture; - }); - - unbakedAssets.put(overrideConditions.get(overrideModel), jsonModel); - } - } - } - } - - if (!assetIdentifiers.isEmpty()) { // contains sub models - LinkedHashMap<Identifier, List<ModelOverride.Condition>> overrideConditions = new LinkedHashMap<>(); - for (Item item : this.items) { - Identifier itemIdentifier = Registry.ITEM.getId(item); - 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())) { - JsonUnbakedModel itemModelJson = JsonUnbakedModel.deserialize(resourceReader); - - if (itemModelJson.getOverrides() != null && !itemModelJson.getOverrides().isEmpty()) - for (ModelOverride override : itemModelJson.getOverrides()) - overrideConditions.put(override.getModelId(), override.streamConditions().toList()); - } - } - - ArrayList<Identifier> overrideModels = new ArrayList<>(overrideConditions.keySet()); - Collections.reverse(overrideModels); - - for (Identifier overrideModel : overrideModels) { - Identifier replacement = assetIdentifiers.remove(overrideModel); - if (replacement == null) - continue; - - if (!GENERATED_SUB_CITS_SEEN.add(replacement)) // cit generated duplicate - replacement = new Identifier(replacement.getNamespace(), GENERATED_SUB_CITS_PREFIX + GENERATED_SUB_CITS_SEEN.size() + "_" + replacement.getPath()); - GENERATED_SUB_CITS_SEEN.add(replacement); - - List<ModelOverride.Condition> conditions = overrideConditions.get(overrideModel); - unbakedAssets.put(conditions, loadUnbakedAsset(resourceManager, replacement)); - } - } - } - } catch (Exception e) { - throw new CITLoadException(pack.resourcePack, propertiesIdentifier, (e.getClass() == Exception.class ? "" : e.getClass().getSimpleName() + ": ") + e.getMessage()); - } finally { - assetIdentifiers = null; - textureOverrideMap = null; - } - } - - private JsonUnbakedModel loadUnbakedAsset(ResourceManager resourceManager, Identifier assetIdentifier) throws Exception { - final Identifier identifier; - { - Identifier possibleIdentifier = assetIdentifier; - while (possibleIdentifier.getPath().startsWith(GENERATED_SUB_CITS_PREFIX)) - possibleIdentifier = new Identifier(possibleIdentifier.getNamespace(), possibleIdentifier.getPath().substring(possibleIdentifier.getPath().substring(GENERATED_SUB_CITS_PREFIX.length()).indexOf('_') + GENERATED_SUB_CITS_PREFIX.length() + 1)); - identifier = possibleIdentifier; - } - 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)); - json.id = assetIdentifier.toString(); - json.id = json.id.substring(0, json.id.length() - 5); - - ((JsonUnbakedModelAccessor) json).getTextureMap().replaceAll((layer, original) -> { - Optional<SpriteIdentifier> left = original.left(); - if (left.isPresent()) { - Identifier resolvedIdentifier = resolvePath(identifier, left.get().getTextureId().getPath(), ".png", resourceManager::containsResource); - if (resolvedIdentifier != null) - return Either.left(new SpriteIdentifier(left.get().getAtlasId(), new ResewnTextureIdentifier(resolvedIdentifier))); - } - return original; - }); - - if (textureOverrideMap.size() > 0) { - Map<String, Either<SpriteIdentifier, String>> jsonTextureMap = ((JsonUnbakedModelAccessor) json).getTextureMap(); - if (jsonTextureMap.size() == 0) - jsonTextureMap.put("layer0", null); - - final Either<SpriteIdentifier, String> defaultTextureOverride = textureOverrideMap.get(null); - if (defaultTextureOverride != null) - jsonTextureMap.replaceAll((layerName, spriteIdentifierStringEither) -> defaultTextureOverride); - - //jsonTextureMap.putAll(textureOverrideMap); - jsonTextureMap.replaceAll((layerName, texture) -> { - if (layerName != null) - try { - String[] split = texture.map(id -> id.getTextureId().getPath(), s -> s).split("/"); - String textureName = split[split.length - 1]; - if (textureName.endsWith(".png")) - textureName = textureName.substring(0, textureName.length() - 4); - return Objects.requireNonNull(textureOverrideMap.get(textureName)); - } catch (Exception ignored) { } - return texture; - }); - jsonTextureMap.values().removeIf(Objects::isNull); - } - - Identifier parentId = ((JsonUnbakedModelAccessor) json).getParentId(); - if (parentId != null) { - String[] parentIdPathSplit = parentId.getPath().split("/"); - if (parentId.getPath().startsWith("./") || (parentIdPathSplit.length > 2 && parentIdPathSplit[1].equals("cit"))) { - parentId = resolvePath(identifier, parentId.getPath(), ".json", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id)); - if (parentId != null) - ((JsonUnbakedModelAccessor) json).setParentId(new ResewnItemModelIdentifier(parentId)); - } - } - - json.getOverrides().replaceAll(override -> { - String[] modelIdPathSplit = override.getModelId().getPath().split("/"); - if (override.getModelId().getPath().startsWith("./") || (modelIdPathSplit.length > 2 && modelIdPathSplit[1].equals("cit"))) { - Identifier resolvedOverridePath = resolvePath(identifier, override.getModelId().getPath(), ".json", id -> pack.resourcePack.contains(ResourceType.CLIENT_RESOURCES, id)); - if (resolvedOverridePath != null) - return new ModelOverride(new ResewnItemModelIdentifier(resolvedOverridePath), override.streamConditions().collect(Collectors.toList())); - } - - return override; - }); - - return json; - } finally { - IOUtils.closeQuietly(is, resource); - } - } else if (identifier.getPath().endsWith(".png")) { - json = getModelForFirstItemType(resourceManager); - if (json == null) - json = new JsonUnbakedModel(new Identifier("minecraft", "item/generated"), new ArrayList<>(), ImmutableMap.of("layer0", Either.left(new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new ResewnTextureIdentifier(identifier)))), true, JsonUnbakedModel.GuiLight.ITEM, ModelTransformation.NONE, new ArrayList<>()); - json.getOverrides().clear(); - json.id = identifier.toString(); - json.id = json.id.substring(0, json.id.length() - 4); - - ((JsonUnbakedModelAccessor) json).getTextureMap().replaceAll((layerName, originalTextureEither) -> { - if (textureOverrideMap.size() > 0) { - Either<SpriteIdentifier, String> textureOverride = textureOverrideMap.get(layerName); - if (textureOverride == null) - textureOverride = textureOverrideMap.get(null); - return textureOverride == null ? originalTextureEither : textureOverride; - } else - return Either.left(new SpriteIdentifier(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE, new ResewnTextureIdentifier(identifier))); - }); - return json; - } - - throw new Exception("Unknown asset type"); - } - - public Identifier fixDeprecatedSubItem(String subItem) { - String replacement = switch (subItem) { - case "bow_pulling_standby" -> "bow"; - case "crossbow_standby" -> "crossbow"; - case "potion_bottle_drinkable" -> "potion"; - case "potion_bottle_splash" -> "splash_potion"; - case "potion_bottle_lingering" -> "lingering_potion"; - - - default -> null; - }; - - if (replacement != null) { - CITResewn.logWarnLoading("CIT Warning: Using deprecated sub item id \"" + subItem + "\" instead of \"" + replacement + "\" in " + pack.resourcePack.getName() + " -> " + propertiesIdentifier.toString()); - - return new Identifier("minecraft", "item/" + replacement); - } - - return null; - } - - 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)); - - 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()); - GENERATED_SUB_CITS_SEEN.add(firstItemModelIdentifier); - - json.id = firstItemModelIdentifier.toString(); - json.id = json.id.substring(0, json.id.length() - 5); - return json; - } catch (Exception e) { - return null; - } finally { - IOUtils.closeQuietly(itemModelResource); - } - } - - public BakedModel getItemModel(ItemStack stack, ClientWorld world, LivingEntity entity, int seed) { - // get sub items or bakedModel if no sub item matches @Nullable - BakedModel bakedModel = bakedSubModels.apply(this.bakedModel, stack, world, entity, seed); - - // apply model overrides - if (bakedModel != null && bakedModel.getOverrides() != null) - bakedModel = bakedModel.getOverrides().apply(bakedModel, stack, world, entity, seed); - - return bakedModel; - } - - public static class CITOverrideList extends ModelOverrideList { - public void override(List<ModelOverride.Condition> key, BakedModel bakedModel) { - Set<Identifier> conditionTypes = new LinkedHashSet<>(Arrays.asList(this.conditionTypes)); - for (ModelOverride.Condition condition : key) - conditionTypes.add(condition.getType()); - this.conditionTypes = conditionTypes.toArray(new Identifier[0]); - - this.overrides = Arrays.copyOf(this.overrides, this.overrides.length + 1); - - Object2IntMap<Identifier> object2IntMap = new Object2IntOpenHashMap<>(); - for(int i = 0; i < this.conditionTypes.length; ++i) - object2IntMap.put(this.conditionTypes[i], i); - - this.overrides[this.overrides.length - 1] = new BakedOverride( - key.stream() - .map((condition) -> new InlinedCondition(object2IntMap.getInt(condition.getType()), condition.getThreshold())) - .toArray(InlinedCondition[]::new) - , bakedModel); - } - } - - public interface Cached { - CITItem citresewn_getCachedCITItem(Supplier<CITItem> realtime); - - boolean citresewn_isMojankCIT(); - void citresewn_setMojankCIT(boolean mojankCIT); - } -} |