From 500117bb7ab02deb17d8e85e8b5029f8581a7524 Mon Sep 17 00:00:00 2001 From: Michael Hillcox Date: Sun, 29 Nov 2020 16:58:41 +0000 Subject: [PATCH] Implemented Configs (Sectioned them out in advance...) --- .../common/ActuallyAdditions.java | 7 ++++++ .../common/config/Config.java | 18 ++++++++++++++ .../common/config/GeneralConfig.java | 18 ++++++++++++++ .../common/config/ItemConfig.java | 24 +++++++++++++++++++ .../items/useables/TeleportStaffItem.java | 9 +++---- .../common/utilities/VisualHelper.java | 2 +- 6 files changed, 73 insertions(+), 5 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/common/config/Config.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/common/config/GeneralConfig.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/common/config/ItemConfig.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/ActuallyAdditions.java b/src/main/java/de/ellpeck/actuallyadditions/common/ActuallyAdditions.java index dc7f15eeb..b5ff0df40 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/ActuallyAdditions.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/ActuallyAdditions.java @@ -1,12 +1,15 @@ package de.ellpeck.actuallyadditions.common; import de.ellpeck.actuallyadditions.common.blocks.ActuallyBlocks; +import de.ellpeck.actuallyadditions.common.config.Config; import de.ellpeck.actuallyadditions.common.items.ActuallyItems; import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; +import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @@ -27,6 +30,10 @@ public class ActuallyAdditions { }; public ActuallyAdditions() { + ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, Config.SERVER_CONFIG); + ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, Config.CLIENT_CONFIG); + ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Config.COMMON_CONFIG); + IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus(); ActuallyBlocks.BLOCKS.register(eventBus); diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/config/Config.java b/src/main/java/de/ellpeck/actuallyadditions/common/config/Config.java new file mode 100644 index 000000000..bc8b94c7d --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/common/config/Config.java @@ -0,0 +1,18 @@ +package de.ellpeck.actuallyadditions.common.config; + +import net.minecraftforge.common.ForgeConfigSpec; + +import static net.minecraftforge.common.ForgeConfigSpec.Builder; + +public class Config { + protected static final Builder SERVER_BUILDER = new Builder(); + protected static final Builder CLIENT_BUILDER = new Builder(); + protected static final Builder COMMON_BUILDER = new Builder(); + + public static final GeneralConfig GENERAL = new GeneralConfig(); + public static final ItemConfig ITEM_CONFIG = new ItemConfig(); + + public static final ForgeConfigSpec SERVER_CONFIG = SERVER_BUILDER.build(); + public static final ForgeConfigSpec CLIENT_CONFIG = CLIENT_BUILDER.build(); + public static final ForgeConfigSpec COMMON_CONFIG = COMMON_BUILDER.build(); +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/config/GeneralConfig.java b/src/main/java/de/ellpeck/actuallyadditions/common/config/GeneralConfig.java new file mode 100644 index 000000000..c0e05b2e0 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/common/config/GeneralConfig.java @@ -0,0 +1,18 @@ +package de.ellpeck.actuallyadditions.common.config; + +import static de.ellpeck.actuallyadditions.common.config.Config.*; +import static net.minecraftforge.common.ForgeConfigSpec.*; + +public class GeneralConfig { + public final BooleanValue advancedInfo; + + public GeneralConfig() { + CLIENT_BUILDER.comment("Actually Additions General Config").push("general"); + + advancedInfo = CLIENT_BUILDER + .comment("Shows advanced item info when holding control on every item") + .define("Advanced Info", true); + + CLIENT_BUILDER.pop(); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/config/ItemConfig.java b/src/main/java/de/ellpeck/actuallyadditions/common/config/ItemConfig.java new file mode 100644 index 000000000..02be6bd58 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/common/config/ItemConfig.java @@ -0,0 +1,24 @@ +package de.ellpeck.actuallyadditions.common.config; + +import static de.ellpeck.actuallyadditions.common.config.Config.COMMON_BUILDER; +import static net.minecraftforge.common.ForgeConfigSpec.IntValue; + +public class ItemConfig { + public final IntValue teleportStaffCost; + public final IntValue teleportStaffMaxEnergy; + + public ItemConfig() { + COMMON_BUILDER.comment("Item Config Options").push("items"); + + teleportStaffCost = COMMON_BUILDER + .comment( + "The base cost of the Teleport Staff (this is used to calculate the cost per distances as well)", + "Don't assign this value higher than the Teleport Staffs max energy!" + ) + .defineInRange("Teleport Staff Base Cost", 200, 0, 100000); + + teleportStaffMaxEnergy = COMMON_BUILDER + .comment("The max amount of Crystal Flux stored in the Teleport Staff") + .defineInRange("Teleport Staff Max Energy", 250000, 0, 1000000); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/items/useables/TeleportStaffItem.java b/src/main/java/de/ellpeck/actuallyadditions/common/items/useables/TeleportStaffItem.java index ff9ea6736..9c4e33052 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/items/useables/TeleportStaffItem.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/items/useables/TeleportStaffItem.java @@ -1,5 +1,6 @@ package de.ellpeck.actuallyadditions.common.items.useables; +import de.ellpeck.actuallyadditions.common.config.Config; import de.ellpeck.actuallyadditions.common.items.CrystalFluxItem; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; @@ -13,12 +14,11 @@ import net.minecraft.world.World; import net.minecraftforge.energy.CapabilityEnergy; public class TeleportStaffItem extends CrystalFluxItem { - private static final int BASE_COST_PER_USE = 200; - public TeleportStaffItem() { - super(baseProps(), () -> 250000); + super(baseProps(), Config.ITEM_CONFIG.teleportStaffMaxEnergy::get); } + // todo: come back and clean this up @Override public ActionResult onItemRightClick(World world, PlayerEntity player, Hand hand) { ItemStack stack = player.getHeldItem(hand); @@ -37,7 +37,8 @@ public class TeleportStaffItem extends CrystalFluxItem { Vector3f centerOfHit = new Vector3f(toPos.getX(), toPos.getY(), toPos.getZ()); centerOfHit.add(.5f, (blockTrace.getFace().getAxis() == Direction.Axis.Y ? .5f : 0), .5f); - int energyCost = BASE_COST_PER_USE + (int) (BASE_COST_PER_USE * (player.getDistanceSq(toPos.getX(), toPos.getY(), toPos.getZ()) / 100)); + int baseCost = Config.ITEM_CONFIG.teleportStaffCost.get(); + int energyCost = baseCost + (int) (baseCost * (player.getDistanceSq(toPos.getX(), toPos.getY(), toPos.getZ()) / 100)); boolean canUse = stack.getCapability(CapabilityEnergy.ENERGY).map(e -> e.getEnergyStored() >= energyCost).orElse(false); if (!canUse) { diff --git a/src/main/java/de/ellpeck/actuallyadditions/common/utilities/VisualHelper.java b/src/main/java/de/ellpeck/actuallyadditions/common/utilities/VisualHelper.java index c63eb90df..0e823e313 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/common/utilities/VisualHelper.java +++ b/src/main/java/de/ellpeck/actuallyadditions/common/utilities/VisualHelper.java @@ -2,7 +2,7 @@ package de.ellpeck.actuallyadditions.common.utilities; public class VisualHelper { /** - * Stolen from Ell's original code, because lazy. What does it do? Something with wheels? (It's an hsb selector) + * Stolen from Ell's original code, because lazy. What does it do? Something with wheels? (It's an RGB selector) */ public static float[] getWheelColor(float pos) { if (pos < 85.0f) { return new float[] { pos * 3.0F, 255.0f - pos * 3.0f, 0.0f }; }