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 | |
| parent | c3c547c6f950ebbc047cd31672f6a794483a9d0e (diff) | |
| download | CITResewn-897172bde9128da47181a6db6c1ff4885081ba8d.tar.gz CITResewn-897172bde9128da47181a6db6c1ff4885081ba8d.tar.bz2 CITResewn-897172bde9128da47181a6db6c1ff4885081ba8d.zip | |
Re(moved) most of the old sources
46 files changed, 21 insertions, 2933 deletions
@@ -20,3 +20,4 @@ build # other eclipse run +srcOld diff --git a/settings.gradle b/settings.gradle index 4ab5170..7a1d91c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -8,4 +8,4 @@ pluginManagement { } } -include 'defaults'
\ No newline at end of file +include 'defaults', 'srcOld'
\ No newline at end of file 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; |
