Pure daisy now allows variable time recipes, closes #137.

This commit is contained in:
Vincent Lee committed 2016-02-26 19:48:43 -06:00
1 parent 47001131b0
commit 18ea3e6bfb
3 files changed
+31 -13

No files matched your search

@@ -413,13 +413,24 @@ public final class BotaniaAPI {
}
/**
* Registers a Pure Daisy Recipe.
* Registers a Pure Daisy Recipe with the default time of 150 ticks per block
* @param input The block that works as an input for the recipe. Can be a Block or an oredict String.
* @param outputState The blockstate to be placed upon recipe completion.
* @return The recipe created.
*/
public static RecipePureDaisy registerPureDaisyRecipe(Object input, IBlockState outputState) {
RecipePureDaisy recipe = new RecipePureDaisy(input, outputState);
return registerPureDaisyRecipe(input, outputState, 150);
}
/**
* Registers a Pure Daisy Recipe.
* @param input The block that works as an input for the recipe. Can be a Block or an oredict String.
* @param outputState The blockstate to be placed upon recipe completion.
* @param time The amount of time in ticks to complete this recipe
* @return The recipe created.
*/
public static RecipePureDaisy registerPureDaisyRecipe(Object input, IBlockState outputState, int time) {
RecipePureDaisy recipe = new RecipePureDaisy(input, outputState, time);
pureDaisyRecipes.add(recipe);
return recipe;
}
@@ -14,6 +14,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.common.base.Preconditions;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.item.ItemStack;
@@ -26,15 +27,18 @@ public class RecipePureDaisy {
private static final Map<String, List<ItemStack>> oreMap = new HashMap<>();
Object input;
IBlockState outputState;
private final Object input;
private final IBlockState outputState;
private final int time;
public RecipePureDaisy(Object input, IBlockState state) {
public RecipePureDaisy(Object input, IBlockState state, int time) {
Preconditions.checkArgument(time >= 0, "Time must be nonnegative");
this.input = input;
this.outputState = state;
this.time = time;
if(input != null && !(input instanceof String || input instanceof Block))
throw new IllegalArgumentException("input must be an oredict String or a Block.");
}
/**
@@ -92,4 +96,8 @@ public class RecipePureDaisy {
return outputState;
}
public int getTime() {
return time;
}
}
@@ -29,9 +29,6 @@ public class SubTilePureDaisy extends SubTileEntity {
private static final String TAG_POSITION = "position";
private static final String TAG_TICKS_REMAINING = "ticksRemaining";
private static final int TOTAL_TIME = 1200;
private static final int TIME_PER = TOTAL_TIME / 8;
private static final BlockPos[] POSITIONS = {
new BlockPos(-1, 0, -1 ),
new BlockPos(-1, 0, 0 ),
@@ -44,7 +41,7 @@ public class SubTilePureDaisy extends SubTileEntity {
};
int positionAt = 0;
int[] ticksRemaining = new int[] { TIME_PER, TIME_PER, TIME_PER, TIME_PER, TIME_PER, TIME_PER, TIME_PER, TIME_PER };
int[] ticksRemaining = { -1, -1, -1, -1, -1, -1, -1, -1};
@Override
public void onUpdate() {
@@ -68,12 +65,14 @@ public class SubTilePureDaisy extends SubTileEntity {
if(recipe != null) {
ticksRemaining[positionAt] = ticksRemaining[positionAt] - 1;
if (ticksRemaining[positionAt] == -1)
ticksRemaining[positionAt] = recipe.getTime();
ticksRemaining[positionAt]--;
Botania.proxy.sparkleFX(supertile.getWorld(), coords.getX() + Math.random(), coords.getY() + Math.random(), coords.getZ() + Math.random(), 1F, 1F, 1F, (float) Math.random(), 5);
if(ticksRemaining[positionAt] <= 0) {
ticksRemaining[positionAt] = TIME_PER;
ticksRemaining[positionAt] = -1;
if(recipe.set(world,coords, this)) {
for(int i = 0; i < 25; i++) {
@@ -87,7 +86,7 @@ public class SubTilePureDaisy extends SubTileEntity {
supertile.getWorld().playAuxSFX(2001, coords, Block.getStateId(recipe.getOutputState()));
}
}
} else ticksRemaining[positionAt] = TIME_PER;
} else ticksRemaining[positionAt] = -1;
}
}