Skip to content

Commit

Permalink
Fix Stan Hebben's weirdness
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Feb 12, 2017
1 parent 7e94e98 commit 92aae33
Show file tree
Hide file tree
Showing 16 changed files with 109 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package nova.core.wrapper.mc.forge.v17.recipes;

import nova.core.item.Item;
import nova.core.recipes.crafting.SpecificItemIngredient;
import nova.core.recipes.ingredient.SpecificItemIngredient;
import nova.internal.core.Game;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import net.minecraft.item.crafting.IRecipe;
import nova.core.event.RecipeEvent;
import nova.core.item.Item;
import nova.core.recipes.crafting.ItemIngredient;
import nova.core.recipes.ingredient.ItemIngredient;
import nova.core.recipes.RecipeManager;
import nova.core.recipes.crafting.CraftingRecipe;
import nova.core.recipes.smelting.SmeltingRecipe;
Expand Down Expand Up @@ -142,9 +142,9 @@ private void onMinecraftRecipeRemoved(IRecipe recipe) {
private void onNOVASmeltingAdded(RecipeEvent.Add<SmeltingRecipe> evt) {
SmeltingRecipe recipe = evt.recipe;

Collection<Item> inputs = recipe.getInput().flatMap(ItemIngredient::getExampleItems).orElse(Collections.emptyList());
Collection<Item> inputs = recipe.getInput().map(ItemIngredient::getExampleItems).orElse(Collections.emptyList());

final Optional<ItemStack> output = recipe.getNominalOutput().map(ItemConverter.instance()::toNative);
final Optional<ItemStack> output = recipe.getExampleOutput().map(ItemConverter.instance()::toNative);
if (!output.isPresent())
return;

Expand All @@ -154,7 +154,8 @@ private void onNOVASmeltingAdded(RecipeEvent.Add<SmeltingRecipe> evt) {
private void onNOVASmeltingRemoved(RecipeEvent.Remove<SmeltingRecipe> evt) {
SmeltingRecipe recipe = evt.recipe;

Collection<Item> inputs = recipe.getInput().flatMap(ItemIngredient::getExampleItems).orElse(Collections.emptyList());
Collection<Item> inputs = recipe.getInput().map(ItemIngredient::getExampleItems).orElse(Collections.emptyList());
@SuppressWarnings("unchecked")
Map<ItemStack, ItemStack> smeltingList = FurnaceRecipes.smelting().getSmeltingList();
inputs.stream().map(ItemConverter.instance()::toNative).forEach(input -> smeltingList.remove(input));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
import net.minecraftforge.oredict.ShapelessOreRecipe;
import nova.core.item.Item;
import nova.core.recipes.crafting.CraftingRecipe;
import nova.core.recipes.crafting.ItemIngredient;
import nova.core.recipes.crafting.OreItemIngredient;
import nova.core.recipes.ingredient.ItemIngredient;
import nova.core.recipes.ingredient.OreItemIngredient;
import nova.core.recipes.crafting.ShapedCraftingRecipe;
import nova.core.recipes.crafting.ShapelessCraftingRecipe;
import nova.core.recipes.crafting.SpecificItemIngredient;
import nova.core.recipes.ingredient.SpecificItemIngredient;
import nova.core.wrapper.mc.forge.v17.util.ReflectionUtil;
import nova.internal.core.Game;

Expand Down Expand Up @@ -110,7 +110,7 @@ private static String findOreDictEntryFor(List ingredient) {
}

private static ItemStack wrapSpecific(SpecificItemIngredient ingredient) {
for (Item item : ingredient.getExampleItems().get()) {
for (Item item : ingredient.getExampleItems()) {
return Game.natives().toNative(item.getFactory().build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
package nova.core.wrapper.mc.forge.v18.recipes;

import nova.core.item.Item;
import nova.core.recipes.crafting.SpecificItemIngredient;
import nova.core.recipes.ingredient.SpecificItemIngredient;
import nova.internal.core.Game;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import net.minecraft.item.crafting.IRecipe;
import nova.core.event.RecipeEvent;
import nova.core.item.Item;
import nova.core.recipes.crafting.ItemIngredient;
import nova.core.recipes.ingredient.ItemIngredient;
import nova.core.recipes.RecipeManager;
import nova.core.recipes.crafting.CraftingRecipe;
import nova.core.recipes.smelting.SmeltingRecipe;
Expand Down Expand Up @@ -142,9 +142,9 @@ private void onMinecraftRecipeRemoved(IRecipe recipe) {
private void onNOVASmeltingAdded(RecipeEvent.Add<SmeltingRecipe> evt) {
SmeltingRecipe recipe = evt.recipe;

Collection<Item> inputs = recipe.getInput().flatMap(ItemIngredient::getExampleItems).orElse(Collections.emptyList());
Collection<Item> inputs = recipe.getInput().map(ItemIngredient::getExampleItems).orElse(Collections.emptyList());

final Optional<ItemStack> output = recipe.getNominalOutput().map(ItemConverter.instance()::toNative);
final Optional<ItemStack> output = recipe.getExampleOutput().map(ItemConverter.instance()::toNative);
if (!output.isPresent())
return;

Expand All @@ -154,7 +154,8 @@ private void onNOVASmeltingAdded(RecipeEvent.Add<SmeltingRecipe> evt) {
private void onNOVASmeltingRemoved(RecipeEvent.Remove<SmeltingRecipe> evt) {
SmeltingRecipe recipe = evt.recipe;

Collection<Item> inputs = recipe.getInput().flatMap(ItemIngredient::getExampleItems).orElse(Collections.emptyList());
Collection<Item> inputs = recipe.getInput().map(ItemIngredient::getExampleItems).orElse(Collections.emptyList());
@SuppressWarnings("unchecked")
Map<ItemStack, ItemStack> smeltingList = FurnaceRecipes.instance().getSmeltingList();
inputs.stream().map(ItemConverter.instance()::toNative).forEach(input -> smeltingList.remove(input));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
import net.minecraftforge.oredict.ShapelessOreRecipe;
import nova.core.item.Item;
import nova.core.recipes.crafting.CraftingRecipe;
import nova.core.recipes.crafting.ItemIngredient;
import nova.core.recipes.crafting.OreItemIngredient;
import nova.core.recipes.ingredient.ItemIngredient;
import nova.core.recipes.ingredient.OreItemIngredient;
import nova.core.recipes.crafting.ShapedCraftingRecipe;
import nova.core.recipes.crafting.ShapelessCraftingRecipe;
import nova.core.recipes.crafting.SpecificItemIngredient;
import nova.core.recipes.ingredient.SpecificItemIngredient;
import nova.core.util.Identifiable;
import nova.core.wrapper.mc.forge.v18.util.ReflectionUtil;
import nova.internal.core.Game;

Expand Down Expand Up @@ -84,11 +85,11 @@ private static ItemIngredient getIngredient(Object ingredient) {
if (ingredient == null) {
return null;
} else if (ingredient instanceof ItemStack) {
return new SpecificItemIngredient(((Item) Game.natives().toNova(ingredient)).getID());
return new SpecificItemIngredient(((Identifiable) Game.natives().toNova(ingredient)).getID());
} else if (ingredient instanceof String) {
return new OreItemIngredient((String) ingredient);
} else if (ingredient instanceof List) {
String oreDictEntry = findOreDictEntryFor((List) ingredient);
String oreDictEntry = findOreDictEntryFor((List<?>) ingredient);
if (oreDictEntry == null) {
return null;
}
Expand All @@ -99,7 +100,7 @@ private static ItemIngredient getIngredient(Object ingredient) {
}
}

private static String findOreDictEntryFor(List ingredient) {
private static String findOreDictEntryFor(List<?> ingredient) {
for (String key : net.minecraftforge.oredict.OreDictionary.getOreNames()) {
if (net.minecraftforge.oredict.OreDictionary.getOres(key).equals(ingredient)) {
return key;
Expand All @@ -110,7 +111,7 @@ private static String findOreDictEntryFor(List ingredient) {
}

private static ItemStack wrapSpecific(SpecificItemIngredient ingredient) {
for (Item item : ingredient.getExampleItems().get()) {
for (Item item : ingredient.getExampleItems()) {
return Game.natives().toNative(item.getFactory().build());
}

Expand Down Expand Up @@ -139,20 +140,21 @@ public static IRecipe convert(ShapelessCraftingRecipe recipe) {
ItemIngredient[] ingredients = recipe.getIngredients();
int type = getRecipeType(ingredients);

if (type == TYPE_BASIC) {
ItemStack[] items = new ItemStack[ingredients.length];
for (int i = 0; i < ingredients.length; i++) {
items[i] = wrapSpecific((SpecificItemIngredient) ingredients[i]);
}
return new ShapelessRecipeBasic(items, recipe);
} else if (type == TYPE_ORE) {
Object[] items = new Object[ingredients.length];
for (int i = 0; i < ingredients.length; i++) {
items[i] = getInternal(ingredients[i]);
}
return new ShapelessRecipeOre(items, recipe);
} else {
return new NovaCraftingRecipe(recipe);
switch (type) {
case TYPE_BASIC: {
ItemStack[] items = new ItemStack[ingredients.length];
for (int i = 0; i < ingredients.length; i++) {
items[i] = wrapSpecific((SpecificItemIngredient) ingredients[i]);
}
return new ShapelessRecipeBasic(items, recipe);
} case TYPE_ORE: {
Object[] items = new Object[ingredients.length];
for (int i = 0; i < ingredients.length; i++) {
items[i] = getInternal(ingredients[i]);
}
return new ShapelessRecipeOre(items, recipe);
} default:
return new NovaCraftingRecipe(recipe);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/nova/core/recipes/crafting/CraftingRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import nova.core.recipes.Recipe;

import java.util.Collection;
import java.util.Collections;
import java.util.Optional;

/**
Expand Down Expand Up @@ -73,7 +74,7 @@ public interface CraftingRecipe extends Recipe {
*
* @return The items
*/
default Optional<Collection<String>> getPossibleItemsInFirstSlot() {
return Optional.empty();
default Collection<String> getPossibleItemsInFirstSlot() {
return Collections.emptyList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ public Optional<CraftingRecipe> getRecipe(CraftingGrid grid) {
// #######################

private <T extends CraftingRecipe> void onCraftingRecipeAdded(RecipeEvent.Add<T> evt) {
Optional<Collection<String>> possibleFirstItemIds = evt.recipe.getPossibleItemsInFirstSlot();
if (possibleFirstItemIds.isPresent()) {
for (String itemId : possibleFirstItemIds.get()) {
Collection<String> possibleFirstItemIds = evt.recipe.getPossibleItemsInFirstSlot();
if (!possibleFirstItemIds.isEmpty()) {
for (String itemId : possibleFirstItemIds) {
staticRecipes.put(itemId, evt.recipe);
}
} else {
Expand All @@ -117,9 +117,9 @@ private <T extends CraftingRecipe> void onCraftingRecipeAdded(RecipeEvent.Add<T>
}

private <T extends CraftingRecipe> void onCraftingRecipeRemoved(RecipeEvent.Remove<T> evt) {
Optional<Collection<String>> possibleFirstItemIds = evt.recipe.getPossibleItemsInFirstSlot();
if (possibleFirstItemIds.isPresent()) {
for (String itemId : possibleFirstItemIds.get()) {
Collection<String> possibleFirstItemIds = evt.recipe.getPossibleItemsInFirstSlot();
if (!possibleFirstItemIds.isEmpty()) {
for (String itemId : possibleFirstItemIds) {
staticRecipes.remove(itemId, evt.recipe);
}
} else {
Expand Down
26 changes: 16 additions & 10 deletions src/main/java/nova/core/recipes/crafting/ShapedCraftingRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@

package nova.core.recipes.crafting;

import nova.core.recipes.ingredient.ItemIngredient;
import nova.core.item.Item;
import org.apache.commons.math3.geometry.euclidean.twod.Vector2D;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -272,22 +274,22 @@ public void consumeItems(CraftingGrid craftingGrid) {
}

@Override
public Optional<Collection<String>> getPossibleItemsInFirstSlot() {
public Collection<String> getPossibleItemsInFirstSlot() {
if (isMirrored()) {
Optional<Collection<String>> optionsForFirstItem = ingredients[0].getPossibleItemIds();
if (!optionsForFirstItem.isPresent()) {
return Optional.empty();
Collection<String> optionsForFirstItem = ingredients[0].getPossibleItemIds();
if (optionsForFirstItem.isEmpty()) {
return Collections.emptyList();
}

Optional<Collection<String>> optionsForSecondItem = ingredients[lastIngredientIndexOnFirstLine].getPossibleItemIds();
if (!optionsForSecondItem.isPresent()) {
return Optional.empty();
Collection<String> optionsForSecondItem = ingredients[lastIngredientIndexOnFirstLine].getPossibleItemIds();
if (optionsForFirstItem.isEmpty()) {
return Collections.emptyList();
}

Set<String> result = new HashSet<>();
result.addAll(optionsForFirstItem.get());
result.addAll(optionsForSecondItem.get());
return Optional.of(result);
result.addAll(optionsForFirstItem);
result.addAll(optionsForSecondItem);
return result;
} else {
return ingredients[0].getPossibleItemIds();
}
Expand Down Expand Up @@ -403,12 +405,14 @@ private NonMirroredMapping(Vector2D firstItemOffset) {
firstItemOffset.getY() - posy[0]));
}

@Override
public Optional<Item> getStack(CraftingGrid craftingGrid, int ingredient) {
return craftingGrid.getStack(
offsetX + posx[ingredient],
offsetY + posy[ingredient]);
}

@Override
public void setStack(CraftingGrid craftingGrid, int ingredient, Optional<Item> value) {
craftingGrid.setStack(
offsetX + posx[ingredient],
Expand All @@ -426,12 +430,14 @@ private MirroredMapping(Vector2D firstItemOffset, int craftingGridWidth) {
firstItemOffset.getY() - posy[0]));
}

@Override
public Optional<Item> getStack(CraftingGrid craftingGrid, int ingredient) {
return craftingGrid.getStack(
craftingGrid.getWidth() - (offsetX + posx[ingredient]) - 1,
offsetY + posy[ingredient]);
}

@Override
public void setStack(CraftingGrid craftingGrid, int ingredient, Optional<Item> value) {
craftingGrid.setStack(
craftingGrid.getWidth() - (offsetX + posx[ingredient]) - 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package nova.core.recipes.crafting;

import nova.core.recipes.ingredient.ItemIngredient;
import nova.core.item.Item;

import java.util.HashMap;
Expand All @@ -35,11 +36,11 @@ public class ShapelessCraftingRecipe implements CraftingRecipe {
private final RecipeFunction recipeFunction;
private final ItemIngredient[] ingredients;

public ShapelessCraftingRecipe(Item output, ItemIngredient[] ingredients) {
public ShapelessCraftingRecipe(Item output, ItemIngredient... ingredients) {
this(output, (crafting, tagged) -> Optional.of(output), ingredients);
}

public ShapelessCraftingRecipe(Item nominalOutput, RecipeFunction recipeFunction, ItemIngredient[] ingredients) {
public ShapelessCraftingRecipe(Item nominalOutput, RecipeFunction recipeFunction, ItemIngredient... ingredients) {
this.nominalOutput = nominalOutput;
this.recipeFunction = recipeFunction;
this.ingredients = ingredients;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
* along with NOVA. If not, see <http://www.gnu.org/licenses/>.
*/

package nova.core.recipes.crafting;
package nova.core.recipes.ingredient;

import nova.core.block.BlockFactory;
import nova.core.item.Item;
import nova.core.item.ItemFactory;
import nova.core.recipes.crafting.CraftingGrid;

import java.util.Collection;
import java.util.Optional;
Expand Down Expand Up @@ -81,15 +82,15 @@ static ItemIngredient forDictionary(String id) {
*
* @return possible items
*/
Optional<Collection<String>> getPossibleItemIds();
Collection<String> getPossibleItemIds();

/**
* Returns a list of example items. This list could be used to render
* ingredients when displayed to users.
*
* @return example items
*/
Optional<Collection<Item>> getExampleItems();
Collection<Item> getExampleItems();

/**
* Checks if this ingredient is a subset of another ingredient. An
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@
* along with NOVA. If not, see <http://www.gnu.org/licenses/>.
*/

package nova.core.recipes.crafting;
package nova.core.recipes.ingredient;

import nova.core.item.Item;
import nova.core.recipes.crafting.CraftingGrid;
import nova.internal.core.Game;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

Expand All @@ -45,16 +44,13 @@ public String getName() {
}

@Override
public Optional<Collection<String>> getPossibleItemIds() {
return Optional.of(Game.itemDictionary().get(name).stream().map(Item::getID).collect(Collectors.toList()));
public Collection<String> getPossibleItemIds() {
return Game.itemDictionary().get(name).stream().map(Item::getID).collect(Collectors.toList());
}

@Override
public Optional<Collection<Item>> getExampleItems() {
List<Item> result = new ArrayList<Item>();


return Optional.of(Game.itemDictionary().get(name));
public Collection<Item> getExampleItems() {
return Game.itemDictionary().get(name);
}

@Override
Expand Down
Loading

0 comments on commit 92aae33

Please sign in to comment.