Skip to content

Commit

Permalink
Crush piston mech works with sticky pistons, and fixed errors in recipe
Browse files Browse the repository at this point in the history
results causing errors in console, it now warns that the result is
invalid and disregards the recipe.
  • Loading branch information
Matthew authored and Matthew committed Feb 12, 2013
1 parent 96bc366 commit 7170f93
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/main/java/com/sk89q/craftbook/mech/BetterPistons.java
Expand Up @@ -169,8 +169,6 @@ public void onBlockRedstoneChange(SourcedBlockRedstoneEvent event) {

if(type == Types.CRUSH && event.getNewCurrent() > event.getOldCurrent()) {
PistonBaseMaterial piston = (PistonBaseMaterial) trigger.getState().getData();
if(piston.isSticky())
return;
piston.setPowered(false);
if(trigger.getRelative(piston.getFacing()).getTypeId() == BlockID.BEDROCK)
return;
Expand Down
@@ -0,0 +1,15 @@
package com.sk89q.craftbook.mech.crafting;

import com.sk89q.craftbook.util.exceptions.CraftbookException;

public class InvalidCraftingException extends CraftbookException {

/**
*
*/
private static final long serialVersionUID = 4305166656444438242L;

public InvalidCraftingException(String message) {
super(message);
}
}
17 changes: 13 additions & 4 deletions src/main/java/com/sk89q/craftbook/mech/crafting/RecipeManager.java
Expand Up @@ -5,6 +5,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.logging.Logger;

Expand Down Expand Up @@ -49,7 +50,11 @@ public void load() {
List<String> keys = config.getKeys("crafting-recipes");
if (keys != null) {
for (String key : keys) {
recipes.add(new Recipe(key, config));
try {
recipes.add(new Recipe(key, config));
} catch (InvalidCraftingException e) {
logger.warning(e.getMessage());
}
}
}
}
Expand Down Expand Up @@ -83,7 +88,7 @@ public boolean hasAdvancedData() {
return false;
}

private Recipe(String id, YAMLProcessor config) {
private Recipe(String id, YAMLProcessor config) throws InvalidCraftingException {

this.id = id;
this.config = config;
Expand All @@ -92,7 +97,7 @@ private Recipe(String id, YAMLProcessor config) {
load();
}

private void load() {
private void load() throws InvalidCraftingException {

type = RecipeType.getTypeFromName(config.getString("crafting-recipes." + id + ".type"));
if (type != RecipeType.SHAPED2X2 && type != RecipeType.SHAPED3X3) {
Expand All @@ -101,7 +106,11 @@ private void load() {
items = getHashItems("crafting-recipes." + id + ".ingredients");
shape = config.getStringList("crafting-recipes." + id + ".shape", Arrays.asList(""));
}
result = getItems("crafting-recipes." + id + ".results").iterator().next();
Iterator<CraftingItemStack> iterator = getItems("crafting-recipes." + id + ".results").iterator();
if(iterator.hasNext())
result = iterator.next();
else
throw new InvalidCraftingException("Result is invalid in recipe: "+ id);
}

private HashMap<CraftingItemStack, Character> getHashItems(String path) {
Expand Down

0 comments on commit 7170f93

Please sign in to comment.