diff --git a/CHANGELOG.md b/CHANGELOG.md index 513b062..b522ed5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## 0.1.4 - Added hitboxes for the attachments on pipes (raoulvdberge) +- Added a config file (raoulvdberge) ## 0.1.3 - Fixed Item Pipes using the wrong side of an inventory (raoulvdberge) diff --git a/src/main/java/com/raoulvdberge/refinedpipes/RefinedPipes.java b/src/main/java/com/raoulvdberge/refinedpipes/RefinedPipes.java index 194d39d..4d247ba 100644 --- a/src/main/java/com/raoulvdberge/refinedpipes/RefinedPipes.java +++ b/src/main/java/com/raoulvdberge/refinedpipes/RefinedPipes.java @@ -1,5 +1,6 @@ package com.raoulvdberge.refinedpipes; +import com.raoulvdberge.refinedpipes.config.ServerConfig; import com.raoulvdberge.refinedpipes.item.group.MainItemGroup; import com.raoulvdberge.refinedpipes.setup.ClientSetup; import com.raoulvdberge.refinedpipes.setup.CommonSetup; @@ -10,7 +11,9 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.DistExecutor; +import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.config.ModConfig; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; @Mod(RefinedPipes.ID) @@ -18,12 +21,15 @@ public class RefinedPipes { public static final String ID = "refinedpipes"; public static final ItemGroup MAIN_GROUP = new MainItemGroup(); public static final RefinedPipesNetwork NETWORK = new RefinedPipesNetwork(); + public static final ServerConfig SERVER_CONFIG = new ServerConfig(); public RefinedPipes() { CommonSetup commonSetup = new CommonSetup(); DistExecutor.runWhenOn(Dist.CLIENT, () -> ClientSetup::new); + ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, SERVER_CONFIG.getSpec()); + FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Block.class, commonSetup::onRegisterBlocks); FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(Item.class, commonSetup::onRegisterItems); FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(TileEntityType.class, commonSetup::onRegisterTileEntities); diff --git a/src/main/java/com/raoulvdberge/refinedpipes/config/ServerConfig.java b/src/main/java/com/raoulvdberge/refinedpipes/config/ServerConfig.java new file mode 100644 index 0000000..40bc417 --- /dev/null +++ b/src/main/java/com/raoulvdberge/refinedpipes/config/ServerConfig.java @@ -0,0 +1,112 @@ +package com.raoulvdberge.refinedpipes.config; + +import net.minecraftforge.common.ForgeConfigSpec; + +public class ServerConfig { + private ForgeConfigSpec.Builder builder = new ForgeConfigSpec.Builder(); + private ForgeConfigSpec spec; + + private ItemPipe basicPipe; + private ItemPipe improvedPipe; + private ItemPipe advancedPipe; + + private ExtractorAttachment basicExtractorAttachment; + private ExtractorAttachment improvedExtractorAttachment; + private ExtractorAttachment advancedExtractorAttachment; + private ExtractorAttachment eliteExtractorAttachment; + private ExtractorAttachment ultimateExtractorAttachment; + + public ServerConfig() { + builder.push("itemPipe"); + basicPipe = new ItemPipe("basic", 30); + improvedPipe = new ItemPipe("improved", 20); + advancedPipe = new ItemPipe("advanced", 10); + builder.pop(); + + builder.push("attachment"); + builder.push("extractor"); + basicExtractorAttachment = new ExtractorAttachment("basic", 20 * 3, 8); + improvedExtractorAttachment = new ExtractorAttachment("improved", 20 * 2, 16); + advancedExtractorAttachment = new ExtractorAttachment("advanced", 20, 32); + eliteExtractorAttachment = new ExtractorAttachment("elite", 10, 64); + ultimateExtractorAttachment = new ExtractorAttachment("ultimate", 10, 64); + builder.pop(); + builder.pop(); + + spec = builder.build(); + } + + public ForgeConfigSpec getSpec() { + return spec; + } + + public ItemPipe getBasicPipe() { + return basicPipe; + } + + public ItemPipe getImprovedPipe() { + return improvedPipe; + } + + public ItemPipe getAdvancedPipe() { + return advancedPipe; + } + + public ExtractorAttachment getBasicExtractorAttachment() { + return basicExtractorAttachment; + } + + public ExtractorAttachment getImprovedExtractorAttachment() { + return improvedExtractorAttachment; + } + + public ExtractorAttachment getAdvancedExtractorAttachment() { + return advancedExtractorAttachment; + } + + public ExtractorAttachment getEliteExtractorAttachment() { + return eliteExtractorAttachment; + } + + public ExtractorAttachment getUltimateExtractorAttachment() { + return ultimateExtractorAttachment; + } + + public class ItemPipe { + private ForgeConfigSpec.IntValue maxTicks; + + public ItemPipe(String type, int defaultMaxTicks) { + builder.push(type); + + maxTicks = builder.comment("The maximum amount of ticks that items can be in the pipe. Lower is faster.").defineInRange("maxTicks", defaultMaxTicks, 0, Integer.MAX_VALUE); + + builder.pop(); + } + + public int getMaxTicks() { + return maxTicks.get(); + } + } + + public class ExtractorAttachment { + private ForgeConfigSpec.IntValue tickInterval; + private ForgeConfigSpec.IntValue itemsToExtract; + + public ExtractorAttachment(String type, int defaultTickInterval, int defaultItemsToExtract) { + builder.push(type); + + tickInterval = builder.comment("The interval between item extractions in ticks. Lower is faster.").defineInRange("tickInterval", defaultTickInterval, 0, Integer.MAX_VALUE); + itemsToExtract = builder.comment("The amount of items to extract per extraction.").defineInRange("itemsToExtract", defaultItemsToExtract, 0, 64); + + builder.pop(); + } + + public int getTickInterval() { + return tickInterval.get(); + } + + public int getItemsToExtract() { + return itemsToExtract.get(); + } + } +} diff --git a/src/main/java/com/raoulvdberge/refinedpipes/network/pipe/ItemPipeType.java b/src/main/java/com/raoulvdberge/refinedpipes/network/pipe/ItemPipeType.java index 00a9c84..3887fd1 100644 --- a/src/main/java/com/raoulvdberge/refinedpipes/network/pipe/ItemPipeType.java +++ b/src/main/java/com/raoulvdberge/refinedpipes/network/pipe/ItemPipeType.java @@ -7,16 +7,14 @@ import net.minecraft.util.ResourceLocation; public enum ItemPipeType { - BASIC(1, 30), - IMPROVED(2, 20), - ADVANCED(3, 10); + BASIC(1), + IMPROVED(2), + ADVANCED(3); private final int tier; - private final int maxTicksInPipe; - ItemPipeType(int tier, int maxTicksInPipe) { + ItemPipeType(int tier) { this.tier = tier; - this.maxTicksInPipe = maxTicksInPipe; } public int getTier() { @@ -24,7 +22,16 @@ public int getTier() { } public int getMaxTicksInPipe() { - return maxTicksInPipe; + switch (this) { + case BASIC: + return RefinedPipes.SERVER_CONFIG.getBasicPipe().getMaxTicks(); + case IMPROVED: + return RefinedPipes.SERVER_CONFIG.getImprovedPipe().getMaxTicks(); + case ADVANCED: + return RefinedPipes.SERVER_CONFIG.getAdvancedPipe().getMaxTicks(); + default: + throw new RuntimeException("?"); + } } public TileEntityType getTileType() { diff --git a/src/main/java/com/raoulvdberge/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachmentType.java b/src/main/java/com/raoulvdberge/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachmentType.java index 0c2125c..3a81c91 100644 --- a/src/main/java/com/raoulvdberge/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachmentType.java +++ b/src/main/java/com/raoulvdberge/refinedpipes/network/pipe/attachment/extractor/ExtractorAttachmentType.java @@ -48,7 +48,7 @@ public ResourceLocation getModelLocation() { @Override public void update(World world, Network network, ItemPipe pipe, Attachment attachment, int ticks) { - if (ticks % type.tickInterval != 0) { + if (ticks % type.getTickInterval() != 0) { return; } @@ -74,7 +74,7 @@ private void update(Network network, ItemPipe pipe, Attachment attachment, Block return; } - ItemStack extracted = source.extractItem(firstSlot, type.itemsToExtract, true); + ItemStack extracted = source.extractItem(firstSlot, type.getItemsToExtract(), true); if (extracted.isEmpty()) { return; } @@ -99,7 +99,7 @@ private void update(Network network, ItemPipe pipe, Attachment attachment, Block return; } - ItemStack extractedActual = source.extractItem(firstSlot, type.itemsToExtract, false); + ItemStack extractedActual = source.extractItem(firstSlot, type.getItemsToExtract(), false); if (extractedActual.isEmpty()) { return; } @@ -175,20 +175,50 @@ public Attachment createNew(Direction dir) { } public enum Type { - BASIC(1, 20 * 3, 8), - IMPROVED(2, 20 * 2, 16), - ADVANCED(3, 20, 32), - ELITE(4, 10, 64), - ULTIMATE(5, 10, 64); + BASIC(1), + IMPROVED(2), + ADVANCED(3), + ELITE(4), + ULTIMATE(5); private final int tier; - private final int tickInterval; - private final int itemsToExtract; - Type(int tier, int tickInterval, int itemsToExtract) { + Type(int tier) { this.tier = tier; - this.tickInterval = tickInterval; - this.itemsToExtract = itemsToExtract; + } + + int getTickInterval() { + switch (this) { + case BASIC: + return RefinedPipes.SERVER_CONFIG.getBasicExtractorAttachment().getTickInterval(); + case IMPROVED: + return RefinedPipes.SERVER_CONFIG.getImprovedExtractorAttachment().getTickInterval(); + case ADVANCED: + return RefinedPipes.SERVER_CONFIG.getAdvancedExtractorAttachment().getTickInterval(); + case ELITE: + return RefinedPipes.SERVER_CONFIG.getEliteExtractorAttachment().getTickInterval(); + case ULTIMATE: + return RefinedPipes.SERVER_CONFIG.getUltimateExtractorAttachment().getTickInterval(); + default: + throw new RuntimeException("?"); + } + } + + int getItemsToExtract() { + switch (this) { + case BASIC: + return RefinedPipes.SERVER_CONFIG.getBasicExtractorAttachment().getItemsToExtract(); + case IMPROVED: + return RefinedPipes.SERVER_CONFIG.getImprovedExtractorAttachment().getItemsToExtract(); + case ADVANCED: + return RefinedPipes.SERVER_CONFIG.getAdvancedExtractorAttachment().getItemsToExtract(); + case ELITE: + return RefinedPipes.SERVER_CONFIG.getEliteExtractorAttachment().getItemsToExtract(); + case ULTIMATE: + return RefinedPipes.SERVER_CONFIG.getUltimateExtractorAttachment().getItemsToExtract(); + default: + throw new RuntimeException("?"); + } } ResourceLocation getId() {