Skip to content

Commit

Permalink
Added config for fortune cookies and levers
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryLoenwind committed Jan 4, 2016
1 parent fea2a6a commit e1af83c
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 25 deletions.
6 changes: 6 additions & 0 deletions src/main/java/info/loenwind/enderioaddons/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@ public enum Config {
flowingMilkCuresPoison(Section.LIQUIDS, 0.001, "Chance that flowing milk will cure poison (applies once per tick)"), //
sourceMilkIsConsumedWhenCuringPoison(Section.LIQUIDS, 0.25, "Chance that a source block of milk will be consumed when curing poison"), //

fortuneCookiesEnabled(Section.RECIPES, true, "When enabled, the fortune cookies will be visible ingame"), //
fortuneCookiesCraftingEnabled(Section.RECIPES, true, "When enabled, the fortune cookies will have a crafting recipe"), //

leversEnabled(Section.RECIPES, "10,30,60,300",
"A comma-seperated list of durations in seconds. For these, self-reseting levers will be created. Set to 0 to disable the lever"), //

profilingEnabled(Section.DEV, false, "When enabled, profiling information will be written into the logfile"), //
;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package info.loenwind.enderioaddons.machine.rlever;

import info.loenwind.enderioaddons.EnderIOAddons;
import info.loenwind.enderioaddons.common.Log;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;

import net.minecraft.block.Block;
Expand All @@ -13,10 +17,8 @@

public class BlockRLever extends BlockLever {

public static Block blockRLever10;
public static Block blockRLever30;
public static Block blockRLever60;
public static Block blockRLever300;
private static List<Integer> delays = null;
private static List<Block> blocks = null;

private int delay = 1;

Expand All @@ -34,14 +36,40 @@ public BlockRLever() {
}

public static void create() {
blockRLever10 = new BlockRLever().setDelay(10 * 20).setBlockName("rlever10");
GameRegistry.registerBlock(blockRLever10, "rlever10");
blockRLever30 = new BlockRLever().setDelay(30 * 20).setBlockName("rlever30");
GameRegistry.registerBlock(blockRLever30, "rlever30");
blockRLever60 = new BlockRLever().setDelay(60 * 20).setBlockName("rlever60");
GameRegistry.registerBlock(blockRLever60, "rlever60");
blockRLever300 = new BlockRLever().setDelay(300 * 20).setBlockName("rlever300");
GameRegistry.registerBlock(blockRLever300, "rlever300");
getLevers();
blocks = new ArrayList<>();
for (Integer value : delays) {
Block lever = new BlockRLever().setDelay(value).setBlockName("rlever" + value);
GameRegistry.registerBlock(lever, "rlever" + value);
blocks.add(lever);
}
}

public static List<Integer> getLevers() {
if (delays == null) {
delays = new ArrayList<>();
String s = info.loenwind.enderioaddons.config.Config.leversEnabled.getString();
s = s.replaceAll("[^0-9,]", "");
String[] split = s.split(",");
for (String string : split) {
if (string != null && !string.isEmpty()) {
try {
final Integer value = Integer.valueOf(string);
if (value > 0 && value <= 60 * 60 * 24) { // max 1 day
delays.add(value);
}
} catch (NumberFormatException e) {
Log.error("Could not parse lever time setting '" + string + "'");
}
}
}
Collections.sort(delays);
}
return delays;
}

public static List<Block> getBlocks() {
return blocks;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ public void loadConfig() {
API.registerRecipeHandler(new TeaserRecipeHandler());
API.registerUsageHandler(new TeaserRecipeHandler());

if (!Config.fortuneCookiesEnabled.getBoolean()) {
API.hideItem(new ItemStack(ItemMachinePart.itemMachinePart, 1, MachinePart.COOKIE.ordinal()));
}
API.hideItem(new ItemStack(ItemMachinePart.itemMachinePart, 1, MachinePart.COOKIESTRIP.ordinal()));

API.hideItem(new ItemStack(AbstractBlockFramework.blockDummy, 1, OreDictionary.WILDCARD_VALUE));
Expand Down
65 changes: 52 additions & 13 deletions src/main/java/info/loenwind/enderioaddons/recipe/Recipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
import info.loenwind.enderioaddons.machine.part.ItemMachinePart;
import info.loenwind.enderioaddons.machine.part.MachinePart;
import info.loenwind.enderioaddons.machine.rlever.BlockRLever;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -158,8 +163,10 @@ public void init(FMLInitializationEvent event) {
}

// Fortune Cookie
ItemStack fortune = new ItemStack(ItemMachinePart.itemMachinePart, 1, MachinePart.COOKIE.ordinal());
addShaped(fortune, "cgc", "cpc", "gcg", 'c', Items.cookie, 'g', "nuggetGold", 'p', Items.paper);
if (Config.fortuneCookiesEnabled.getBoolean() && Config.fortuneCookiesCraftingEnabled.getBoolean()) {
ItemStack fortune = new ItemStack(ItemMachinePart.itemMachinePart, 1, MachinePart.COOKIE.ordinal());
addShaped(fortune, "cgc", "cpc", "gcg", 'c', Items.cookie, 'g', "nuggetGold", 'p', Items.paper);
}

// Drain
if (Config.drainEnabled.getBoolean()) {
Expand Down Expand Up @@ -425,20 +432,52 @@ public void init(FMLInitializationEvent event) {
}

// Lever
addShapeless(BlockRLever.blockRLever10, Blocks.lever, "dustRedstone");

addShapeless(BlockRLever.blockRLever30, BlockRLever.blockRLever10, "dustRedstone");
addShapeless(BlockRLever.blockRLever30, Blocks.lever, "dustRedstone", "dustRedstone");
List<Block> levers = BlockRLever.getBlocks();
List<Block> usedLevers = new ArrayList<>();
int rs = 0;
for (Block block : levers) {
addShapelessWT(block, Blocks.lever, "dustRedstone", ++rs);
int rsl = rs;
for (Block block0 : usedLevers) {
addShapelessWT(block, block0, "dustRedstone", --rsl);
}
usedLevers.add(block);
}
}

addShapeless(BlockRLever.blockRLever60, BlockRLever.blockRLever10, "dustRedstone", "dustRedstone");
addShapeless(BlockRLever.blockRLever60, BlockRLever.blockRLever30, "dustRedstone");
addShapeless(BlockRLever.blockRLever60, Blocks.lever, "dustRedstone", "dustRedstone", "dustRedstone");
@SuppressWarnings("unused")
private static void addShapelessWT(Block block, Object in, int count) {
if (count > 0 && count <= 9) {
Object[] ingr = new Object[count];
for (int i = 0; i < count; i++) {
ingr[i] = in;
}
addShapeless(block, ingr);
}
}

addShapeless(BlockRLever.blockRLever300, BlockRLever.blockRLever10, "dustRedstone", "dustRedstone", "dustRedstone");
addShapeless(BlockRLever.blockRLever300, BlockRLever.blockRLever30, "dustRedstone", "dustRedstone");
addShapeless(BlockRLever.blockRLever300, BlockRLever.blockRLever60, "dustRedstone");
addShapeless(BlockRLever.blockRLever300, Blocks.lever, "dustRedstone", "dustRedstone", "dustRedstone", "dustRedstone");
private static void addShapelessWT(Block block, Object in0, Object in, int count) {
if (count >= 0 && count < 9) {
Object[] ingr = new Object[count + 1];
ingr[0] = in0;
for (int i = 0; i < count; i++) {
ingr[i + 1] = in;
}
addShapeless(block, ingr);
}
}

@SuppressWarnings("unused")
private static void addShapelessWT(Block block, Object in0, Object in1, Object in, int count) {
if (count >= 0 && count < 8) {
Object[] ingr = new Object[count + 2];
ingr[0] = in0;
ingr[1] = in1;
for (int i = 0; i < count; i++) {
ingr[i + 2] = in;
}
addShapeless(block, ingr);
}
}

private static boolean isAnyFrameworkMachineEnabled() {
Expand Down

0 comments on commit e1af83c

Please sign in to comment.