Skip to content
This repository has been archived by the owner on Nov 18, 2023. It is now read-only.

Commit

Permalink
Added a config file
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Mar 27, 2020
1 parent 1bbc989 commit f5dcdf8
Show file tree
Hide file tree
Showing 5 changed files with 176 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/raoulvdberge/refinedpipes/RefinedPipes.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,20 +11,25 @@
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)
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);
Expand Down
112 changes: 112 additions & 0 deletions src/main/java/com/raoulvdberge/refinedpipes/config/ServerConfig.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,31 @@
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() {
return tier;
}

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<ItemPipeTileEntity> getTileType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit f5dcdf8

Please sign in to comment.