Skip to content

Commit

Permalink
Allows Addon Makers to register new increment Upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeryn99 committed Dec 18, 2023
1 parent 8761933 commit ca72e07
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -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<ItemStack> icon, ResourceLocation translationKey, UpgradeType upgradeType) {
super(icon, translationKey, upgradeType);
}

public IncrementUpgrade(Supplier<ItemStack> icon, Supplier<Upgrade> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public class Upgrades {
public static final RegistrySupplier<Upgrade> 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<Upgrade> EXPLORER = UPGRADE_DEFERRED_REGISTRY.register("explorer", () -> new Upgrade(Items.COMPASS::getDefaultInstance, NAVIGATION_SYSTEM, RegistryHelper.makeKey("explorer"), Upgrade.UpgradeType.SUB_UPGRADE)
public static final RegistrySupplier<Upgrade> 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<Upgrade> 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<Upgrade> 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<Upgrade> 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<Upgrade> 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<Upgrade> 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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{
Expand Down Expand Up @@ -518,23 +521,21 @@ public void cycleCordIncrement(int direction) {
this.cordIncrementIndex = nextIndex;
}

public int[] getCoordinateIncrements(UpgradeHandler upgradeHandler){
public int[] getCoordinateIncrements(UpgradeHandler upgradeHandler) {
List<Integer> 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;
}
Expand Down

0 comments on commit ca72e07

Please sign in to comment.