Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5 from Create-Fabric/arrp_lang
Browse files Browse the repository at this point in the history
Runtime translations and config stuff
  • Loading branch information
YTG1234 committed Mar 15, 2021
2 parents 516b8af + 3d3d185 commit 8a4b812
Show file tree
Hide file tree
Showing 20 changed files with 679 additions and 163 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -5,7 +5,7 @@ org.gradle.jvmargs = -Xmx4G
# check these on https://fabricmc.net/use
minecraft_version = 1.16.5
yarn_mappings = 1.16.5+build.5
loader_version = 0.11.2
loader_version = 0.11.3

# Mod Properties
mod_version = 0.1.0
Expand Down
24 changes: 16 additions & 8 deletions src/main/java/com/simibubi/create/Create.java
Expand Up @@ -10,10 +10,10 @@
import com.simibubi.create.foundation.advancement.AllTriggers;
import com.simibubi.create.foundation.config.AllConfigs;
import com.simibubi.create.foundation.networking.AllPackets;
import com.simibubi.create.foundation.resource.TranslationsHolder;
import com.simibubi.create.foundation.worldgen.AllWorldFeatures;

import net.devtech.arrp.api.RRPCallback;
import net.devtech.arrp.api.RuntimeResourcePack;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.ConfigData;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.minecraft.SharedConstants;
Expand All @@ -28,13 +28,12 @@ public class Create implements ModInitializer {
public static final String NAME = "Create";

public static Logger logger = LogManager.getLogger();
public static ItemGroup baseCreativeTab = FabricItemGroupBuilder.build(new Identifier(ID, "base"), () -> new ItemStack(AllBlocks.COGWHEEL));
public static ItemGroup palettesCreativeTab = FabricItemGroupBuilder.build(new Identifier(ID, "palettes"), () -> new ItemStack(AllBlocks.ZINC_BLOCK));
public static ItemGroup baseCreativeTab = FabricItemGroupBuilder.build(id("base"), () -> new ItemStack(AllBlocks.COGWHEEL));
public static ItemGroup palettesCreativeTab = FabricItemGroupBuilder.build(id("palettes"), () -> new ItemStack(AllBlocks.ZINC_BLOCK));

public static TorquePropagator torquePropagator;
public static Random random;

public static final RuntimeResourcePack RESOURCE_PACK = RuntimeResourcePack.create(ID + ":resources");

@Override
public void onInitialize() {
Expand All @@ -58,14 +57,23 @@ public void onInitialize() {

AllWorldFeatures.reload();

RRPCallback.EVENT.register(a -> a.add(RESOURCE_PACK));
TranslationsHolder.initialize();

if (SharedConstants.isDevelopment) MixinEnvironment.getCurrentEnvironment().audit();

AllTriggers.register();
}

public static Identifier asResource(String path) {
public static Identifier id(String path) {
return new Identifier(ID, path);
}
public static AllConfigs getConfig() {
AllConfigs config = AutoConfig.getConfigHolder(AllConfigs.class).getConfig();
try {
config.validatePostLoad(); // The best way to validate :)
} catch (ConfigData.ValidationException e) {
throw new RuntimeException(e);
}
return config;
}
}
Expand Up @@ -10,7 +10,6 @@
import net.minecraft.world.WorldAccess;

public class TorquePropagator {

static Map<WorldAccess, Map<Long, KineticNetwork>> networks = new HashMap<>();

public void onLoadWorld(WorldAccess world) {
Expand Down
111 changes: 44 additions & 67 deletions src/main/java/com/simibubi/create/foundation/config/AllConfigs.java
Expand Up @@ -6,11 +6,20 @@
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.autoconfig.annotation.ConfigEntry;
import me.shedaniel.autoconfig.annotation.ConfigEntry.Gui.CollapsibleObject;
import me.shedaniel.autoconfig.annotation.ConfigEntry.Gui.Tooltip;
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;

@Config(name = "create")
public class AllConfigs implements ConfigData {
public static void register() {
try {
AutoConfig.register(AllConfigs.class, Toml4jConfigSerializer::new).getConfig().validatePostLoad();
} catch (ValidationException e) {
throw new RuntimeException(e);
}
}

// use this to use the config
// ModConfig config = AutoConfig.getConfigHolder(ModConfig.class).getConfig();

Expand All @@ -25,82 +34,50 @@ public class AllConfigs implements ConfigData {
*/

// creating collapsible groups
@ConfigEntry.Gui.CollapsibleObject
@CollapsibleObject
@Tooltip
CClient client = new CClient();
@ConfigEntry.Gui.CollapsibleObject

@CollapsibleObject
CCommon common = new CCommon();
@ConfigEntry.Gui.CollapsibleObject

@CollapsibleObject
CCuriosities curiosities = new CCuriosities();
@ConfigEntry.Gui.CollapsibleObject

@CollapsibleObject
CFluids fluids = new CFluids();
@ConfigEntry.Gui.CollapsibleObject

@CollapsibleObject
CKinetics kinetics = new CKinetics();
@ConfigEntry.Gui.CollapsibleObject

@CollapsibleObject
CLogistics logistics = new CLogistics();
@ConfigEntry.Gui.CollapsibleObject

@CollapsibleObject
CRecipes recipes = new CRecipes();
@ConfigEntry.Gui.CollapsibleObject

@CollapsibleObject
CSchematics schematics = new CSchematics();
@ConfigEntry.Gui.CollapsibleObject
CServer server = new CServer();
@ConfigEntry.Gui.CollapsibleObject
CStress stress = new CStress();
@ConfigEntry.Gui.CollapsibleObject
CWorldGen worldGen = new CWorldGen();

@CollapsibleObject
CServer server = new CServer();

@CollapsibleObject
CStress stress = new CStress();

public static void register() {
validateConfigs();
AutoConfig.register(AllConfigs.class, Toml4jConfigSerializer::new);
}
@CollapsibleObject
CWorldGen worldGen = new CWorldGen();

// MY EYES
public static void validateConfigs() { // this is probably the wrong way to do it but post-validation documentation is literally 3 sentences
final Logger LOGGER = LogManager.getLogger("Create Config Validation");
String reset = " reset! Invalid Value!";
if (!(CClient.fanParticleDensity >= 0) ||
(CClient.fanParticleDensity <= 1)) { CClient.fanParticleDensity = 0.5f; LOGGER.warn("fanParticleDensity" + reset);}
if (!(CClient.overlayOffsetX >= Integer.MIN_VALUE)) { CClient.overlayOffsetX = 0; LOGGER.warn("overlayOffsetX" + reset);} // i know what the errors say. gonna leave it anyway.
if (!(CClient.overlayOffsetY >= Integer.MIN_VALUE)) { CClient.overlayOffsetY = 0; LOGGER.warn("overlayOffsetY" + reset);}
if (!(CCuriosities.maxSymmetryWandRange > 10)) { CCuriosities.maxSymmetryWandRange = 50; LOGGER.warn("maxSymmetryWandRange" + reset);}
//if (!(CCuriosities.zapperUndoLogLength > 0)) { CCuriosities.zapperUndoLogLength = 10; LOGGER.warn("zapperUndoLogLength" + reset");}
if (!(CFluids.fluidTankCapacity >= 1)) { CFluids.fluidTankCapacity = 8; LOGGER.warn("fluidTankCapacity" + reset);}
if (!(CFluids.fluidTankMaxHeight >= 1)) { CFluids.fluidTankMaxHeight = 32; LOGGER.warn("fluidTankCapacity" + reset);}
if (!(CFluids.mechanicalPumpRange >= 1)) { CFluids.mechanicalPumpRange = 16; LOGGER.warn("mechanicalPumpRange" + reset);}
if (!(CFluids.hosePulleyBlockThreshold >= -1)) { CFluids.hosePulleyBlockThreshold = 10000; LOGGER.warn("hosePulleyBlockThreshold" + reset);}
if (!(CFluids.hosePulleyRange >= 1)) { CFluids.hosePulleyRange = 128; LOGGER.warn("hosePulleyRange" + reset);}
if (!(CKinetics.maxBeltLength >= 5)) { CKinetics.maxBeltLength = 20; LOGGER.warn("maxBeltLength" + reset);}
if (!(CKinetics.crushingDamage >= 0)) { CKinetics.crushingDamage = 4; LOGGER.warn("crushingDamage" + reset);}
if (!(CKinetics.maxMotorSpeed >= 64)) { CKinetics.maxMotorSpeed = 256; LOGGER.warn("maxMotorSpeed" + reset);}
if (!(CKinetics.waterWheelBaseSpeed >= 1)) { CKinetics.waterWheelBaseSpeed = 4; LOGGER.warn("waterWheelBaseSpeed" + reset);}
if (!(CKinetics.waterWheelFlowSpeed >= 1)) { CKinetics.waterWheelFlowSpeed = 4; LOGGER.warn("waterWheelFlowSpeed" + reset);}
if (!(CKinetics.furnaceEngineSpeed >= 1)) { CKinetics.furnaceEngineSpeed = 16; LOGGER.warn("furnaceEngineSpeed" + reset);}
if (!(CKinetics.maxRotationSpeed >= 64)) { CKinetics.maxRotationSpeed = 256; LOGGER.warn("maxRotationSpeed" + reset);}
if (!(CKinetics.kineticValidationFrequency >= 5)) { CKinetics.kineticValidationFrequency = 60;LOGGER.warn("kineticValidationFrequency" + reset);}
if (!(CKinetics.crankHungerMultiplier >= 0) ||
(CKinetics.crankHungerMultiplier <= 1)) { CKinetics.crankHungerMultiplier = 0.01f; LOGGER.warn("crankHungerMultiplier" + reset);}
if (!(CKinetics.fanPushDistance >= 5)) { CKinetics.fanPushDistance = 20; LOGGER.warn("fanPushDistance" + reset);}
if (!(CKinetics.fanPullDistance >= 5)) { CKinetics.fanPullDistance = 20; LOGGER.warn("fanPullDistance" + reset);}
if (!(CKinetics.fanBlockCheckRate >= 10)) { CKinetics.fanBlockCheckRate = 30; LOGGER.warn("fanBlockCheckRate" + reset);}
if (!(CKinetics.fanRotationArgmax >= 64)) { CKinetics.fanRotationArgmax = 256; LOGGER.warn("fanRotationArgmax" + reset);}
if (!(CKinetics.generatingFanSpeed >= 0)) { CKinetics.generatingFanSpeed = 4; LOGGER.warn("generatingFanSpeed" + reset);}
if (!(CKinetics.maxBlocksMoved >= 1)) { CKinetics.maxBlocksMoved = 2048; LOGGER.warn("maxBlocksMoved" + reset);}
if (!(CKinetics.maxChassisRange >= 1)) { CKinetics.maxChassisRange = 16; LOGGER.warn("maxChassisRange" + reset);}
if (!(CKinetics.maxPistonPoles >= 1)) { CKinetics.maxPistonPoles = 64; LOGGER.warn("maxPistonPoles" + reset);}
if (!(CKinetics.maxRopeLength >= 1)) { CKinetics.maxRopeLength = 128; LOGGER.warn("maxRopeLength" + reset);}
if (!(CKinetics.maxCartCouplingLength >= 1)) { CKinetics.maxCartCouplingLength = 32; LOGGER.warn("maxCartCouplingLength" + reset);}
/*if (!(CKinetics.crankHungerMultiplier >= 0) ||
(CKinetics.crankHungerMultiplier <= 1)) { CKinetics.crankHungerMultiplier = 0.01f; LOGGER.warn("crankHungerMultiplier" + reset);}
if (!(CKinetics.crankHungerMultiplier >= 0) ||
(CKinetics.crankHungerMultiplier <= 1)) { CKinetics.crankHungerMultiplier = 0.01f; LOGGER.warn("crankHungerMultiplier" + reset);}
if (!(CKinetics.crankHungerMultiplier >= 0) ||
(CKinetics.crankHungerMultiplier <= 1)) { CKinetics.crankHungerMultiplier = 0.01f; LOGGER.warn("crankHungerMultiplier" + reset);}
if (!(CKinetics.crankHungerMultiplier >= 0) ||
(CKinetics.crankHungerMultiplier <= 1)) { CKinetics.crankHungerMultiplier = 0.01f; LOGGER.warn("crankHungerMultiplier" + reset);}
if (!(CKinetics.crankHungerMultiplier >= 0) ||
(CKinetics.crankHungerMultiplier <= 1)) { CKinetics.crankHungerMultiplier = 0.01f; LOGGER.warn("crankHungerMultiplier" + reset);}
if (!(CKinetics.crankHungerMultiplier >= 0) ||
(CKinetics.crankHungerMultiplier <= 1)) { CKinetics.crankHungerMultiplier = 0.01f; LOGGER.warn("crankHungerMultiplier" + reset);}*/
@Override
public void validatePostLoad() throws ValidationException {
client.validate();
curiosities.validate();
fluids.validate();
kinetics.validate();
logistics.validate();
recipes.validate();
schematics.validate();
server.validate();
worldGen.validate();
}
}
}
50 changes: 37 additions & 13 deletions src/main/java/com/simibubi/create/foundation/config/CClient.java
@@ -1,15 +1,39 @@
package com.simibubi.create.foundation.config;

public class CClient {
// todo: lang
// "Client-only settings - If you're looking for general settings, look inside your worlds serverconfig folder!"
boolean enableTooltips = true; // "Show item descriptions on Shift and controls on Ctrl."
boolean enableOverstressedTooltip = true; // "Display a tooltip when looking at overstressed components."
boolean explainRenderErrors = true; // "Log a stack-trace when rendering issues happen within a moving contraption."
static float fanParticleDensity = .5f; // 0-1, "fanParticleDensity"
boolean enableRainbowDebug = true; // "Show colourful debug information while the F3-Menu is open."
boolean experimentalRendering = true; // "Use modern OpenGL features to drastically increase performance."
static int overlayOffsetX = 20; // > -2147483648, "Offset the overlay from goggle- and hover- information by this many pixels on the X axis; Use /create overlay"
static int overlayOffsetY = 0; // > -2147483648, "Offset the overlay from goggle- and hover- information by this many pixels on the Y axis; Use /create overlay"
boolean smoothPlacementIndicator = false; // "Use an alternative indicator when showing where the assisted placement ends up relative to your crosshair"
}
import com.simibubi.create.foundation.config.util.Validatable;
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.ConfigEntry.Gui.Tooltip;
import net.minecraft.util.math.MathHelper;

public class CClient implements Validatable {
@Tooltip
boolean enableTooltips = true;

@Tooltip
boolean enableOverstressedTooltip = true;

@Tooltip
boolean explainRenderErrors = true;

float fanParticleDensity = .5f;

@Tooltip
boolean enableRainbowDebug = true;

@Tooltip
boolean experimentalRendering = true;

@Tooltip
int overlayOffsetX = 20;

@Tooltip
int overlayOffsetY = 0;

@Tooltip
boolean smoothPlacementIndicator = false;

@Override
public void validate() throws ConfigData.ValidationException {
fanParticleDensity = MathHelper.clamp(fanParticleDensity, 0f, 1f);
}
}
@@ -1,7 +1,10 @@
package com.simibubi.create.foundation.config;

import me.shedaniel.autoconfig.annotation.ConfigEntry;

public class CCommon {
boolean logTeErrors = false; // "Forward caught TileEntityExceptions to the log at debug level."
@ConfigEntry.Gui.Tooltip
boolean logBeErrors = false;
}

//public CWorldGen worldGen = nested(0, CWorldGen::new, Comments.worldGen); "Modify Create's impact on your terrain" todo
// TODO: public CWorldGen worldGen = nested(0, CWorldGen::new, Comments.worldGen); "Modify Create's impact on your terrain"
@@ -1,7 +1,15 @@
package com.simibubi.create.foundation.config;

public class CCuriosities {
static int maxSymmetryWandRange = 50; // min 10, "The Maximum Distance to an active mirror for the symmetry wand to trigger."
//static int zapperUndoLogLength = 10; // min 0, "The maximum amount of operations, a blockzapper can remember for undoing. (0 to disable undo)" NOT YET IMPLEMENTED UPSTREAM
}
import com.simibubi.create.foundation.config.util.Validatable;
import me.shedaniel.autoconfig.annotation.ConfigEntry;

public class CCuriosities implements Validatable {
@ConfigEntry.Gui.Tooltip
int maxSymmetryWandRange = 50; // min 10

@Override
public void validate() {
maxSymmetryWandRange = Math.max(maxSymmetryWandRange, 10);
}
//int zapperUndoLogLength = 10; // min 0, "The maximum amount of operations, a blockzapper can remember for undoing. (0 to disable undo)" NOT YET IMPLEMENTED UPSTREAM
}
34 changes: 28 additions & 6 deletions src/main/java/com/simibubi/create/foundation/config/CFluids.java
@@ -1,9 +1,31 @@
package com.simibubi.create.foundation.config;

public class CFluids {
static int fluidTankCapacity = 8; // min 1, "[in Buckets]" "The amount of liquid a tank can hold per block."
static int fluidTankMaxHeight = 32; // min 1, "[in Blocks]" "The maximum height a fluid tank can reach."
static int mechanicalPumpRange = 16; // min 1, "[in Blocks]" "The maximum distance a mechanical pump can push or pull liquids on either side."
static int hosePulleyBlockThreshold = 10000; // min -1, "[in Blocks]" "[-1 to disable this behaviour]" "The minimum amount of fluid blocks the hose pulley needs to find before deeming it an infinite source."
static int hosePulleyRange = 128; // min 1, "[in Blocks]" "The maximum distance a hose pulley can draw fluid blocks from."
import com.simibubi.create.foundation.config.util.Validatable;
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.ConfigEntry.Gui.Tooltip;

public class CFluids implements Validatable {
@Tooltip
int fluidTankCapacity = 8; // min 1, "[in Buckets]" "The amount of liquid a tank can hold per block."

@Tooltip
int fluidTankMaxHeight = 32; // min 1, "[in Blocks]" "The maximum height a fluid tank can reach."

@Tooltip
int mechanicalPumpRange = 16; // min 1, "[in Blocks]" "The maximum distance a mechanical pump can push or pull liquids on either side."

@Tooltip(count = 2)
int hosePulleyBlockThreshold = 10000; // min -1, "[in Blocks]" "[-1 to disable this behaviour]" "The minimum amount of fluid blocks the hose pulley needs to find before deeming it an infinite source."

@Tooltip
int hosePulleyRange = 128; // min 1, "[in Blocks]" "The maximum distance a hose pulley can draw fluid blocks from."

@Override
public void validate() throws ConfigData.ValidationException {
fluidTankCapacity = Math.max(fluidTankCapacity, 1);
fluidTankMaxHeight = Math.max(fluidTankMaxHeight, 1);
mechanicalPumpRange = Math.max(mechanicalPumpRange, 1);
hosePulleyBlockThreshold = Math.max(hosePulleyBlockThreshold, -1);
hosePulleyRange = Math.max(hosePulleyRange, 1);
}
}

0 comments on commit 8a4b812

Please sign in to comment.