From ca72e07d0d037c584bddffc533149d728a65395e Mon Sep 17 00:00:00 2001 From: Craig Date: Mon, 18 Dec 2023 18:33:40 +0000 Subject: [PATCH] Allows Addon Makers to register new increment Upgrades --- .../capability/upgrades/IncrementUpgrade.java | 28 +++++++++++++++++++ .../common/capability/upgrades/Upgrades.java | 6 ++-- .../tardis/manager/TardisPilotingManager.java | 23 +++++++-------- 3 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/IncrementUpgrade.java diff --git a/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/IncrementUpgrade.java b/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/IncrementUpgrade.java new file mode 100644 index 000000000..84c5c4c2f --- /dev/null +++ b/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/IncrementUpgrade.java @@ -0,0 +1,28 @@ +package whocraft.tardis_refined.common.capability.upgrades; + +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; + +import java.util.function.Supplier; + +public class IncrementUpgrade extends Upgrade{ + + int incrementAmount = 0; + + public IncrementUpgrade(Supplier icon, ResourceLocation translationKey, UpgradeType upgradeType) { + super(icon, translationKey, upgradeType); + } + + public IncrementUpgrade(Supplier icon, Supplier parent, ResourceLocation translationKey, UpgradeType upgradeType) { + super(icon, parent, translationKey, upgradeType); + } + + public int getIncrementAmount() { + return incrementAmount; + } + + public IncrementUpgrade setIncrementAmount(int incrementAmount) { + this.incrementAmount = incrementAmount; + return this; + } +} diff --git a/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/Upgrades.java b/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/Upgrades.java index fe9e4b22c..e0db8a3d9 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/Upgrades.java +++ b/common/src/main/java/whocraft/tardis_refined/common/capability/upgrades/Upgrades.java @@ -48,13 +48,13 @@ public class Upgrades { public static final RegistrySupplier NAVIGATION_SYSTEM = UPGRADE_DEFERRED_REGISTRY.register("navigation_system", () -> new Upgrade(Items.COMPASS::getDefaultInstance, TARDIS_XP, RegistryHelper.makeKey("navigation_system"), Upgrade.UpgradeType.MAIN_UPGRADE) .setSkillPointsRequired(50).setPosition(0, 2)); - public static final RegistrySupplier EXPLORER = UPGRADE_DEFERRED_REGISTRY.register("explorer", () -> new Upgrade(Items.COMPASS::getDefaultInstance, NAVIGATION_SYSTEM, RegistryHelper.makeKey("explorer"), Upgrade.UpgradeType.SUB_UPGRADE) + public static final RegistrySupplier EXPLORER = UPGRADE_DEFERRED_REGISTRY.register("explorer", () -> new IncrementUpgrade(Items.COMPASS::getDefaultInstance, NAVIGATION_SYSTEM, RegistryHelper.makeKey("explorer"), Upgrade.UpgradeType.SUB_UPGRADE).setIncrementAmount(1000) .setSkillPointsRequired(50).setPosition(1, 2)); - public static final RegistrySupplier EXPLORER_II = UPGRADE_DEFERRED_REGISTRY.register("explorer_ii", () -> new Upgrade(Items.COMPASS::getDefaultInstance, EXPLORER, RegistryHelper.makeKey("explorer_ii"), Upgrade.UpgradeType.SUB_UPGRADE) + public static final RegistrySupplier EXPLORER_II = UPGRADE_DEFERRED_REGISTRY.register("explorer_ii", () -> new IncrementUpgrade(Items.COMPASS::getDefaultInstance, EXPLORER, RegistryHelper.makeKey("explorer_ii"), Upgrade.UpgradeType.SUB_UPGRADE).setIncrementAmount(2500) .setSkillPointsRequired(50).setPosition(2, 2)); - public static final RegistrySupplier EXPLORER_III = UPGRADE_DEFERRED_REGISTRY.register("explorer_iii", () -> new Upgrade(Items.COMPASS::getDefaultInstance, EXPLORER_II, RegistryHelper.makeKey("explorer_iii"), Upgrade.UpgradeType.SUB_UPGRADE) + public static final RegistrySupplier EXPLORER_III = UPGRADE_DEFERRED_REGISTRY.register("explorer_iii", () -> new IncrementUpgrade(Items.COMPASS::getDefaultInstance, EXPLORER_II, RegistryHelper.makeKey("explorer_iii"), Upgrade.UpgradeType.SUB_UPGRADE).setIncrementAmount(5000) .setSkillPointsRequired(50).setPosition(3, 2)); public static final RegistrySupplier DIMENSION_TRAVEL = UPGRADE_DEFERRED_REGISTRY.register("dimension_travel", () -> new Upgrade(Blocks.NETHER_BRICKS.asItem()::getDefaultInstance, NAVIGATION_SYSTEM, RegistryHelper.makeKey("dimension_travel"), Upgrade.UpgradeType.SUB_UPGRADE) diff --git a/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisPilotingManager.java b/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisPilotingManager.java index bc55eddc9..3321660a9 100644 --- a/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisPilotingManager.java +++ b/common/src/main/java/whocraft/tardis_refined/common/tardis/manager/TardisPilotingManager.java @@ -13,6 +13,8 @@ import net.minecraft.world.phys.Vec3; import whocraft.tardis_refined.api.event.TardisEvents; import whocraft.tardis_refined.common.capability.TardisLevelOperator; +import whocraft.tardis_refined.common.capability.upgrades.IncrementUpgrade; +import whocraft.tardis_refined.common.capability.upgrades.Upgrade; import whocraft.tardis_refined.common.capability.upgrades.UpgradeHandler; import whocraft.tardis_refined.common.capability.upgrades.Upgrades; import whocraft.tardis_refined.common.tardis.TardisArchitectureHandler; @@ -21,6 +23,7 @@ import whocraft.tardis_refined.registry.SoundRegistry; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class TardisPilotingManager extends BaseHandler{ @@ -518,23 +521,21 @@ public void cycleCordIncrement(int direction) { this.cordIncrementIndex = nextIndex; } - public int[] getCoordinateIncrements(UpgradeHandler upgradeHandler){ + public int[] getCoordinateIncrements(UpgradeHandler upgradeHandler) { List increments = new ArrayList<>(List.of(1, 10, 100)); - if(Upgrades.EXPLORER.get().isUnlocked(upgradeHandler)){ - increments.add(1000); - } - - if(Upgrades.EXPLORER_II.get().isUnlocked(upgradeHandler)){ - increments.add(2500); - } - if(Upgrades.EXPLORER_III.get().isUnlocked(upgradeHandler)){ - increments.add(5000); + for (Upgrade upgrade : Upgrades.UPGRADE_DEFERRED_REGISTRY.getRegistry()) { + if (upgrade instanceof IncrementUpgrade incrementUpgrade) { + if (upgrade.isUnlocked(upgradeHandler)) { + increments.add(incrementUpgrade.getIncrementAmount()); + } + } } - + Collections.sort(increments); return increments.stream().mapToInt(Integer::intValue).toArray(); } + public boolean shouldThrottleBeDown() { return isInFlight && ticksLanding == 0; }