Update to proper configs, as well as add no power requirement to machines
This commit is contained in:
@@ -1,7 +1,9 @@
|
|||||||
package net.cmr.jurassicrevived.block.custom;
|
package net.cmr.jurassicrevived.block.custom;
|
||||||
|
|
||||||
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
||||||
|
import net.cmr.jurassicrevived.block.entity.custom.GeneratorBlockEntity;
|
||||||
import net.cmr.jurassicrevived.block.entity.custom.PipeBlockEntity;
|
import net.cmr.jurassicrevived.block.entity.custom.PipeBlockEntity;
|
||||||
|
import net.cmr.jurassicrevived.block.entity.custom.PowerCellBlockEntity;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
||||||
import net.cmr.jurassicrevived.config.JRConfigManager;
|
import net.cmr.jurassicrevived.config.JRConfigManager;
|
||||||
import net.cmr.jurassicrevived.item.ModItems;
|
import net.cmr.jurassicrevived.item.ModItems;
|
||||||
@@ -195,7 +197,7 @@ public class PipeBlock extends Block implements EntityBlock, SimpleWaterloggedBl
|
|||||||
hasCommonConnection = switch (this.transport) {
|
hasCommonConnection = switch (this.transport) {
|
||||||
case ITEMS -> be instanceof Container;
|
case ITEMS -> be instanceof Container;
|
||||||
case FLUIDS -> false;
|
case FLUIDS -> false;
|
||||||
case ENERGY -> be instanceof ModEnergyUtil.EnergyProvider;
|
case ENERGY -> be instanceof ModEnergyUtil.EnergyProvider && canEnergyPipeConnectTo(be);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +205,7 @@ public class PipeBlock extends Block implements EntityBlock, SimpleWaterloggedBl
|
|||||||
boolean platformHasHandler = switch (this.transport) {
|
boolean platformHasHandler = switch (this.transport) {
|
||||||
case ITEMS -> Services.TRANSFER.getItemHandler(lvl, neighborPos, dir.getOpposite()).isPresent();
|
case ITEMS -> Services.TRANSFER.getItemHandler(lvl, neighborPos, dir.getOpposite()).isPresent();
|
||||||
case FLUIDS -> Services.TRANSFER.getFluidHandler(lvl, neighborPos, dir.getOpposite()).isPresent();
|
case FLUIDS -> Services.TRANSFER.getFluidHandler(lvl, neighborPos, dir.getOpposite()).isPresent();
|
||||||
case ENERGY -> Services.TRANSFER.getEnergyHandler(lvl, neighborPos, dir.getOpposite()).isPresent();
|
case ENERGY -> canEnergyPipeConnectTo(be) && Services.TRANSFER.getEnergyHandler(lvl, neighborPos, dir.getOpposite()).isPresent();
|
||||||
};
|
};
|
||||||
hasCommonConnection = hasCommonConnection || platformHasHandler;
|
hasCommonConnection = hasCommonConnection || platformHasHandler;
|
||||||
}
|
}
|
||||||
@@ -218,6 +220,17 @@ public class PipeBlock extends Block implements EntityBlock, SimpleWaterloggedBl
|
|||||||
return ConnectionType.NONE;
|
return ConnectionType.NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean canEnergyPipeConnectTo(@Nullable BlockEntity be) {
|
||||||
|
if (JRConfigManager.get().requirePower) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !(be instanceof ModEnergyUtil.EnergyProvider)
|
||||||
|
|| be instanceof GeneratorBlockEntity
|
||||||
|
|| be instanceof PowerCellBlockEntity
|
||||||
|
|| be instanceof PipeBlockEntity;
|
||||||
|
}
|
||||||
|
|
||||||
public static EnumProperty<ConnectionType> getProp(Direction dir) {
|
public static EnumProperty<ConnectionType> getProp(Direction dir) {
|
||||||
return switch (dir) {
|
return switch (dir) {
|
||||||
case DOWN -> DOWN;
|
case DOWN -> DOWN;
|
||||||
|
|||||||
+5
-2
@@ -5,6 +5,7 @@ import net.cmr.jurassicrevived.block.custom.DNAAnalyzerBlock;
|
|||||||
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
||||||
|
import net.cmr.jurassicrevived.config.JRConfigManager;
|
||||||
import net.cmr.jurassicrevived.item.ModItems;
|
import net.cmr.jurassicrevived.item.ModItems;
|
||||||
import net.cmr.jurassicrevived.recipe.DNAAnalyzerRecipe;
|
import net.cmr.jurassicrevived.recipe.DNAAnalyzerRecipe;
|
||||||
import net.cmr.jurassicrevived.recipe.DNAAnalyzerRecipeInput;
|
import net.cmr.jurassicrevived.recipe.DNAAnalyzerRecipeInput;
|
||||||
@@ -265,8 +266,10 @@ public class DNAAnalyzerBlockEntity extends BlockEntity implements ExtendedMenuP
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!lockedOutput.isEmpty() && canInsertOutput(lockedOutput)) {
|
if (!lockedOutput.isEmpty() && canInsertOutput(lockedOutput)) {
|
||||||
if (energyStorage.getEnergyStored() < 10) return;
|
if (JRConfigManager.get().requirePower) {
|
||||||
energyStorage.extractEnergy(10, false);
|
if (energyStorage.getEnergyStored() < 10) return;
|
||||||
|
energyStorage.extractEnergy(10, false);
|
||||||
|
}
|
||||||
|
|
||||||
progress++;
|
progress++;
|
||||||
level.setBlockAndUpdate(pos, state.setValue(DNAAnalyzerBlock.LIT, true));
|
level.setBlockAndUpdate(pos, state.setValue(DNAAnalyzerBlock.LIT, true));
|
||||||
|
|||||||
+5
-2
@@ -5,6 +5,7 @@ import net.cmr.jurassicrevived.block.custom.DNAExtractorBlock;
|
|||||||
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
||||||
|
import net.cmr.jurassicrevived.config.JRConfigManager;
|
||||||
import net.cmr.jurassicrevived.item.ModItems;
|
import net.cmr.jurassicrevived.item.ModItems;
|
||||||
import net.cmr.jurassicrevived.recipe.DNAExtractorRecipe;
|
import net.cmr.jurassicrevived.recipe.DNAExtractorRecipe;
|
||||||
import net.cmr.jurassicrevived.recipe.DNAExtractorRecipeInput;
|
import net.cmr.jurassicrevived.recipe.DNAExtractorRecipeInput;
|
||||||
@@ -263,8 +264,10 @@ public class DNAExtractorBlockEntity extends BlockEntity implements ExtendedMenu
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!lockedOutput.isEmpty() && canInsertOutput(lockedOutput)) {
|
if (!lockedOutput.isEmpty() && canInsertOutput(lockedOutput)) {
|
||||||
if (energyStorage.getEnergyStored() < 10) return;
|
if (JRConfigManager.get().requirePower) {
|
||||||
energyStorage.extractEnergy(10, false);
|
if (energyStorage.getEnergyStored() < 10) return;
|
||||||
|
energyStorage.extractEnergy(10, false);
|
||||||
|
}
|
||||||
|
|
||||||
progress++;
|
progress++;
|
||||||
level.setBlockAndUpdate(pos, state.setValue(DNAExtractorBlock.LIT, true));
|
level.setBlockAndUpdate(pos, state.setValue(DNAExtractorBlock.LIT, true));
|
||||||
|
|||||||
+5
-2
@@ -5,6 +5,7 @@ import net.cmr.jurassicrevived.block.custom.DNAHybridizerBlock;
|
|||||||
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
||||||
|
import net.cmr.jurassicrevived.config.JRConfigManager;
|
||||||
import net.cmr.jurassicrevived.recipe.DNAHybridizerRecipe;
|
import net.cmr.jurassicrevived.recipe.DNAHybridizerRecipe;
|
||||||
import net.cmr.jurassicrevived.recipe.DNAHybridizerRecipeInput;
|
import net.cmr.jurassicrevived.recipe.DNAHybridizerRecipeInput;
|
||||||
import net.cmr.jurassicrevived.recipe.ModRecipes;
|
import net.cmr.jurassicrevived.recipe.ModRecipes;
|
||||||
@@ -274,8 +275,10 @@ public class DNAHybridizerBlockEntity extends BlockEntity implements ExtendedMen
|
|||||||
boolean canProceed = exactMatch != null && !lockedOutput.isEmpty() && canInsertOutput(lockedOutput);
|
boolean canProceed = exactMatch != null && !lockedOutput.isEmpty() && canInsertOutput(lockedOutput);
|
||||||
|
|
||||||
if (canProceed) {
|
if (canProceed) {
|
||||||
if (energyStorage.getEnergyStored() < 10) return;
|
if (JRConfigManager.get().requirePower) {
|
||||||
energyStorage.extractEnergy(10, false);
|
if (energyStorage.getEnergyStored() < 10) return;
|
||||||
|
energyStorage.extractEnergy(10, false);
|
||||||
|
}
|
||||||
|
|
||||||
progress++;
|
progress++;
|
||||||
level.setBlockAndUpdate(pos, state.setValue(DNAHybridizerBlock.LIT, true));
|
level.setBlockAndUpdate(pos, state.setValue(DNAHybridizerBlock.LIT, true));
|
||||||
|
|||||||
+5
-2
@@ -5,6 +5,7 @@ import net.cmr.jurassicrevived.block.custom.EmbryoCalcificationMachineBlock;
|
|||||||
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
||||||
|
import net.cmr.jurassicrevived.config.JRConfigManager;
|
||||||
import net.cmr.jurassicrevived.recipe.EmbryoCalcificationMachineRecipe;
|
import net.cmr.jurassicrevived.recipe.EmbryoCalcificationMachineRecipe;
|
||||||
import net.cmr.jurassicrevived.recipe.EmbryoCalcificationMachineRecipeInput;
|
import net.cmr.jurassicrevived.recipe.EmbryoCalcificationMachineRecipeInput;
|
||||||
import net.cmr.jurassicrevived.recipe.ModRecipes;
|
import net.cmr.jurassicrevived.recipe.ModRecipes;
|
||||||
@@ -264,8 +265,10 @@ public class EmbryoCalcificationMachineBlockEntity extends BlockEntity implement
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!lockedOutput.isEmpty() && canInsertOutput(lockedOutput)) {
|
if (!lockedOutput.isEmpty() && canInsertOutput(lockedOutput)) {
|
||||||
if (energyStorage.getEnergyStored() < 10) return;
|
if (JRConfigManager.get().requirePower) {
|
||||||
energyStorage.extractEnergy(10, false);
|
if (energyStorage.getEnergyStored() < 10) return;
|
||||||
|
energyStorage.extractEnergy(10, false);
|
||||||
|
}
|
||||||
|
|
||||||
progress++;
|
progress++;
|
||||||
level.setBlockAndUpdate(pos, state.setValue(EmbryoCalcificationMachineBlock.LIT, true));
|
level.setBlockAndUpdate(pos, state.setValue(EmbryoCalcificationMachineBlock.LIT, true));
|
||||||
|
|||||||
+5
-2
@@ -5,6 +5,7 @@ import net.cmr.jurassicrevived.block.custom.EmbryonicMachineBlock;
|
|||||||
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
||||||
|
import net.cmr.jurassicrevived.config.JRConfigManager;
|
||||||
import net.cmr.jurassicrevived.item.ModItems;
|
import net.cmr.jurassicrevived.item.ModItems;
|
||||||
import net.cmr.jurassicrevived.recipe.EmbryonicMachineRecipe;
|
import net.cmr.jurassicrevived.recipe.EmbryonicMachineRecipe;
|
||||||
import net.cmr.jurassicrevived.recipe.EmbryonicMachineRecipeInput;
|
import net.cmr.jurassicrevived.recipe.EmbryonicMachineRecipeInput;
|
||||||
@@ -270,8 +271,10 @@ public class EmbryonicMachineBlockEntity extends BlockEntity implements Extended
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!lockedOutput.isEmpty() && canInsertOutput(lockedOutput)) {
|
if (!lockedOutput.isEmpty() && canInsertOutput(lockedOutput)) {
|
||||||
if (energyStorage.getEnergyStored() < 10) return;
|
if (JRConfigManager.get().requirePower) {
|
||||||
energyStorage.extractEnergy(10, false);
|
if (energyStorage.getEnergyStored() < 10) return;
|
||||||
|
energyStorage.extractEnergy(10, false);
|
||||||
|
}
|
||||||
|
|
||||||
progress++;
|
progress++;
|
||||||
level.setBlockAndUpdate(pos, state.setValue(EmbryonicMachineBlock.LIT, true));
|
level.setBlockAndUpdate(pos, state.setValue(EmbryonicMachineBlock.LIT, true));
|
||||||
|
|||||||
+5
-2
@@ -6,6 +6,7 @@ import net.cmr.jurassicrevived.block.custom.FossilCleanerBlock;
|
|||||||
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
||||||
|
import net.cmr.jurassicrevived.config.JRConfigManager;
|
||||||
import net.cmr.jurassicrevived.recipe.FossilCleanerRecipe;
|
import net.cmr.jurassicrevived.recipe.FossilCleanerRecipe;
|
||||||
import net.cmr.jurassicrevived.recipe.FossilCleanerRecipeInput;
|
import net.cmr.jurassicrevived.recipe.FossilCleanerRecipeInput;
|
||||||
import net.cmr.jurassicrevived.recipe.ModRecipes;
|
import net.cmr.jurassicrevived.recipe.ModRecipes;
|
||||||
@@ -289,8 +290,10 @@ public class FossilCleanerBlockEntity extends BlockEntity implements ExtendedMen
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!lockedOutput.isEmpty() && canInsertOutput(lockedOutput) && fluidStack.getAmount() >= WATER_CRAFT_AMOUNT) {
|
if (!lockedOutput.isEmpty() && canInsertOutput(lockedOutput) && fluidStack.getAmount() >= WATER_CRAFT_AMOUNT) {
|
||||||
if (energyStorage.getEnergyStored() < 10) return;
|
if (JRConfigManager.get().requirePower) {
|
||||||
energyStorage.extractEnergy(10, false);
|
if (energyStorage.getEnergyStored() < 10) return;
|
||||||
|
energyStorage.extractEnergy(10, false);
|
||||||
|
}
|
||||||
|
|
||||||
progress++;
|
progress++;
|
||||||
level.setBlockAndUpdate(pos, state.setValue(FossilCleanerBlock.LIT, true));
|
level.setBlockAndUpdate(pos, state.setValue(FossilCleanerBlock.LIT, true));
|
||||||
|
|||||||
+5
-2
@@ -5,6 +5,7 @@ import net.cmr.jurassicrevived.block.custom.FossilGrinderBlock;
|
|||||||
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
||||||
|
import net.cmr.jurassicrevived.config.JRConfigManager;
|
||||||
import net.cmr.jurassicrevived.recipe.FossilGrinderRecipe;
|
import net.cmr.jurassicrevived.recipe.FossilGrinderRecipe;
|
||||||
import net.cmr.jurassicrevived.recipe.FossilGrinderRecipeInput;
|
import net.cmr.jurassicrevived.recipe.FossilGrinderRecipeInput;
|
||||||
import net.cmr.jurassicrevived.recipe.ModRecipes;
|
import net.cmr.jurassicrevived.recipe.ModRecipes;
|
||||||
@@ -271,8 +272,10 @@ public class FossilGrinderBlockEntity extends BlockEntity implements ExtendedMen
|
|||||||
boolean canOutput = !output.isEmpty() && canInsertOutput(output);
|
boolean canOutput = !output.isEmpty() && canInsertOutput(output);
|
||||||
|
|
||||||
if (canOutput) {
|
if (canOutput) {
|
||||||
if (energyStorage.getEnergyStored() < 10) return;
|
if (JRConfigManager.get().requirePower) {
|
||||||
energyStorage.extractEnergy(10, false);
|
if (energyStorage.getEnergyStored() < 10) return;
|
||||||
|
energyStorage.extractEnergy(10, false);
|
||||||
|
}
|
||||||
|
|
||||||
progress++;
|
progress++;
|
||||||
level.setBlockAndUpdate(pos, state.setValue(FossilGrinderBlock.LIT, true));
|
level.setBlockAndUpdate(pos, state.setValue(FossilGrinderBlock.LIT, true));
|
||||||
|
|||||||
+5
-2
@@ -5,6 +5,7 @@ import net.cmr.jurassicrevived.block.custom.IncubatorBlock;
|
|||||||
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
import net.cmr.jurassicrevived.block.entity.ModBlockEntities;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyStorage;
|
||||||
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
import net.cmr.jurassicrevived.block.entity.energy.ModEnergyUtil;
|
||||||
|
import net.cmr.jurassicrevived.config.JRConfigManager;
|
||||||
import net.cmr.jurassicrevived.recipe.IncubatorRecipe;
|
import net.cmr.jurassicrevived.recipe.IncubatorRecipe;
|
||||||
import net.cmr.jurassicrevived.recipe.IncubatorRecipeInput;
|
import net.cmr.jurassicrevived.recipe.IncubatorRecipeInput;
|
||||||
import net.cmr.jurassicrevived.recipe.ModRecipes;
|
import net.cmr.jurassicrevived.recipe.ModRecipes;
|
||||||
@@ -280,8 +281,10 @@ public class IncubatorBlockEntity extends BlockEntity implements ExtendedMenuPro
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (anyActive) {
|
if (anyActive) {
|
||||||
if (energyStorage.getEnergyStored() < 10) return;
|
if (JRConfigManager.get().requirePower) {
|
||||||
energyStorage.extractEnergy(10, false);
|
if (energyStorage.getEnergyStored() < 10) return;
|
||||||
|
energyStorage.extractEnergy(10, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int s = 0; s < 3; s++) {
|
for (int s = 0; s < 3; s++) {
|
||||||
|
|||||||
@@ -1,14 +1,33 @@
|
|||||||
package net.cmr.jurassicrevived.config;
|
package net.cmr.jurassicrevived.config;
|
||||||
|
|
||||||
public final class JRConfig {
|
public final class JRConfig {
|
||||||
// Example options (replace with your real ones)
|
/**
|
||||||
public boolean enableDinosaurs = true;
|
* When false, machines do not require/consume power, machine GUIs hide their power bars,
|
||||||
public int spawnWeight = 10;
|
* and energy pipes do not connect to machines. Generator and power cell behavior is unchanged.
|
||||||
public boolean requirePower = true;
|
*/
|
||||||
public int fePerSecond = 1000;
|
public boolean requirePower = true;
|
||||||
public int itemsPerSecond = 100;
|
|
||||||
public int milliBucketsPerSecond = 1000;
|
|
||||||
|
|
||||||
public JRConfig() {
|
/**
|
||||||
}
|
* Controls whether dinosaurs should naturally spawn.
|
||||||
|
* Entity spawning is not implemented yet, but future spawn code should read this.
|
||||||
|
*/
|
||||||
|
public boolean naturallySpawning = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Energy pipe transfer rate in FE per second.
|
||||||
|
*/
|
||||||
|
public int fePerSecond = 1000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Item pipe transfer rate in items per second.
|
||||||
|
*/
|
||||||
|
public int itemsPerSecond = 100;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fluid pipe transfer rate in milliBuckets per second.
|
||||||
|
*/
|
||||||
|
public int milliBucketsPerSecond = 1000;
|
||||||
|
|
||||||
|
public JRConfig() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,16 @@ public final class JRConfigManager {
|
|||||||
// For now: keep it simple and non-fatal.
|
// For now: keep it simple and non-fatal.
|
||||||
try {
|
try {
|
||||||
String text = Files.readString(file, StandardCharsets.UTF_8);
|
String text = Files.readString(file, StandardCharsets.UTF_8);
|
||||||
// TODO: parse JSON into config (Gson recommended)
|
JRConfig loaded = new JRConfig();
|
||||||
// config = parsed;
|
|
||||||
|
loaded.requirePower = readBoolean(text, "requirePower", loaded.requirePower);
|
||||||
|
loaded.naturallySpawning = readBoolean(text, "naturallySpawning", loaded.naturallySpawning);
|
||||||
|
loaded.fePerSecond = readPositiveInt(text, "fePerSecond", loaded.fePerSecond);
|
||||||
|
loaded.itemsPerSecond = readPositiveInt(text, "itemsPerSecond", loaded.itemsPerSecond);
|
||||||
|
loaded.milliBucketsPerSecond = readPositiveInt(text, "milliBucketsPerSecond", loaded.milliBucketsPerSecond);
|
||||||
|
|
||||||
|
config = loaded;
|
||||||
|
save(configDir);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// Keep defaults if load fails
|
// Keep defaults if load fails
|
||||||
}
|
}
|
||||||
@@ -40,10 +48,12 @@ public final class JRConfigManager {
|
|||||||
Files.createDirectories(configDir);
|
Files.createDirectories(configDir);
|
||||||
Path file = configDir.resolve("jurassicrevived.json");
|
Path file = configDir.resolve("jurassicrevived.json");
|
||||||
|
|
||||||
// TODO: write JSON (Gson recommended)
|
|
||||||
String text = "{\n" +
|
String text = "{\n" +
|
||||||
" \"enableDinosaurs\": " + config.enableDinosaurs + ",\n" +
|
" \"requirePower\": " + config.requirePower + ",\n" +
|
||||||
" \"spawnWeight\": " + config.spawnWeight + "\n" +
|
" \"naturallySpawning\": " + config.naturallySpawning + ",\n" +
|
||||||
|
" \"fePerSecond\": " + config.fePerSecond + ",\n" +
|
||||||
|
" \"itemsPerSecond\": " + config.itemsPerSecond + ",\n" +
|
||||||
|
" \"milliBucketsPerSecond\": " + config.milliBucketsPerSecond + "\n" +
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
Files.writeString(file, text, StandardCharsets.UTF_8);
|
Files.writeString(file, text, StandardCharsets.UTF_8);
|
||||||
@@ -51,4 +61,45 @@ public final class JRConfigManager {
|
|||||||
// ignore / log via your logger if desired
|
// ignore / log via your logger if desired
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean readBoolean(String text, String key, boolean fallback) {
|
||||||
|
String value = readRawValue(text, key);
|
||||||
|
if ("true".equalsIgnoreCase(value)) return true;
|
||||||
|
if ("false".equalsIgnoreCase(value)) return false;
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int readPositiveInt(String text, String key, int fallback) {
|
||||||
|
String value = readRawValue(text, key);
|
||||||
|
if (value == null) return fallback;
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Math.max(1, Integer.parseInt(value));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String readRawValue(String text, String key) {
|
||||||
|
String quotedKey = "\"" + key + "\"";
|
||||||
|
int keyIndex = text.indexOf(quotedKey);
|
||||||
|
if (keyIndex < 0) return null;
|
||||||
|
|
||||||
|
int colonIndex = text.indexOf(':', keyIndex + quotedKey.length());
|
||||||
|
if (colonIndex < 0) return null;
|
||||||
|
|
||||||
|
int valueStart = colonIndex + 1;
|
||||||
|
while (valueStart < text.length() && Character.isWhitespace(text.charAt(valueStart))) {
|
||||||
|
valueStart++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int valueEnd = valueStart;
|
||||||
|
while (valueEnd < text.length()) {
|
||||||
|
char c = text.charAt(valueEnd);
|
||||||
|
if (c == ',' || c == '\n' || c == '\r' || c == '}') break;
|
||||||
|
valueEnd++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return text.substring(valueStart, valueEnd).trim();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+42
-7
@@ -23,18 +23,53 @@ public final class JRClothConfigScreens {
|
|||||||
ConfigEntryBuilder eb = builder.entryBuilder();
|
ConfigEntryBuilder eb = builder.entryBuilder();
|
||||||
|
|
||||||
general.addEntry(
|
general.addEntry(
|
||||||
eb.startBooleanToggle(Component.literal("Enable Dinosaurs"), cfg.enableDinosaurs)
|
eb.startBooleanToggle(Component.literal("Require Power"), cfg.requirePower)
|
||||||
.setDefaultValue(true)
|
.setDefaultValue(true)
|
||||||
.setSaveConsumer(v -> cfg.enableDinosaurs = v)
|
.setTooltip(Component.literal("When disabled, machines do not consume power, hide power bars, and energy pipes do not connect to machines."))
|
||||||
|
.setSaveConsumer(v -> cfg.requirePower = v)
|
||||||
|
.requireRestart()
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
general.addEntry(
|
general.addEntry(
|
||||||
eb.startIntField(Component.literal("Spawn Weight"), cfg.spawnWeight)
|
eb.startBooleanToggle(Component.literal("Naturally Spawning Dinosaurs"), cfg.naturallySpawning)
|
||||||
.setDefaultValue(10)
|
.setDefaultValue(false)
|
||||||
.setMin(0)
|
.setTooltip(Component.literal("Controls whether dinosaurs naturally spawn once entity spawning is implemented."))
|
||||||
.setMax(1000)
|
.setSaveConsumer(v -> cfg.naturallySpawning = v)
|
||||||
.setSaveConsumer(v -> cfg.spawnWeight = v)
|
.requireRestart()
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
general.addEntry(
|
||||||
|
eb.startIntField(Component.literal("FE Per Second"), cfg.fePerSecond)
|
||||||
|
.setDefaultValue(1000)
|
||||||
|
.setMin(1)
|
||||||
|
.setMax(Integer.MAX_VALUE)
|
||||||
|
.setTooltip(Component.literal("Energy pipe transfer rate in FE per second."))
|
||||||
|
.setSaveConsumer(v -> cfg.fePerSecond = Math.max(1, v))
|
||||||
|
.requireRestart()
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
general.addEntry(
|
||||||
|
eb.startIntField(Component.literal("Items Per Second"), cfg.itemsPerSecond)
|
||||||
|
.setDefaultValue(100)
|
||||||
|
.setMin(1)
|
||||||
|
.setMax(Integer.MAX_VALUE)
|
||||||
|
.setTooltip(Component.literal("Item pipe transfer rate in items per second."))
|
||||||
|
.setSaveConsumer(v -> cfg.itemsPerSecond = Math.max(1, v))
|
||||||
|
.requireRestart()
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
general.addEntry(
|
||||||
|
eb.startIntField(Component.literal("MilliBuckets Per Second"), cfg.milliBucketsPerSecond)
|
||||||
|
.setDefaultValue(1000)
|
||||||
|
.setMin(1)
|
||||||
|
.setMax(Integer.MAX_VALUE)
|
||||||
|
.setTooltip(Component.literal("Fluid pipe transfer rate in milliBuckets per second."))
|
||||||
|
.setSaveConsumer(v -> cfg.milliBucketsPerSecond = Math.max(1, v))
|
||||||
|
.requireRestart()
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
+42
-7
@@ -23,18 +23,53 @@ public final class JRClothConfigScreens {
|
|||||||
ConfigEntryBuilder eb = builder.entryBuilder();
|
ConfigEntryBuilder eb = builder.entryBuilder();
|
||||||
|
|
||||||
general.addEntry(
|
general.addEntry(
|
||||||
eb.startBooleanToggle(Component.literal("Enable Dinosaurs"), cfg.enableDinosaurs)
|
eb.startBooleanToggle(Component.literal("Require Power"), cfg.requirePower)
|
||||||
.setDefaultValue(true)
|
.setDefaultValue(true)
|
||||||
.setSaveConsumer(v -> cfg.enableDinosaurs = v)
|
.setTooltip(Component.literal("When disabled, machines do not consume power, hide power bars, and energy pipes do not connect to machines."))
|
||||||
|
.setSaveConsumer(v -> cfg.requirePower = v)
|
||||||
|
.requireRestart()
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
general.addEntry(
|
general.addEntry(
|
||||||
eb.startIntField(Component.literal("Spawn Weight"), cfg.spawnWeight)
|
eb.startBooleanToggle(Component.literal("Naturally Spawning Dinosaurs"), cfg.naturallySpawning)
|
||||||
.setDefaultValue(10)
|
.setDefaultValue(false)
|
||||||
.setMin(0)
|
.setTooltip(Component.literal("Controls whether dinosaurs naturally spawn once entity spawning is implemented."))
|
||||||
.setMax(1000)
|
.setSaveConsumer(v -> cfg.naturallySpawning = v)
|
||||||
.setSaveConsumer(v -> cfg.spawnWeight = v)
|
.requireRestart()
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
general.addEntry(
|
||||||
|
eb.startIntField(Component.literal("FE Per Second"), cfg.fePerSecond)
|
||||||
|
.setDefaultValue(1000)
|
||||||
|
.setMin(1)
|
||||||
|
.setMax(Integer.MAX_VALUE)
|
||||||
|
.setTooltip(Component.literal("Energy pipe transfer rate in FE per second."))
|
||||||
|
.setSaveConsumer(v -> cfg.fePerSecond = Math.max(1, v))
|
||||||
|
.requireRestart()
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
general.addEntry(
|
||||||
|
eb.startIntField(Component.literal("Items Per Second"), cfg.itemsPerSecond)
|
||||||
|
.setDefaultValue(100)
|
||||||
|
.setMin(1)
|
||||||
|
.setMax(Integer.MAX_VALUE)
|
||||||
|
.setTooltip(Component.literal("Item pipe transfer rate in items per second."))
|
||||||
|
.setSaveConsumer(v -> cfg.itemsPerSecond = Math.max(1, v))
|
||||||
|
.requireRestart()
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
general.addEntry(
|
||||||
|
eb.startIntField(Component.literal("MilliBuckets Per Second"), cfg.milliBucketsPerSecond)
|
||||||
|
.setDefaultValue(1000)
|
||||||
|
.setMin(1)
|
||||||
|
.setMax(Integer.MAX_VALUE)
|
||||||
|
.setTooltip(Component.literal("Fluid pipe transfer rate in milliBuckets per second."))
|
||||||
|
.setSaveConsumer(v -> cfg.milliBucketsPerSecond = Math.max(1, v))
|
||||||
|
.requireRestart()
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
+42
-7
@@ -23,18 +23,53 @@ public final class JRClothConfigScreens {
|
|||||||
ConfigEntryBuilder eb = builder.entryBuilder();
|
ConfigEntryBuilder eb = builder.entryBuilder();
|
||||||
|
|
||||||
general.addEntry(
|
general.addEntry(
|
||||||
eb.startBooleanToggle(Component.literal("Enable Dinosaurs"), cfg.enableDinosaurs)
|
eb.startBooleanToggle(Component.literal("Require Power"), cfg.requirePower)
|
||||||
.setDefaultValue(true)
|
.setDefaultValue(true)
|
||||||
.setSaveConsumer(v -> cfg.enableDinosaurs = v)
|
.setTooltip(Component.literal("When disabled, machines do not consume power, hide power bars, and energy pipes do not connect to machines."))
|
||||||
|
.setSaveConsumer(v -> cfg.requirePower = v)
|
||||||
|
.requireRestart()
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
general.addEntry(
|
general.addEntry(
|
||||||
eb.startIntField(Component.literal("Spawn Weight"), cfg.spawnWeight)
|
eb.startBooleanToggle(Component.literal("Naturally Spawning Dinosaurs"), cfg.naturallySpawning)
|
||||||
.setDefaultValue(10)
|
.setDefaultValue(false)
|
||||||
.setMin(0)
|
.setTooltip(Component.literal("Controls whether dinosaurs naturally spawn once entity spawning is implemented."))
|
||||||
.setMax(1000)
|
.setSaveConsumer(v -> cfg.naturallySpawning = v)
|
||||||
.setSaveConsumer(v -> cfg.spawnWeight = v)
|
.requireRestart()
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
general.addEntry(
|
||||||
|
eb.startIntField(Component.literal("FE Per Second"), cfg.fePerSecond)
|
||||||
|
.setDefaultValue(1000)
|
||||||
|
.setMin(1)
|
||||||
|
.setMax(Integer.MAX_VALUE)
|
||||||
|
.setTooltip(Component.literal("Energy pipe transfer rate in FE per second."))
|
||||||
|
.setSaveConsumer(v -> cfg.fePerSecond = Math.max(1, v))
|
||||||
|
.requireRestart()
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
general.addEntry(
|
||||||
|
eb.startIntField(Component.literal("Items Per Second"), cfg.itemsPerSecond)
|
||||||
|
.setDefaultValue(100)
|
||||||
|
.setMin(1)
|
||||||
|
.setMax(Integer.MAX_VALUE)
|
||||||
|
.setTooltip(Component.literal("Item pipe transfer rate in items per second."))
|
||||||
|
.setSaveConsumer(v -> cfg.itemsPerSecond = Math.max(1, v))
|
||||||
|
.requireRestart()
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
|
||||||
|
general.addEntry(
|
||||||
|
eb.startIntField(Component.literal("MilliBuckets Per Second"), cfg.milliBucketsPerSecond)
|
||||||
|
.setDefaultValue(1000)
|
||||||
|
.setMin(1)
|
||||||
|
.setMax(Integer.MAX_VALUE)
|
||||||
|
.setTooltip(Component.literal("Fluid pipe transfer rate in milliBuckets per second."))
|
||||||
|
.setSaveConsumer(v -> cfg.milliBucketsPerSecond = Math.max(1, v))
|
||||||
|
.requireRestart()
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user