Last active
July 21, 2017 03:52
-
-
Save pie-flavor/b08ae7276e0b947293c1ad27e1fdb18a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CopperRecipe implements SmeltingRecipe { | |
private ItemStackSnapshot exemplaryIngredient; | |
private ItemStackSnapshot exemplaryResult; | |
private Text ingredientName = Text.of(TextColors.WHITE, "Copper Ore"); | |
private Text resultName = Text.of(TextColors.WHITE, "Copper Nugget"); | |
{ | |
ItemStack ingredient = ItemStack.builder() | |
.itemType(ItemTypes.STONE) | |
.keyValue(Keys.STONE_TYPE, StoneTypes.GRANITE) | |
.keyValue(Keys.DISPLAY_NAME, ingredientName) | |
.build(); | |
exemplaryIngredient = ingredient.createSnapshot(); | |
ItemStack result = ItemStack.builder() | |
.itemType(ItemTypes.DYE) | |
.keyValue(Keys.DYE_COLOR, DyeColors.BROWN) | |
.keyValue(Keys.DISPLAY_NAME, resultName) | |
.build(); | |
exemplaryResult = result.createSnapshot(); | |
} | |
@Override | |
public ItemStackSnapshot getExemplaryIngredient() { | |
return exemplaryIngredient; | |
} | |
@Override | |
public ItemStackSnapshot getExemplaryResult() { | |
return exemplaryResult; | |
} | |
@Override | |
public Optional<SmeltingResult> getResult(ItemStackSnapshot ingredient) { | |
if (isValid(ingredient)) { | |
return Optional.of(new SmeltingResult(exemplaryResult, 0.6)); | |
} else { | |
return Optional.empty(); | |
} | |
} | |
@Override | |
public boolean isValid(ItemStackSnapshot ingredient) { | |
if (!ingredient.getType().equals(ItemTypes.STONE)) return false; | |
if (!ingredient.get(Keys.STONE_TYPE).get().equals(StoneTypes.GRANITE)) return false; | |
Optional<Text> name = ingredient.get(Keys.DISPLAY_NAME); | |
if (!name.isPresent() || !name.get().equals(ingredientName)) return false; | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment