Skip to content

Instantly share code, notes, and snippets.

@pie-flavor
Last active July 21, 2017 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pie-flavor/b08ae7276e0b947293c1ad27e1fdb18a to your computer and use it in GitHub Desktop.
Save pie-flavor/b08ae7276e0b947293c1ad27e1fdb18a to your computer and use it in GitHub Desktop.
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