diff --git a/build.gradle b/build.gradle index a8efc8935..bbde7129e 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ archivesBaseName = 'create' sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' minecraft { - mappings channel: 'snapshot', version: '20190902-1.14.3' + mappings channel: 'snapshot', version: '20190910-1.14.3' runs { client { @@ -58,7 +58,7 @@ minecraft { } dependencies { - minecraft 'net.minecraftforge:forge:1.14.4-28.0.83' + minecraft 'net.minecraftforge:forge:1.14.4-28.0.102' } jar { diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index 975a01f43..bee4ee78c 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -14,9 +14,11 @@ import net.minecraft.item.ItemGroup; import net.minecraft.item.crafting.IRecipeSerializer; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; +import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; +import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; @EventBusSubscriber(bus = Bus.MOD) @@ -34,13 +36,19 @@ public class Create { public static InWorldItemProcessingHandler itemProcessingHandler; public static MovingConstructHandler constructHandler; + public static ModConfig config; + + public Create() { + ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, CreateConfig.specification); + ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, CreateClientConfig.specification); + } + @SubscribeEvent public static void init(final FMLCommonSetupEvent event) { schematicReceiver = new ServerSchematicLoader(); itemProcessingHandler = new InWorldItemProcessingHandler(); frequencyHandler = new FrequencyHandler(); constructHandler = new MovingConstructHandler(); - AllPackets.registerPackets(); } @@ -59,7 +67,15 @@ public class Create { public static void registerRecipes(RegistryEvent.Register> event) { AllRecipes.register(event); } - + + @SubscribeEvent + public static void createConfigs(ModConfig.ModConfigEvent event) { + if (event.getConfig().getSpec() == CreateClientConfig.specification) + return; + + config = event.getConfig(); + } + public static void tick() { schematicReceiver.tick(); } diff --git a/src/main/java/com/simibubi/create/CreateClient.java b/src/main/java/com/simibubi/create/CreateClient.java index 80d020ca8..0281389f6 100644 --- a/src/main/java/com/simibubi/create/CreateClient.java +++ b/src/main/java/com/simibubi/create/CreateClient.java @@ -5,13 +5,13 @@ import com.simibubi.create.modules.schematics.client.SchematicAndQuillHandler; import com.simibubi.create.modules.schematics.client.SchematicHandler; import com.simibubi.create.modules.schematics.client.SchematicHologram; -import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; +import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; -@EventBusSubscriber(value = Dist.CLIENT, bus = Bus.MOD) +@EventBusSubscriber(bus = Bus.MOD) public class CreateClient { public static ClientSchematicLoader schematicSender; @@ -19,18 +19,28 @@ public class CreateClient { public static SchematicHologram schematicHologram; public static SchematicAndQuillHandler schematicAndQuillHandler; + public static ModConfig config; + @SubscribeEvent public static void clientInit(FMLClientSetupEvent event) { schematicSender = new ClientSchematicLoader(); schematicHandler = new SchematicHandler(); schematicHologram = new SchematicHologram(); schematicAndQuillHandler = new SchematicAndQuillHandler(); - + AllKeys.register(); AllContainers.registerScreenFactories(); AllTileEntities.registerRenderers(); AllItems.registerColorHandlers(); } + + @SubscribeEvent + public static void createConfigs(ModConfig.ModConfigEvent event) { + if (event.getConfig().getSpec() == CreateConfig.specification) + return; + + config = event.getConfig(); + } public static void gameTick() { schematicSender.tick(); diff --git a/src/main/java/com/simibubi/create/CreateClientConfig.java b/src/main/java/com/simibubi/create/CreateClientConfig.java new file mode 100644 index 000000000..9384f5b31 --- /dev/null +++ b/src/main/java/com/simibubi/create/CreateClientConfig.java @@ -0,0 +1,26 @@ +package com.simibubi.create; + +import org.apache.commons.lang3.tuple.Pair; + +import net.minecraftforge.common.ForgeConfigSpec; + +public class CreateClientConfig { + + public static final ForgeConfigSpec specification; + public static final CreateClientConfig instance; + + static { + final Pair specPair = new ForgeConfigSpec.Builder() + .configure(CreateClientConfig::new); + + specification = specPair.getRight(); + instance = specPair.getLeft(); + } + + CreateClientConfig(final ForgeConfigSpec.Builder builder) { + builder.comment("Client-only settings").push("client"); + + builder.pop(); + } + +} diff --git a/src/main/java/com/simibubi/create/CreateConfig.java b/src/main/java/com/simibubi/create/CreateConfig.java new file mode 100644 index 000000000..6c724a593 --- /dev/null +++ b/src/main/java/com/simibubi/create/CreateConfig.java @@ -0,0 +1,257 @@ +package com.simibubi.create; + +import java.nio.file.InvalidPathException; +import java.nio.file.Paths; + +import org.apache.commons.lang3.tuple.Pair; + +import net.minecraftforge.common.ForgeConfigSpec; +import net.minecraftforge.common.ForgeConfigSpec.Builder; +import net.minecraftforge.common.ForgeConfigSpec.ConfigValue; +import net.minecraftforge.common.ForgeConfigSpec.DoubleValue; +import net.minecraftforge.common.ForgeConfigSpec.IntValue; + +public class CreateConfig { + + public static final ForgeConfigSpec specification; + public static final CreateConfig parameters; + + static { + final Pair specPair = new ForgeConfigSpec.Builder().configure(CreateConfig::new); + + specification = specPair.getRight(); + parameters = specPair.getLeft(); + } + + // Schematics + public IntValue maxSchematics, maxTotalSchematicSize, maxSchematicPacketSize, schematicIdleTimeout; + public IntValue schematicannonDelay, schematicannonSkips; + public DoubleValue schematicannonGunpowderWorth, schematicannonFuelUsage; + public ConfigValue schematicPath; + + // Curiosities + public IntValue maxSymmetryWandRange; + + // Contraptions + public IntValue maxBeltLength, crushingDamage, maxMotorSpeed, maxRotationSpeed; + public IntValue fanMaxPushDistance, fanMaxPullDistance, fanBlockCheckRate, fanRotationArgmax; + public IntValue maxChassisForTranslation, maxChassisForRotation, maxChassisRange, maxPistonPoles; + + // Logistics + public IntValue extractorDelay, extractorAmount, linkRange; + + // Gardens + public DoubleValue cocoaLogGrowthSpeed; + + CreateConfig(final ForgeConfigSpec.Builder builder) { + + // Schematics + initSchematics(builder); + initContraptions(builder); + initCuriosities(builder); + initLogistics(builder); + initGardens(builder); + } + + private void initGardens(Builder builder) { + builder.comment("The Gardens Module").push("gardens"); + String basePath = "create.config.gardens"; + String name = ""; + + name = "cocoaLogGrowthSpeed"; + cocoaLogGrowthSpeed = builder + .comment("", "% of random Ticks causing a Cocoa log to grow.") + .translation(basePath + name).defineInRange(name, 0D, 20D, 100D); + + builder.pop(); + } + + private void initLogistics(Builder builder) { + builder.comment("The Logistics Module").push("logistics"); + String basePath = "create.config.logistics"; + String name = ""; + + name = "extractorDelay"; + extractorDelay = builder + .comment("", "The amount of game ticks an Extractor waits after pulling an item successfully.") + .translation(basePath + name).defineInRange(name, 20, 1, Integer.MAX_VALUE); + + name = "extractorAmount"; + extractorAmount = builder + .comment("", "The amount of items an extractor pulls at a time without an applied filter.") + .translation(basePath + name).defineInRange(name, 16, 1, 64); + + name = "linkRange"; + linkRange = builder + .comment("", "Maximum possible range in blocks of redstone link connections.") + .translation(basePath + name).defineInRange(name, 128, 4, Integer.MAX_VALUE); + + builder.pop(); + } + + private void initContraptions(Builder builder) { + builder.comment("The Contraptions Module").push("contraptions"); + String basePath = "create.config.contraptions"; + String name = ""; + + name = "maxBeltLength"; + maxBeltLength = builder + .comment("", "Maximum length in blocks of mechanical belts.") + .translation(basePath + name).defineInRange(name, 20, 5, Integer.MAX_VALUE); + + name = "crushingDamage"; + crushingDamage = builder + .comment("", "Damage dealt by active Crushing Wheels.") + .translation(basePath + name).defineInRange(name, 4, 0, Integer.MAX_VALUE); + + { + builder.comment("Encased Fan").push("encasedFan"); + basePath = "create.config.contraptions.encasedFan"; + + name = "fanBlockCheckRate"; + fanBlockCheckRate = builder + .comment("", "Game ticks between Fans checking for anything blocking their air flow.") + .translation(basePath + name).defineInRange(name, 100, 20, Integer.MAX_VALUE); + + name = "fanMaxPushDistance"; + fanMaxPushDistance = builder + .comment("", "Maximum distance in blocks Fans can push entities.") + .translation(basePath + name).defineInRange(name, 20, 1, Integer.MAX_VALUE); + + name = "fanMaxPullDistance"; + fanMaxPullDistance = builder + .comment("", "Maximum distance in blocks from where Fans can pull entities.") + .translation(basePath + name).defineInRange(name, 5, 1, Integer.MAX_VALUE); + + name = "fanRotationArgmax"; + fanRotationArgmax = builder + .comment("", "Rotation speed at which the maximum stats of fans are reached.") + .translation(basePath + name).defineInRange(name, 8192, 64, Integer.MAX_VALUE); + + + builder.pop(); + } + + { + builder.comment("Mechanical Pistons and Bearings").push("constructs"); + basePath = "create.config.contraptions.constructs"; + + name = "maxChassisRange"; + maxChassisRange = builder + .comment("", "Maximum value of a chassis attachment range.") + .translation(basePath + name).defineInRange(name, 16, 1, Integer.MAX_VALUE); + + name = "maxChassisForRotation"; + maxChassisForRotation = builder + .comment("", "Maximum amount of chassis blocks movable by a Mechanical Bearing.") + .translation(basePath + name).defineInRange(name, 16, 1, Integer.MAX_VALUE); + + name = "maxChassisForTranslation"; + maxChassisForTranslation = builder + .comment("", "Maximum amount of chassis blocks movable by a Mechanical Piston.") + .translation(basePath + name).defineInRange(name, 16, 1, Integer.MAX_VALUE); + + name = "maxPistonPoles"; + maxPistonPoles = builder + .comment("", "Maximum amount of extension poles behind a Mechanical Piston.") + .translation(basePath + name).defineInRange(name, 64, 1, Integer.MAX_VALUE); + + builder.pop(); + } + + name = "maxMotorSpeed"; + maxMotorSpeed = builder + .comment("", "Maximum allowed speed of a configurable motor.") + .translation(basePath + name).defineInRange(name, 4096, 64, Integer.MAX_VALUE); + + name = "maxRotationSpeed"; + maxRotationSpeed = builder + .comment("", "Maximum allowed rotation speed for any Kinetic Tile.") + .translation(basePath + name).defineInRange(name, 16384, 64, Integer.MAX_VALUE); + + builder.pop(); + } + + private void initCuriosities(Builder builder) { + builder.comment("The Curiosities Module").push("curiosities"); + String basePath = "create.config.curiosities"; + String name = ""; + + name = "maxSymmetryWandRange"; + maxSymmetryWandRange = builder + .comment("", "The Maximum Distance to an active mirror for the symmetry wand to trigger.") + .translation(basePath + name).defineInRange(name, 50, 10, Integer.MAX_VALUE); + + builder.pop(); + } + + public void initSchematics(final ForgeConfigSpec.Builder builder) { + builder.comment("The Schematics Module").push("schematics"); + String basePath = "create.config.schematics"; + String name = ""; + + name = "maxSchematics"; + maxSchematics = builder + .comment("", "The amount of Schematics a player can upload until previous ones are overwritten.") + .translation(basePath + name).defineInRange(name, 10, 1, Integer.MAX_VALUE); + + name = "schematicPath"; + schematicPath = builder.comment("", "The file location where uploaded Schematics are stored.").define(name, + "schematics/uploaded", this::isValidPath); + + name = "maxTotalSchematicSize"; + maxTotalSchematicSize = builder + .comment("", "[in KiloBytes]", "The maximum allowed file size of uploaded Schematics.") + .translation(basePath + name).defineInRange(name, 256, 16, Integer.MAX_VALUE); + + name = "maxSchematicPacketSize"; + maxSchematicPacketSize = builder + .comment("", "[in Bytes]", "The maximum packet size uploaded Schematics are split into.") + .translation(basePath + name).defineInRange(name, 1024, 256, 32767); + + name = "schematicIdleTimeout"; + schematicIdleTimeout = builder.comment("", + "Amount of game ticks without new packets arriving until an active schematic upload process is discarded.") + .translation(basePath + name).defineInRange(name, 600, 100, Integer.MAX_VALUE); + + { + builder.comment("Schematicannon").push("schematicannon"); + basePath = "create.config.schematics.schematicannon"; + + name = "schematicannonDelay"; + schematicannonDelay = builder.comment("", + "Amount of game ticks between shots of the cannon. Higher => Slower") + .translation(basePath + name).defineInRange(name, 10, 1, Integer.MAX_VALUE); + + name = "schematicannonSkips"; + schematicannonSkips = builder.comment("", + "Amount of block positions per tick scanned by a running cannon. Higher => Faster") + .translation(basePath + name).defineInRange(name, 10, 1, Integer.MAX_VALUE); + + name = "schematicannonGunpowderWorth"; + schematicannonGunpowderWorth = builder.comment("", + "% of Schematicannon's Fuel filled by 1 Gunpowder.") + .translation(basePath + name).defineInRange(name, 20D, 0D, 100D); + + name = "schematicannonFuelUsage"; + schematicannonFuelUsage = builder.comment("", + "% of Schematicannon's Fuel used for each fired block.") + .translation(basePath + name).defineInRange(name, 0.05D, 0D, 100D); + builder.pop(); + } + + builder.pop(); + } + + private boolean isValidPath(Object path) { + if (!(path instanceof String)) + return false; + try { + Paths.get((String) path); + return true; + } catch (InvalidPathException e) { + return false; + } + } + +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/FilesHelper.java b/src/main/java/com/simibubi/create/foundation/utility/FilesHelper.java index 7bcd04bbc..2ab097e60 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/FilesHelper.java +++ b/src/main/java/com/simibubi/create/foundation/utility/FilesHelper.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.file.Files; +import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; @@ -22,9 +23,13 @@ import net.minecraft.nbt.JsonToNBT; public class FilesHelper { public static void createFolderIfMissing(String name) { - if (!Files.isDirectory(Paths.get(name))) { + Path path = Paths.get(name); + if (path.getParent() != null) + createFolderIfMissing(path.getParent().toString()); + + if (!Files.isDirectory(path)) { try { - Files.createDirectory(Paths.get(name)); + Files.createDirectory(path); } catch (IOException e) { Create.logger.warn("Could not create Folder: " + name); } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java b/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java index 2cef8f30f..50b6f2798 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/RotationPropagator.java @@ -1,5 +1,7 @@ package com.simibubi.create.modules.contraptions; +import static com.simibubi.create.CreateConfig.parameters; + import java.util.LinkedList; import java.util.List; @@ -66,7 +68,7 @@ public class RotationPropagator { && stateTo.get(EncasedBeltBlock.CONNECTED_FACE) == direction.getOpposite(); return connected ? 1 : 0; } - + // Attached Fans if (AllBlocks.ENCASED_FAN.typeOf(stateFrom) && AllBlocks.ENCASED_FAN.typeOf(stateTo)) { if (stateFrom.get(BlockStateProperties.AXIS) == stateTo.get(BlockStateProperties.AXIS)) @@ -176,7 +178,7 @@ public class RotationPropagator { if ((neighbourTE.isSource()) || neighbourTE.hasSource() && !neighbourTE.getSource().equals(updateTE.getPos())) { - if (neighbourTE.getSpeed() != newSpeed) { + if (neighbourTE.getSpeed() != newSpeed || Math.abs(newSpeed) > parameters.maxRotationSpeed.get()) { world.destroyBlock(pos, true); return; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorTileEntity.java index e7b16bf64..1dad6d68c 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/generators/MotorTileEntity.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules.contraptions.generators; import com.simibubi.create.AllPackets; import com.simibubi.create.AllTileEntities; +import com.simibubi.create.CreateConfig; import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import net.minecraft.tileentity.ITickableTileEntity; @@ -9,21 +10,20 @@ import net.minecraft.util.math.MathHelper; public class MotorTileEntity extends KineticTileEntity implements ITickableTileEntity { - public static final int MAX_SPEED = 4096; public static final int DEFAULT_SPEED = 64; public int newSpeed; public int lastModified; - + public MotorTileEntity() { super(AllTileEntities.MOTOR.type); setSpeed(DEFAULT_SPEED); } - + @Override public boolean hasFastRenderer() { return true; } - + @Override public boolean isSource() { return true; @@ -34,7 +34,7 @@ public class MotorTileEntity extends KineticTileEntity implements ITickableTileE super.setSpeed(speed); newSpeed = (int) speed; } - + public int getSpeedValue() { if (world.isRemote) return newSpeed; @@ -44,7 +44,7 @@ public class MotorTileEntity extends KineticTileEntity implements ITickableTileE public void setSpeedValueLazily(int speed) { if (newSpeed == speed) return; - newSpeed = MathHelper.clamp(speed, 1, MAX_SPEED); + newSpeed = MathHelper.clamp(speed, 1, CreateConfig.parameters.maxMotorSpeed.get()); this.lastModified = 0; } @@ -59,5 +59,5 @@ public class MotorTileEntity extends KineticTileEntity implements ITickableTileE AllPackets.channel.sendToServer(new ConfigureMotorPacket(pos, newSpeed)); } } - + } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/CrushingWheelControllerTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/CrushingWheelControllerTileEntity.java index 7b89c4c01..e93346877 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/CrushingWheelControllerTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/CrushingWheelControllerTileEntity.java @@ -7,6 +7,7 @@ import java.util.UUID; import com.simibubi.create.AllRecipes; import com.simibubi.create.AllTileEntities; +import com.simibubi.create.CreateConfig; import com.simibubi.create.foundation.block.SyncedTileEntity; import net.minecraft.entity.Entity; @@ -142,7 +143,7 @@ public class CrushingWheelControllerTileEntity extends SyncedTileEntity implemen return; if (!(processingEntity instanceof ItemEntity)) { - processingEntity.attackEntityFrom(damageSource, 4); + processingEntity.attackEntityFrom(damageSource, CreateConfig.parameters.crushingDamage.get()); return; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/EncasedFanTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/EncasedFanTileEntity.java index 7d38a574e..ce721e9ed 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/EncasedFanTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/EncasedFanTileEntity.java @@ -1,5 +1,6 @@ package com.simibubi.create.modules.contraptions.receivers; +import static com.simibubi.create.CreateConfig.parameters; import static net.minecraft.state.properties.BlockStateProperties.AXIS; import static net.minecraft.util.Direction.AxisDirection.NEGATIVE; import static net.minecraft.util.Direction.AxisDirection.POSITIVE; @@ -44,30 +45,20 @@ import net.minecraft.util.math.Vec3i; public class EncasedFanTileEntity extends KineticTileEntity implements ITickableTileEntity { - public static final int PUSH_DISTANCE_MAX = 20; - public static final int PULL_DISTANCE_MAX = 5; - public static final int DISTANCE_ARGMAX = 6400; - - public static final float PUSH_FORCE_MAX = 20; - public static final float PULL_FORCE_MAX = 10; - public static final int FORCE_ARGMAX = 6400; - - public static final int BLOCK_CHECK_UPDATE_DELAY = 100; public static final Map> effects = new HashMap<>(); - private static DamageSource damageSourceFire = new DamageSource("create.fan_fire").setDifficultyScaled() .setFireDamage(); private static DamageSource damageSourceLava = new DamageSource("create.fan_lava").setDifficultyScaled() .setFireDamage(); - protected BlockState frontBlock; protected float pushDistance; protected float pullDistance; - protected float pushForce; - protected float pullForce; protected AxisAlignedBB frontBB; protected AxisAlignedBB backBB; + protected int blockCheckCooldown; + protected BlockState frontBlock; + protected boolean findLoadedItems; protected boolean findFrontBlock; public List items; @@ -157,7 +148,7 @@ public class EncasedFanTileEntity extends KineticTileEntity implements ITickable frontBB = new AxisAlignedBB(0, 0, 0, 0, 0, 0); backBB = new AxisAlignedBB(0, 0, 0, 0, 0, 0); items = new ArrayList<>(); - if (effects.isEmpty()) +// if (effects.isEmpty()) initEffects(); } @@ -165,8 +156,8 @@ public class EncasedFanTileEntity extends KineticTileEntity implements ITickable effects.clear(); List standardFX = new ArrayList<>(2); - standardFX.add(new FanEffect(ParticleTypes.BUBBLE_POP, 1 / 4f, 1 / 8f, 1 / 8f, 1)); - standardFX.add(new FanEffect(new RedstoneParticleData(1, 1, 1, 1), 1 / 2f, 1 / 32f, 0f, 512f)); + standardFX.add(new FanEffect(ParticleTypes.BUBBLE_POP, 1 / 4f, 1 / 4f, 1 / 3f, 1)); + standardFX.add(new FanEffect(new RedstoneParticleData(1, 1, 1, 1), 1 / 2f, 1 / 32f, 1/16f, 512f)); effects.put(Blocks.AIR, standardFX); List waterFX = new ArrayList<>(2); @@ -207,8 +198,6 @@ public class EncasedFanTileEntity extends KineticTileEntity implements ITickable pushDistance = compound.getFloat("PushDistance"); pullDistance = compound.getFloat("PullDistance"); - pushForce = compound.getFloat("PushForce"); - pullForce = compound.getFloat("PullForce"); ListNBT itemsNBT = compound.getList("Items", 10); items.clear(); @@ -223,8 +212,6 @@ public class EncasedFanTileEntity extends KineticTileEntity implements ITickable public CompoundNBT write(CompoundNBT compound) { compound.putFloat("PushDistance", pushDistance); compound.putFloat("PullDistance", pullDistance); - compound.putFloat("PushForce", pushForce); - compound.putFloat("PullForce", pullForce); ListNBT itemsNBT = new ListNBT(); for (ProcessedItem item : items) { @@ -244,13 +231,10 @@ public class EncasedFanTileEntity extends KineticTileEntity implements ITickable return; float speed = Math.abs(this.speed); - float distanceFactor = Math.min(speed / DISTANCE_ARGMAX, 1); - float forceFactor = Math.min(speed / FORCE_ARGMAX, 1); + float distanceFactor = Math.min(speed / parameters.fanRotationArgmax.get(), 1); - pushDistance = MathHelper.lerp(distanceFactor, 3, PUSH_DISTANCE_MAX); - pullDistance = MathHelper.lerp(distanceFactor, 1.5f, PULL_DISTANCE_MAX); - pushForce = MathHelper.lerp(forceFactor, 1, PUSH_FORCE_MAX); - pullForce = MathHelper.lerp(forceFactor, 1, PULL_FORCE_MAX); + pushDistance = MathHelper.lerp(distanceFactor, 3, parameters.fanMaxPushDistance.get()); + pullDistance = MathHelper.lerp(distanceFactor, 1.5f, parameters.fanMaxPullDistance.get()); Direction direction = getAirFlow(); if (speed != 0) { @@ -345,7 +329,7 @@ public class EncasedFanTileEntity extends KineticTileEntity implements ITickable } if (!world.isRemote && blockCheckCooldown-- <= 0) { - blockCheckCooldown = BLOCK_CHECK_UPDATE_DELAY; + blockCheckCooldown = parameters.fanBlockCheckRate.get(); updateReachAndForce(); } @@ -459,9 +443,10 @@ public class EncasedFanTileEntity extends KineticTileEntity implements ITickable float s = (float) (speed * 1 / modifier / (entity.getPositionVec().distanceTo(center) / (push ? pushDistance : pullDistance))); Vec3d motion = entity.getMotion(); - double xIn = flow.getX() * s - motion.x; - double yIn = flow.getY() * s - motion.y; - double zIn = flow.getZ() * s - motion.z; + float maxSpeedModifier = 5; + double xIn = MathHelper.clamp(flow.getX() * s - motion.x, -maxSpeedModifier, maxSpeedModifier); + double yIn = MathHelper.clamp(flow.getY() * s - motion.y, -maxSpeedModifier, maxSpeedModifier); + double zIn = MathHelper.clamp(flow.getZ() * s - motion.z, -maxSpeedModifier, maxSpeedModifier); entity.setMotion(motion.add(new Vec3d(xIn, yIn, zIn).mul(flow.getX(), flow.getY(), flow.getZ()).scale(1 / 8f))); entity.fallDistance = 0; } diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/ChassisTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/ChassisTileEntity.java index 44d364ba4..e33f0aafa 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/ChassisTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/ChassisTileEntity.java @@ -11,7 +11,6 @@ import net.minecraft.util.math.MathHelper; public class ChassisTileEntity extends SyncedTileEntity implements ITickableTileEntity { public static final int MAX_RANGE = 16; - public static final int DEFAULT_RANGE = 8; private int range; public int newRange; @@ -19,7 +18,7 @@ public class ChassisTileEntity extends SyncedTileEntity implements ITickableTile public ChassisTileEntity() { super(AllTileEntities.CHASSIS.type); - newRange = range = DEFAULT_RANGE; + newRange = range = MAX_RANGE / 2; } @Override diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonBlock.java index e698ceab9..059b97417 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonBlock.java @@ -1,6 +1,7 @@ package com.simibubi.create.modules.contraptions.receivers.constructs; import com.simibubi.create.AllBlocks; +import com.simibubi.create.CreateConfig; import com.simibubi.create.foundation.utility.ItemDescription; import com.simibubi.create.modules.contraptions.base.KineticBlock; @@ -120,7 +121,8 @@ public class MechanicalPistonBlock extends KineticBlock { BlockPos pistonHead = null; BlockPos pistonBase = pos; - for (int offset = 1; offset < TranslationConstruct.MAX_EXTENSIONS; offset++) { + Integer maxPoles = CreateConfig.parameters.maxPistonPoles.get(); + for (int offset = 1; offset < maxPoles; offset++) { BlockPos currentPos = pos.offset(direction, offset); BlockState block = worldIn.getBlockState(currentPos); @@ -140,7 +142,7 @@ public class MechanicalPistonBlock extends KineticBlock { .forEach(p -> worldIn.destroyBlock(p, !player.isCreative())); } - for (int offset = 1; offset < TranslationConstruct.MAX_EXTENSIONS; offset++) { + for (int offset = 1; offset < maxPoles; offset++) { BlockPos currentPos = pos.offset(direction.getOpposite(), offset); BlockState block = worldIn.getBlockState(currentPos); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonHeadBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonHeadBlock.java index 8cb602eaf..132a66335 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonHeadBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonHeadBlock.java @@ -1,6 +1,7 @@ package com.simibubi.create.modules.contraptions.receivers.constructs; import com.simibubi.create.AllBlocks; +import com.simibubi.create.CreateConfig; import com.simibubi.create.foundation.block.IWithoutBlockItem; import com.simibubi.create.foundation.block.ProperDirectionalBlock; import com.simibubi.create.modules.contraptions.receivers.constructs.MechanicalPistonBlock.PistonState; @@ -65,7 +66,7 @@ public class MechanicalPistonHeadBlock extends ProperDirectionalBlock implements BlockPos pistonHead = pos; BlockPos pistonBase = null; - for (int offset = 1; offset < TranslationConstruct.MAX_EXTENSIONS; offset++) { + for (int offset = 1; offset < CreateConfig.parameters.maxPistonPoles.get(); offset++) { BlockPos currentPos = pos.offset(direction.getOpposite(), offset); BlockState block = worldIn.getBlockState(currentPos); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonTileEntity.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonTileEntity.java index 6252f06e0..6e5985157 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/MechanicalPistonTileEntity.java @@ -1,5 +1,7 @@ package com.simibubi.create.modules.contraptions.receivers.constructs; +import static com.simibubi.create.CreateConfig.parameters; + import java.util.Arrays; import java.util.Iterator; @@ -207,8 +209,8 @@ public class MechanicalPistonTileEntity extends KineticTileEntity implements ITi BlockPos relativePos = BlockPos.ZERO.offset(movementDirection, getModulatedOffset(newOffset)); // Other moving Pistons - int maxPossibleRange = TranslationConstruct.MAX_EXTENSIONS + TranslationConstruct.MAX_CHAINED_BLOCKS - + TranslationConstruct.MAX_CHAINED_CHASSIS; + int maxPossibleRange = parameters.maxPistonPoles.get() + parameters.maxChassisRange.get() + + parameters.maxChassisForTranslation.get(); Iterator iterator = Create.constructHandler.getOtherMovingPistonsInWorld(this) .iterator(); pistonLoop: while (iterator.hasNext()) { diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/PistonPoleBlock.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/PistonPoleBlock.java index c63993395..f227ad990 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/PistonPoleBlock.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/PistonPoleBlock.java @@ -3,6 +3,7 @@ package com.simibubi.create.modules.contraptions.receivers.constructs; import java.util.List; import com.simibubi.create.AllBlocks; +import com.simibubi.create.CreateConfig; import com.simibubi.create.foundation.block.ProperDirectionalBlock; import com.simibubi.create.foundation.utility.ITooltip; import com.simibubi.create.foundation.utility.ItemDescription; @@ -55,7 +56,8 @@ public class PistonPoleBlock extends ProperDirectionalBlock implements ITooltip BlockPos pistonBase = null; for (int modifier : new int[] { 1, -1 }) { - for (int offset = modifier; modifier * offset < TranslationConstruct.MAX_EXTENSIONS; offset += modifier) { + for (int offset = modifier; modifier * offset < CreateConfig.parameters.maxPistonPoles + .get(); offset += modifier) { BlockPos currentPos = pos.offset(direction, offset); BlockState block = worldIn.getBlockState(currentPos); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/RotationConstruct.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/RotationConstruct.java index 002fa8832..c56174bad 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/RotationConstruct.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/RotationConstruct.java @@ -9,6 +9,7 @@ import java.util.Map; import java.util.Set; import com.simibubi.create.AllBlocks; +import com.simibubi.create.CreateConfig; import net.minecraft.block.BlockState; import net.minecraft.block.PistonBlock; @@ -24,8 +25,6 @@ import net.minecraft.world.gen.feature.template.Template.BlockInfo; public class RotationConstruct { - public static final int MAX_CHAINED_CHASSIS = 10; - protected Map blocks; public RotationConstruct() { @@ -52,7 +51,7 @@ public class RotationConstruct { if (chassis.isEmpty()) { BlockPos blockPos = pos.offset(direction); BlockState state = world.getBlockState(pos.offset(direction)); - + if (state.getMaterial().isReplaceable() || state.isAir(world, blockPos)) return true; if (state.getCollisionShape(world, blockPos).isEmpty()) @@ -62,7 +61,7 @@ public class RotationConstruct { blocks.put(blockPos, new BlockInfo(blockPos.subtract(pos), state, null)); - // Get attached blocks by chassis + // Get attached blocks by chassis } else { List attachedBlocksByChassis = getAttachedBlocksByChassis(world, direction, chassis); if (attachedBlocksByChassis == null) @@ -78,35 +77,35 @@ public class RotationConstruct { private List getAttachedBlocksByChassis(World world, Direction direction, List chassis) { List blocks = new ArrayList<>(); RotationChassisBlock def = (RotationChassisBlock) AllBlocks.ROTATION_CHASSIS.block; - + for (BlockInfo chassisBlock : chassis) { blocks.add(chassisBlock); BlockState state = chassisBlock.state; BlockPos currentPos = chassisBlock.pos; TileEntity tileEntity = world.getTileEntity(currentPos); - + if (!(tileEntity instanceof ChassisTileEntity)) return null; - + int chassisRange = ((ChassisTileEntity) tileEntity).getRange(); Set visited = new HashSet<>(); - + for (Direction facing : Direction.values()) { if (facing.getAxis() == direction.getAxis()) continue; if (!state.get(def.getGlueableSide(state, facing))) continue; - + BlockPos startPos = currentPos.offset(facing); List frontier = new LinkedList<>(); frontier.add(startPos); CompoundNBT nbt = new CompoundNBT(); nbt.putInt("Range", chassisRange); - + while (!frontier.isEmpty()) { BlockPos searchPos = frontier.remove(0); BlockState searchedState = world.getBlockState(searchPos); - + if (visited.contains(searchPos)) continue; if (!searchPos.withinDistance(currentPos, chassisRange + .5f)) @@ -117,18 +116,18 @@ public class RotationConstruct { continue; if (!canRotate(world, searchPos, direction)) return null; - + visited.add(searchPos); - + blocks.add(new BlockInfo(searchPos, searchedState, AllBlocks.ROTATION_CHASSIS.typeOf(searchedState) ? nbt : null)); - + for (Direction offset : Direction.values()) { if (offset.getAxis() == direction.getAxis()) continue; if (searchPos.equals(currentPos) && offset != facing) continue; - + frontier.add(searchPos.offset(offset)); } } @@ -139,7 +138,7 @@ public class RotationConstruct { private List collectChassis(World world, BlockPos pos, Direction direction) { List chassis = new ArrayList<>(); - for (int distance = 1; distance <= MAX_CHAINED_CHASSIS; distance++) { + for (int distance = 1; distance <= CreateConfig.parameters.maxChassisForRotation.get(); distance++) { BlockPos currentPos = pos.offset(direction, distance); if (!world.isBlockPresent(currentPos)) return chassis; diff --git a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/TranslationConstruct.java b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/TranslationConstruct.java index 138057e78..77588c5f0 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/TranslationConstruct.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/receivers/constructs/TranslationConstruct.java @@ -3,6 +3,7 @@ package com.simibubi.create.modules.contraptions.receivers.constructs; import static com.simibubi.create.AllBlocks.MECHANICAL_PISTON_HEAD; import static com.simibubi.create.AllBlocks.PISTON_POLE; import static com.simibubi.create.AllBlocks.STICKY_MECHANICAL_PISTON; +import static com.simibubi.create.CreateConfig.parameters; import static net.minecraft.state.properties.BlockStateProperties.FACING; import java.util.ArrayList; @@ -34,10 +35,6 @@ import net.minecraft.world.gen.feature.template.Template.BlockInfo; public class TranslationConstruct { - public static final int MAX_EXTENSIONS = 20; - public static final int MAX_CHAINED_CHASSIS = 12; - public static final int MAX_CHAINED_BLOCKS = 8; - protected Map blocks; protected List actors; @@ -120,7 +117,7 @@ public class TranslationConstruct { extensionsInFront++; nextBlock = world.getBlockState(actualStart.offset(direction)); - if (extensionsInFront > MAX_EXTENSIONS) + if (extensionsInFront > parameters.maxPistonPoles.get()) return false; } @@ -143,7 +140,7 @@ public class TranslationConstruct { extensionsInBack++; nextBlock = world.getBlockState(end.offset(direction.getOpposite())); - if (extensionsInFront + extensionsInBack > MAX_EXTENSIONS) + if (extensionsInFront + extensionsInBack > parameters.maxPistonPoles.get()) return false; } @@ -184,7 +181,7 @@ public class TranslationConstruct { collisionBoxFront = new AxisAlignedBB(blockPos); } else { - for (int distance = 1; distance <= MAX_CHAINED_BLOCKS + 1; distance++) { + for (int distance = 1; distance <= parameters.maxChassisRange.get() + 1; distance++) { BlockPos currentPos = pos.offset(direction, distance); BlockState state = world.getBlockState(currentPos); @@ -199,7 +196,7 @@ public class TranslationConstruct { return false; // Too many blocks - if (distance == MAX_CHAINED_BLOCKS + 1) + if (distance == parameters.maxChassisRange.get() + 1) return false; BlockPos blockPos = currentPos.offset(direction, -offset); @@ -272,7 +269,7 @@ public class TranslationConstruct { int chassisRange = ((ChassisTileEntity) world.getTileEntity(currentChassisPos)).getRange(); boolean chassisSticky = chassisState .get(((AbstractChassisBlock) chassisState.getBlock()).getGlueableSide(chassisState, direction)); - + // Ignore replaceable Blocks and Air-like if (state.getMaterial().isReplaceable() || state.isAir(world, currentPos)) continue; @@ -340,11 +337,11 @@ public class TranslationConstruct { private static List collectChassis(World world, BlockPos pos, Direction direction, int offset2) { List search = new LinkedList<>(); - Set visited = new HashSet<>(MAX_CHAINED_CHASSIS); + Set visited = new HashSet<>(); List chassis = new LinkedList<>(); search.add(pos.offset(direction)); while (!search.isEmpty()) { - if (chassis.size() > MAX_CHAINED_CHASSIS) + if (chassis.size() > parameters.maxChassisForTranslation.get()) return null; BlockPos current = search.remove(0); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItem.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItem.java index 81c0ee7b9..55ff72be8 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItem.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItem.java @@ -4,6 +4,7 @@ import java.util.LinkedList; import java.util.List; import com.simibubi.create.AllBlocks; +import com.simibubi.create.CreateConfig; import com.simibubi.create.modules.contraptions.base.KineticTileEntity; import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Part; import com.simibubi.create.modules.contraptions.relays.belt.BeltBlock.Slope; @@ -23,8 +24,6 @@ import net.minecraft.world.World; public class BeltItem extends Item { - public static final int MAX_PULLEY_DISTANCE = 20; - public BeltItem(Properties properties) { super(properties); } @@ -35,7 +34,7 @@ public class BeltItem extends Item { context.getItem().setTag(null); return ActionResultType.SUCCESS; } - + World world = context.getWorld(); BlockPos pos = context.getPos(); boolean validAxis = validateAxis(world, pos); @@ -164,7 +163,7 @@ public class BeltItem extends Item { return false; if (!world.isAreaLoaded(second, 1)) return false; - if (!second.withinDistance(first, MAX_PULLEY_DISTANCE)) + if (!second.withinDistance(first, CreateConfig.parameters.maxBeltLength.get())) return false; BlockPos diff = second.subtract(first); diff --git a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItemHandler.java b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItemHandler.java index dbd49fb88..39721de7e 100644 --- a/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItemHandler.java +++ b/src/main/java/com/simibubi/create/modules/contraptions/relays/belt/BeltItemHandler.java @@ -6,6 +6,7 @@ import java.util.Random; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; +import com.simibubi.create.CreateConfig; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.PlayerEntity; @@ -69,7 +70,7 @@ public class BeltItemHandler { return; if (!AllBlocks.SHAFT.typeOf(world.getBlockState(selected))) selected = selected.offset(((BlockRayTraceResult) rayTrace).getFace()); - if (!selected.withinDistance(first, BeltItem.MAX_PULLEY_DISTANCE)) + if (!selected.withinDistance(first, CreateConfig.parameters.maxBeltLength.get())) return; boolean canConnect = BeltItem.validateAxis(world, selected) && BeltItem.canConnect(world, first, selected); diff --git a/src/main/java/com/simibubi/create/modules/gardens/CocoaLogBlock.java b/src/main/java/com/simibubi/create/modules/gardens/CocoaLogBlock.java index d6336d049..200552d29 100644 --- a/src/main/java/com/simibubi/create/modules/gardens/CocoaLogBlock.java +++ b/src/main/java/com/simibubi/create/modules/gardens/CocoaLogBlock.java @@ -5,6 +5,8 @@ import java.util.Collections; import java.util.List; import java.util.Random; +import com.simibubi.create.CreateConfig; + import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Blocks; @@ -22,8 +24,6 @@ public class CocoaLogBlock extends RotatedPillarBlock implements IGrowable { public static IntegerProperty AGE = BlockStateProperties.AGE_0_2; - private static final int GROWTH_CHANCE = 20; - public CocoaLogBlock() { super(Properties.from(Blocks.JUNGLE_LOG).tickRandomly()); } @@ -53,7 +53,7 @@ public class CocoaLogBlock extends RotatedPillarBlock implements IGrowable { @Override public void grow(World world, Random random, BlockPos pos, BlockState state) { - if (random.nextInt(100 / GROWTH_CHANCE) != 0) + if (random.nextDouble() > CreateConfig.parameters.cocoaLogGrowthSpeed.get() / 100D) return; int age = state.get(AGE); diff --git a/src/main/java/com/simibubi/create/modules/logistics/FrequencyHandler.java b/src/main/java/com/simibubi/create/modules/logistics/FrequencyHandler.java index 242ae957f..c1ca02594 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/FrequencyHandler.java +++ b/src/main/java/com/simibubi/create/modules/logistics/FrequencyHandler.java @@ -8,6 +8,7 @@ import java.util.Map; import org.apache.commons.lang3.tuple.Pair; import com.simibubi.create.Create; +import com.simibubi.create.CreateConfig; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -16,8 +17,6 @@ import net.minecraft.world.IWorld; public class FrequencyHandler { - public static final int RANGE = 128; - static Map, List>> connections = new HashMap<>(); public static class Frequency { @@ -110,7 +109,7 @@ public class FrequencyHandler { } public static boolean withinRange(IHaveWireless from, IHaveWireless to) { - return from.getPos().withinDistance(to.getPos(), RANGE); + return from.getPos().withinDistance(to.getPos(), CreateConfig.parameters.linkRange.get()); } public Map, List> networksIn(IWorld world) { diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/ExtractorTileEntity.java b/src/main/java/com/simibubi/create/modules/logistics/block/ExtractorTileEntity.java index 135ed11bc..eb960626a 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/ExtractorTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/ExtractorTileEntity.java @@ -1,6 +1,7 @@ package com.simibubi.create.modules.logistics.block; import com.simibubi.create.AllTileEntities; +import com.simibubi.create.CreateConfig; import com.simibubi.create.foundation.block.SyncedTileEntity; import net.minecraft.item.ItemStack; @@ -60,7 +61,7 @@ public class ExtractorTileEntity extends SyncedTileEntity implements IExtractor, @Override public void setState(State state) { if (state == State.ON_COOLDOWN) - cooldown = EXTRACTOR_COOLDOWN; + cooldown = CreateConfig.parameters.extractorDelay.get(); this.state = state; } diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/IExtractor.java b/src/main/java/com/simibubi/create/modules/logistics/block/IExtractor.java index 0e073d6fb..4ca89407f 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/IExtractor.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/IExtractor.java @@ -1,5 +1,6 @@ package com.simibubi.create.modules.logistics.block; +import com.simibubi.create.CreateConfig; import com.simibubi.create.foundation.utility.VecHelper; import net.minecraft.entity.item.ItemEntity; @@ -13,9 +14,6 @@ import net.minecraftforge.items.IItemHandler; // Its like delegation but better! public interface IExtractor extends ITickableTileEntity, IInventoryManipulator { - public static final int EXTRACTOR_COOLDOWN = 20; - public static final int EXTRACTION_COUNT = 16; - public enum State { WAITING_FOR_INVENTORY, WAITING_FOR_ENTITY, RUNNING, ON_COOLDOWN, LOCKED; } @@ -113,7 +111,7 @@ public interface IExtractor extends ITickableTileEntity, IInventoryManipulator { IItemHandler inv = getInventory().orElse(null); ItemStack extracting = ItemStack.EMPTY; ItemStack filter = (this instanceof IHaveFilter) ? filter = ((IHaveFilter) this).getFilter() : ItemStack.EMPTY; - int extractionCount = filter.isEmpty() ? EXTRACTION_COUNT : filter.getCount(); + int extractionCount = filter.isEmpty() ? CreateConfig.parameters.extractorAmount.get() : filter.getCount(); for (int slot = 0; slot < inv.getSlots(); slot++) { ItemStack stack = inv.extractItem(slot, extractionCount - extracting.getCount(), true); diff --git a/src/main/java/com/simibubi/create/modules/logistics/block/LinkedExtractorTileEntity.java b/src/main/java/com/simibubi/create/modules/logistics/block/LinkedExtractorTileEntity.java index a4d1ec03f..e65f35963 100644 --- a/src/main/java/com/simibubi/create/modules/logistics/block/LinkedExtractorTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/logistics/block/LinkedExtractorTileEntity.java @@ -3,6 +3,7 @@ package com.simibubi.create.modules.logistics.block; import static net.minecraft.state.properties.BlockStateProperties.POWERED; import com.simibubi.create.AllTileEntities; +import com.simibubi.create.CreateConfig; import com.simibubi.create.modules.logistics.IReceiveWireless; import net.minecraft.item.ItemStack; @@ -67,7 +68,7 @@ public class LinkedExtractorTileEntity extends LinkedTileEntity @Override public void setState(State state) { if (state == State.ON_COOLDOWN) - cooldown = EXTRACTOR_COOLDOWN; + cooldown = CreateConfig.parameters.extractorDelay.get(); this.state = state; } diff --git a/src/main/java/com/simibubi/create/modules/schematics/ClientSchematicLoader.java b/src/main/java/com/simibubi/create/modules/schematics/ClientSchematicLoader.java index 876e6a708..b737a66cf 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/ClientSchematicLoader.java +++ b/src/main/java/com/simibubi/create/modules/schematics/ClientSchematicLoader.java @@ -1,6 +1,6 @@ package com.simibubi.create.modules.schematics; -import static com.simibubi.create.modules.schematics.ServerSchematicLoader.MAX_PACKET_SIZE; +import static com.simibubi.create.CreateConfig.parameters; import java.io.IOException; import java.io.InputStream; @@ -66,12 +66,12 @@ public class ClientSchematicLoader { long size = Files.size(path); // Too big - if (size > ServerSchematicLoader.MAX_SCHEMATIC_FILE_SIZE) { + Integer maxSize = parameters.maxTotalSchematicSize.get(); + if (size > maxSize * 1000) { Minecraft.getInstance().player - .sendMessage(new StringTextComponent("Your schematic is too large (" + size / 1024 + " KB).")); - Minecraft.getInstance().player - .sendMessage(new StringTextComponent("The maximum allowed schematic file size is: " - + ServerSchematicLoader.MAX_SCHEMATIC_FILE_SIZE / 1024 + " KB")); + .sendMessage(new StringTextComponent("Your schematic is too large (" + size / 1000 + " KB).")); + Minecraft.getInstance().player.sendMessage( + new StringTextComponent("The maximum allowed schematic file size is: " + maxSize + " KB")); return; } @@ -85,10 +85,11 @@ public class ClientSchematicLoader { private void continueUpload(String schematic) { if (activeUploads.containsKey(schematic)) { - byte[] data = new byte[MAX_PACKET_SIZE]; + Integer maxPacketSize = parameters.maxSchematicPacketSize.get(); + byte[] data = new byte[maxPacketSize]; try { int status = activeUploads.get(schematic).read(data); - if (status < MAX_PACKET_SIZE) { + if (status < maxPacketSize) { data = Arrays.copyOf(data, status); } @@ -99,7 +100,7 @@ public class ClientSchematicLoader { return; } - if (status < MAX_PACKET_SIZE) + if (status < maxPacketSize) finishUpload(schematic); } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/com/simibubi/create/modules/schematics/ServerSchematicLoader.java b/src/main/java/com/simibubi/create/modules/schematics/ServerSchematicLoader.java index 23c824efd..07f2cf8a8 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/ServerSchematicLoader.java +++ b/src/main/java/com/simibubi/create/modules/schematics/ServerSchematicLoader.java @@ -1,5 +1,7 @@ package com.simibubi.create.modules.schematics; +import static com.simibubi.create.CreateConfig.parameters; + import java.io.IOException; import java.io.OutputStream; import java.nio.file.Files; @@ -28,12 +30,6 @@ import net.minecraft.util.text.StringTextComponent; public class ServerSchematicLoader { - public static final String PATH = "schematics/uploaded"; - public static final int IDLE_TIMEOUT = 600; - public static final int MAX_PACKET_SIZE = 1024; - public static final int MAX_SCHEMATICS_PER_PLAYER = 10; - public static final int MAX_SCHEMATIC_FILE_SIZE = 256 * 1024; // 256 kiB - private Map activeUploads; public class SchematicUploadEntry { @@ -54,8 +50,11 @@ public class ServerSchematicLoader { public ServerSchematicLoader() { activeUploads = new HashMap<>(); - FilesHelper.createFolderIfMissing("schematics"); - FilesHelper.createFolderIfMissing(PATH); + FilesHelper.createFolderIfMissing(getSchematicPath()); + } + + public String getSchematicPath() { + return parameters.schematicPath.get(); } public void tick() { @@ -64,7 +63,7 @@ public class ServerSchematicLoader { for (String upload : activeUploads.keySet()) { SchematicUploadEntry entry = activeUploads.get(upload); - if (entry.idleTime++ > IDLE_TIMEOUT) { + if (entry.idleTime++ > parameters.schematicIdleTimeout.get()) { Create.logger.warn("Schematic Upload timed out: " + upload); deadEntries.add(upload); } @@ -81,7 +80,7 @@ public class ServerSchematicLoader { } public void handleNewUpload(ServerPlayerEntity player, String schematic, long size, DimensionPos dimPos) { - String playerPath = PATH + "/" + player.getName().getFormattedText(); + String playerPath = getSchematicPath() + "/" + player.getName().getFormattedText(); String playerSchematicId = player.getName().getFormattedText() + "/" + schematic; FilesHelper.createFolderIfMissing(playerPath); @@ -91,10 +90,11 @@ public class ServerSchematicLoader { } // Too big - if (size > MAX_SCHEMATIC_FILE_SIZE) { - player.sendMessage(new StringTextComponent("Your schematic is too large (" + size/1024 + " KB).")); - player.sendMessage(new StringTextComponent( - "The maximum allowed schematic file size is: " + MAX_SCHEMATIC_FILE_SIZE/1024 + " KB")); + Integer maxFileSize = parameters.maxTotalSchematicSize.get(); + if (size > maxFileSize * 1000) { + player.sendMessage(new StringTextComponent("Your schematic is too large (" + size / 1000 + " KB).")); + player.sendMessage( + new StringTextComponent("The maximum allowed schematic file size is: " + maxFileSize + " KB")); return; } @@ -109,11 +109,11 @@ public class ServerSchematicLoader { return; // Delete schematic with same name - Files.deleteIfExists(Paths.get(PATH, playerSchematicId)); + Files.deleteIfExists(Paths.get(getSchematicPath(), playerSchematicId)); // Too many Schematics Stream list = Files.list(Paths.get(playerPath)); - if (list.count() >= MAX_SCHEMATICS_PER_PLAYER) { + if (list.count() >= parameters.maxSchematics.get()) { Stream list2 = Files.list(Paths.get(playerPath)); Optional lastFilePath = list2.filter(f -> !Files.isDirectory(f)) .min(Comparator.comparingLong(f -> f.toFile().lastModified())); @@ -125,7 +125,7 @@ public class ServerSchematicLoader { list.close(); // Open Stream - OutputStream writer = Files.newOutputStream(Paths.get(PATH, playerSchematicId), + OutputStream writer = Files.newOutputStream(Paths.get(getSchematicPath(), playerSchematicId), StandardOpenOption.CREATE_NEW); activeUploads.put(playerSchematicId, new SchematicUploadEntry(writer, size, dimPos)); @@ -147,7 +147,7 @@ public class ServerSchematicLoader { entry.bytesUploaded += data.length; // Size Validations - if (data.length > MAX_PACKET_SIZE) { + if (data.length > parameters.maxSchematicPacketSize.get()) { Create.logger.warn("Oversized Upload Packet received: " + playerSchematicId); cancelUpload(playerSchematicId); return; @@ -186,7 +186,7 @@ public class ServerSchematicLoader { SchematicUploadEntry entry = activeUploads.remove(playerSchematicId); try { entry.stream.close(); - Files.deleteIfExists(Paths.get(PATH, playerSchematicId)); + Files.deleteIfExists(Paths.get(getSchematicPath(), playerSchematicId)); Create.logger.warn("Cancelled Schematic Upload: " + playerSchematicId); } catch (IOException e) { @@ -197,11 +197,11 @@ public class ServerSchematicLoader { DimensionPos dimpos = entry.tablePos; if (dimpos == null) return; - + BlockState blockState = dimpos.world.getBlockState(dimpos.pos); if (!AllBlocks.SCHEMATIC_TABLE.typeOf(blockState)) return; - + SchematicTableTileEntity tileEntity = (SchematicTableTileEntity) dimpos.world.getTileEntity(dimpos.pos); tileEntity.finishUpload(); } diff --git a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonScreen.java b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonScreen.java index 0be76418a..2368ec098 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonScreen.java +++ b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonScreen.java @@ -146,8 +146,7 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen"); + ((IconButton) w).getToolTip().add(TextFormatting.DARK_GRAY + "< Hold Shift >"); } if (hasShiftDown()) { @@ -292,9 +291,10 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen= fuelX && mouseY >= fuelY && mouseX <= fuelX + ScreenResources.SCHEMATICANNON_FUEL.width && mouseY <= fuelY + ScreenResources.SCHEMATICANNON_FUEL.height) { container.getTileEntity(); - int shotsLeft = (int) (te.fuelLevel / SchematicannonTileEntity.FUEL_USAGE_RATE); - int shotsLeftWithItems = (int) (shotsLeft + te.inventory.getStackInSlot(4).getCount() - * (SchematicannonTileEntity.FUEL_PER_GUNPOWDER / SchematicannonTileEntity.FUEL_USAGE_RATE)); + double fuelUsageRate = te.getFuelUsageRate(); + int shotsLeft = (int) (te.fuelLevel / fuelUsageRate); + int shotsLeftWithItems = (int) (shotsLeft + + te.inventory.getStackInSlot(4).getCount() * (te.getFuelAddedByGunPowder() / fuelUsageRate)); renderTooltip( ImmutableList.of("Gunpowder at " + (int) (te.fuelLevel * 100) + "%", TextFormatting.GRAY + "Shots left: " + TextFormatting.BLUE + shotsLeft, diff --git a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonTileEntity.java b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonTileEntity.java index 5c9643d53..13f54b2d2 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonTileEntity.java +++ b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicannonTileEntity.java @@ -1,5 +1,7 @@ package com.simibubi.create.modules.schematics.block; +import static com.simibubi.create.CreateConfig.parameters; + import java.util.HashMap; import java.util.LinkedList; import java.util.List; @@ -53,12 +55,8 @@ import net.minecraftforge.items.ItemStackHandler; public class SchematicannonTileEntity extends SyncedTileEntity implements ITickableTileEntity, INamedContainerProvider { public static final int NEIGHBOUR_CHECKING = 100; - public static final int PLACEMENT_DELAY = 10; - public static final float FUEL_PER_GUNPOWDER = .2f; - public static final float FUEL_USAGE_RATE = .0005f; - public static final int SKIPS_PER_TICK = 10; public static final int MAX_ANCHOR_DISTANCE = 256; - + public enum State { STOPPED, PAUSED, RUNNING; } @@ -66,8 +64,8 @@ public class SchematicannonTileEntity extends SyncedTileEntity implements ITicka // Inventory public SchematicannonInventory inventory; - // Sync public boolean sendUpdate; + // Sync public boolean dontUpdateChecklist; public int neighbourCheckCooldown; @@ -364,7 +362,7 @@ public class SchematicannonTileEntity extends SyncedTileEntity implements ITicka refillFuelIfPossible(); // Update Printer - skipsLeft = SKIPS_PER_TICK; + skipsLeft = parameters.schematicannonSkips.get(); blockSkipped = true; while (blockSkipped && skipsLeft-- > 0) @@ -399,7 +397,7 @@ public class SchematicannonTileEntity extends SyncedTileEntity implements ITicka return; } - if (state == State.PAUSED && !blockNotLoaded && missingBlock == null && fuelLevel > FUEL_USAGE_RATE) + if (state == State.PAUSED && !blockNotLoaded && missingBlock == null && fuelLevel > getFuelUsageRate()) return; // Initialize Printer @@ -493,12 +491,16 @@ public class SchematicannonTileEntity extends SyncedTileEntity implements ITicka else statusMsg = "Clearing Blocks"; launchBlock(target, blockState); - printerCooldown = PLACEMENT_DELAY; - fuelLevel -= FUEL_USAGE_RATE; + printerCooldown = parameters.schematicannonDelay.get(); + fuelLevel -= getFuelUsageRate(); sendUpdate = true; missingBlock = null; } + public double getFuelUsageRate() { + return parameters.schematicannonFuelUsage.get() / 100f; + } + protected void initializePrinter(ItemStack blueprint) { if (!blueprint.hasTag()) { state = State.STOPPED; @@ -689,16 +691,20 @@ public class SchematicannonTileEntity extends SyncedTileEntity implements ITicka } protected void refillFuelIfPossible() { - if (1 - fuelLevel + 1 / 128f < FUEL_PER_GUNPOWDER) + if (1 - fuelLevel + 1 / 128f < getFuelAddedByGunPowder()) return; if (inventory.getStackInSlot(4).isEmpty()) return; inventory.getStackInSlot(4).shrink(1); - fuelLevel += FUEL_PER_GUNPOWDER; + fuelLevel += getFuelAddedByGunPowder(); sendUpdate = true; } + public double getFuelAddedByGunPowder() { + return parameters.schematicannonGunpowderWorth.get() / 100f; + } + protected void tickPaperPrinter() { int BookInput = 2; int BookOutput = 3; diff --git a/src/main/java/com/simibubi/create/modules/schematics/client/tools/SchematicToolBase.java b/src/main/java/com/simibubi/create/modules/schematics/client/tools/SchematicToolBase.java index 12af5f211..9c7d150c5 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/client/tools/SchematicToolBase.java +++ b/src/main/java/com/simibubi/create/modules/schematics/client/tools/SchematicToolBase.java @@ -32,12 +32,9 @@ public abstract class SchematicToolBase implements ISchematicTool { public boolean renderSelectedFace; public Direction selectedFace; - public SchematicToolBase() { - schematicHandler = CreateClient.schematicHandler; - } - @Override public void init() { + schematicHandler = CreateClient.schematicHandler; selectedPos = null; selectedFace = null; schematicSelected = false; diff --git a/src/main/java/com/simibubi/create/modules/symmetry/SymmetryWandItem.java b/src/main/java/com/simibubi/create/modules/symmetry/SymmetryWandItem.java index 95a7c5724..ae5d9df81 100644 --- a/src/main/java/com/simibubi/create/modules/symmetry/SymmetryWandItem.java +++ b/src/main/java/com/simibubi/create/modules/symmetry/SymmetryWandItem.java @@ -1,5 +1,7 @@ package com.simibubi.create.modules.symmetry; +import static com.simibubi.create.CreateConfig.parameters; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -186,7 +188,7 @@ public class SymmetryWandItem extends InfoItem { SymmetryMirror symmetry = SymmetryMirror.fromNBT((CompoundNBT) wand.getTag().getCompound($SYMMETRY)); Vec3d mirrorPos = symmetry.getPosition(); - if (mirrorPos.distanceTo(new Vec3d(pos)) > 50) + if (mirrorPos.distanceTo(new Vec3d(pos)) > parameters.maxSymmetryWandRange.get()) return; if (!player.isCreative() && BlockHelper.findAndRemoveInInventory(block, player, 1) == 0) return; @@ -241,7 +243,7 @@ public class SymmetryWandItem extends InfoItem { SymmetryMirror symmetry = SymmetryMirror.fromNBT((CompoundNBT) wand.getTag().getCompound($SYMMETRY)); Vec3d mirrorPos = symmetry.getPosition(); - if (mirrorPos.distanceTo(new Vec3d(pos)) > 50) + if (mirrorPos.distanceTo(new Vec3d(pos)) > parameters.maxSymmetryWandRange.get()) return; symmetry.process(blockSet);