mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
first pass at functional crusher.
This commit is contained in:
parent
04714de062
commit
86a89a96a8
5 changed files with 37 additions and 28 deletions
|
@ -718,7 +718,7 @@ e088aee52db067c15c72bfe743ac106b98ca4be2 data/actuallyadditions/recipes/colorcha
|
||||||
a4fb51f83c38bfebceeadde885d59632e355bf6d data/actuallyadditions/recipes/colorchange/yellow_terracotta.json
|
a4fb51f83c38bfebceeadde885d59632e355bf6d data/actuallyadditions/recipes/colorchange/yellow_terracotta.json
|
||||||
ca4f8d37d115eac5889542b04d1c01cd2e0cde43 data/actuallyadditions/recipes/colorchange/yellow_wool.json
|
ca4f8d37d115eac5889542b04d1c01cd2e0cde43 data/actuallyadditions/recipes/colorchange/yellow_wool.json
|
||||||
160466dfd10fafc2ae4b4130ca35220d4c2d2342 data/actuallyadditions/recipes/crate_keeper.json
|
160466dfd10fafc2ae4b4130ca35220d4c2d2342 data/actuallyadditions/recipes/crate_keeper.json
|
||||||
b76b843a60a1c456a11d3bb932a93ab3753d6f58 data/actuallyadditions/recipes/crushing/bone_crusher.json
|
341c5816febc417a36e516986f6d1461cf38cfed data/actuallyadditions/recipes/crushing/bone_crusher.json
|
||||||
293cecfa94d22e62bd817a3964e82dca4479d44d data/actuallyadditions/recipes/diamond_aiot.json
|
293cecfa94d22e62bd817a3964e82dca4479d44d data/actuallyadditions/recipes/diamond_aiot.json
|
||||||
abb220fb19dea7cf9afcd30fbe533d21b7c4e9c0 data/actuallyadditions/recipes/display_stand.json
|
abb220fb19dea7cf9afcd30fbe533d21b7c4e9c0 data/actuallyadditions/recipes/display_stand.json
|
||||||
f3465f5a05a931f4e5933508c2bc56de9c9eafe5 data/actuallyadditions/recipes/double_battery.json
|
f3465f5a05a931f4e5933508c2bc56de9c9eafe5 data/actuallyadditions/recipes/double_battery.json
|
||||||
|
|
|
@ -6,10 +6,12 @@
|
||||||
"result": [
|
"result": [
|
||||||
{
|
{
|
||||||
"item": "minecraft:bone_meal",
|
"item": "minecraft:bone_meal",
|
||||||
|
"count": 6,
|
||||||
"chance": 1.0
|
"chance": 1.0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"item": "minecraft:air",
|
"item": "minecraft:air",
|
||||||
|
"count": 0,
|
||||||
"chance": 0.0
|
"chance": 0.0
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -121,14 +121,18 @@ public class CrushingRecipe implements IRecipe<IInventory> {
|
||||||
if (resultList.size() < 1)
|
if (resultList.size() < 1)
|
||||||
throw new IllegalStateException(pRecipeId.toString() + ": Recipe must contain at least 1 result item");
|
throw new IllegalStateException(pRecipeId.toString() + ": Recipe must contain at least 1 result item");
|
||||||
|
|
||||||
ItemStack output1 = new ItemStack(JSONUtils.getAsItem(resultList.get(0).getAsJsonObject(), "item"));
|
JsonObject result1 = resultList.get(0).getAsJsonObject();
|
||||||
float chance1 = JSONUtils.getAsFloat(resultList.get(0).getAsJsonObject(), "chance");
|
int count1 = JSONUtils.getAsInt(result1, "count", 0);
|
||||||
|
ItemStack output1 = new ItemStack(JSONUtils.getAsItem(result1, "item"), count1);
|
||||||
|
float chance1 = JSONUtils.getAsFloat(result1, "chance");
|
||||||
|
|
||||||
ItemStack output2 = ItemStack.EMPTY;
|
ItemStack output2 = ItemStack.EMPTY;
|
||||||
float chance2 = 1.0f;
|
float chance2 = 1.0f;
|
||||||
if (resultList.size() > 1) {
|
if (resultList.size() > 1) {
|
||||||
output2 = new ItemStack(JSONUtils.getAsItem(resultList.get(1).getAsJsonObject(), "item"));
|
JsonObject result2 = resultList.get(1).getAsJsonObject();
|
||||||
chance2 = JSONUtils.getAsFloat(resultList.get(1).getAsJsonObject(), "chance");
|
int count2 = JSONUtils.getAsInt(result2, "count", 0);
|
||||||
|
output2 = new ItemStack(JSONUtils.getAsItem(result2, "item"), count2);
|
||||||
|
chance2 = JSONUtils.getAsFloat(result2, "chance");
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CrushingRecipe(pRecipeId, ingredient, output1, chance1, output2, chance2);
|
return new CrushingRecipe(pRecipeId, ingredient, output1, chance1, output2, chance2);
|
||||||
|
@ -182,10 +186,12 @@ public class CrushingRecipe implements IRecipe<IInventory> {
|
||||||
|
|
||||||
JsonObject result1 = new JsonObject();
|
JsonObject result1 = new JsonObject();
|
||||||
result1.addProperty("item", outputOne.asItem().getRegistryName().toString());
|
result1.addProperty("item", outputOne.asItem().getRegistryName().toString());
|
||||||
|
result1.addProperty("count", countOne);
|
||||||
result1.addProperty("chance", outputChance1);
|
result1.addProperty("chance", outputChance1);
|
||||||
|
|
||||||
JsonObject result2 = new JsonObject();
|
JsonObject result2 = new JsonObject();
|
||||||
result2.addProperty("item", outputTwo.asItem().getRegistryName().toString());
|
result2.addProperty("item", outputTwo.asItem().getRegistryName().toString());
|
||||||
|
result2.addProperty("count", countTwo);
|
||||||
result2.addProperty("chance", outputChance2);
|
result2.addProperty("chance", outputChance2);
|
||||||
|
|
||||||
JsonArray resultList = new JsonArray();
|
JsonArray resultList = new JsonArray();
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.tile;
|
package de.ellpeck.actuallyadditions.mod.tile;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
||||||
import de.ellpeck.actuallyadditions.mod.AASounds;
|
import de.ellpeck.actuallyadditions.mod.AASounds;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
import de.ellpeck.actuallyadditions.mod.blocks.ActuallyBlocks;
|
||||||
import de.ellpeck.actuallyadditions.mod.crafting.CrushingRecipe;
|
import de.ellpeck.actuallyadditions.mod.crafting.CrushingRecipe;
|
||||||
import de.ellpeck.actuallyadditions.mod.inventory.CrusherContainer;
|
import de.ellpeck.actuallyadditions.mod.inventory.CrusherContainer;
|
||||||
|
@ -37,6 +39,7 @@ import net.minecraftforge.common.util.LazyOptional;
|
||||||
import net.minecraftforge.energy.IEnergyStorage;
|
import net.minecraftforge.energy.IEnergyStorage;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class TileEntityCrusher extends TileEntityInventoryBase implements IButtonReactor, INamedContainerProvider {
|
public class TileEntityCrusher extends TileEntityInventoryBase implements IButtonReactor, INamedContainerProvider {
|
||||||
|
|
||||||
|
@ -186,18 +189,21 @@ public class TileEntityCrusher extends TileEntityInventoryBase implements IButto
|
||||||
return (slot, automation) -> !automation || slot == SLOT_OUTPUT_1_1 || slot == SLOT_OUTPUT_1_2 || slot == SLOT_OUTPUT_2_1 || slot == SLOT_OUTPUT_2_2;
|
return (slot, automation) -> !automation || slot == SLOT_OUTPUT_1_1 || slot == SLOT_OUTPUT_1_2 || slot == SLOT_OUTPUT_2_1 || slot == SLOT_OUTPUT_2_2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Optional<CrushingRecipe> getRecipeForInput(ItemStack itemStack) {
|
||||||
|
return ActuallyAdditionsAPI.CRUSHER_RECIPES.stream().filter($ -> $.matches(itemStack)).findFirst();
|
||||||
|
}
|
||||||
public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput) {
|
public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput) {
|
||||||
if (StackUtil.isValid(this.inv.getStackInSlot(theInput))) {
|
ItemStack inputStack = this.inv.getStackInSlot(theInput);
|
||||||
CrushingRecipe recipe = null;//CrusherRecipeRegistry.getRecipeFromInput(this.inv.getStackInSlot(theInput)); //TODO
|
if (!inputStack.isEmpty()) {
|
||||||
if (recipe == null) {
|
Optional<CrushingRecipe> recipeOpt = getRecipeForInput(inputStack);
|
||||||
|
if (!recipeOpt.isPresent()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
CrushingRecipe recipe = recipeOpt.get();
|
||||||
ItemStack outputOne = recipe.getOutputOne();
|
ItemStack outputOne = recipe.getOutputOne();
|
||||||
ItemStack outputTwo = recipe.getOutputTwo();
|
ItemStack outputTwo = recipe.getOutputTwo();
|
||||||
if (StackUtil.isValid(outputOne)) {
|
if (!outputOne.isEmpty()) {
|
||||||
if ((!StackUtil.isValid(this.inv.getStackInSlot(theFirstOutput)) || this.inv.getStackInSlot(theFirstOutput).sameItem(outputOne) && this.inv.getStackInSlot(theFirstOutput).getCount() <= this.inv.getStackInSlot(theFirstOutput).getMaxStackSize() - outputOne.getCount()) && (!StackUtil.isValid(outputTwo) || !StackUtil.isValid(this.inv.getStackInSlot(theSecondOutput)) || this.inv.getStackInSlot(theSecondOutput).sameItem(outputTwo) && this.inv.getStackInSlot(theSecondOutput).getCount() <= this.inv.getStackInSlot(theSecondOutput).getMaxStackSize() - outputTwo.getCount())) {
|
return (this.inv.getStackInSlot(theFirstOutput).isEmpty() || this.inv.getStackInSlot(theFirstOutput).sameItem(outputOne) && this.inv.getStackInSlot(theFirstOutput).getCount() <= this.inv.getStackInSlot(theFirstOutput).getMaxStackSize() - outputOne.getCount()) && (outputTwo.isEmpty() || this.inv.getStackInSlot(theSecondOutput).isEmpty() || this.inv.getStackInSlot(theSecondOutput).sameItem(outputTwo) && this.inv.getStackInSlot(theSecondOutput).getCount() <= this.inv.getStackInSlot(theSecondOutput).getMaxStackSize() - outputTwo.getCount());
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -210,18 +216,15 @@ public class TileEntityCrusher extends TileEntityInventoryBase implements IButto
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finishCrushing(int theInput, int theFirstOutput, int theSecondOutput) {
|
public void finishCrushing(int theInput, int theFirstOutput, int theSecondOutput) {
|
||||||
CrushingRecipe recipe = CrusherRecipeRegistry.getRecipeFromInput(this.inv.getStackInSlot(theInput));//TODO
|
Optional<CrushingRecipe> recipeOpt = getRecipeForInput(this.inv.getStackInSlot(theInput));
|
||||||
if (recipe == null) {
|
if (!recipeOpt.isPresent()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
CrushingRecipe recipe = recipeOpt.get();
|
||||||
|
|
||||||
ItemStack outputOne = recipe.getOutputOne();
|
ItemStack outputOne = recipe.getOutputOne();
|
||||||
if (StackUtil.isValid(outputOne)) {
|
if (!outputOne.isEmpty()) {
|
||||||
/* //TODO
|
if (this.inv.getStackInSlot(theFirstOutput).isEmpty()) {
|
||||||
if (outputOne.getDamage() == Util.WILDCARD) {
|
|
||||||
outputOne.setDamage(0);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (!StackUtil.isValid(this.inv.getStackInSlot(theFirstOutput))) {
|
|
||||||
this.inv.setStackInSlot(theFirstOutput, outputOne.copy());
|
this.inv.setStackInSlot(theFirstOutput, outputOne.copy());
|
||||||
} else if (this.inv.getStackInSlot(theFirstOutput).getItem() == outputOne.getItem()) {
|
} else if (this.inv.getStackInSlot(theFirstOutput).getItem() == outputOne.getItem()) {
|
||||||
this.inv.setStackInSlot(theFirstOutput, StackUtil.grow(this.inv.getStackInSlot(theFirstOutput), outputOne.getCount()));
|
this.inv.setStackInSlot(theFirstOutput, StackUtil.grow(this.inv.getStackInSlot(theFirstOutput), outputOne.getCount()));
|
||||||
|
@ -229,15 +232,10 @@ public class TileEntityCrusher extends TileEntityInventoryBase implements IButto
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack outputTwo = recipe.getOutputTwo();
|
ItemStack outputTwo = recipe.getOutputTwo();
|
||||||
if (StackUtil.isValid(outputTwo)) {
|
if (!outputTwo.isEmpty()) {
|
||||||
/* //TODO
|
|
||||||
if (outputTwo.getDamage() == Util.WILDCARD) {
|
|
||||||
outputTwo.setDamage(0);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
float rand = this.level.random.nextFloat();
|
float rand = this.level.random.nextFloat();
|
||||||
if (rand <= recipe.getSecondChance()) {
|
if (rand <= recipe.getSecondChance()) {
|
||||||
if (!StackUtil.isValid(this.inv.getStackInSlot(theSecondOutput))) {
|
if (this.inv.getStackInSlot(theSecondOutput).isEmpty()) {
|
||||||
this.inv.setStackInSlot(theSecondOutput, outputTwo.copy());
|
this.inv.setStackInSlot(theSecondOutput, outputTwo.copy());
|
||||||
} else if (this.inv.getStackInSlot(theSecondOutput).getItem() == outputTwo.getItem()) {
|
} else if (this.inv.getStackInSlot(theSecondOutput).getItem() == outputTwo.getItem()) {
|
||||||
this.inv.setStackInSlot(theSecondOutput, StackUtil.grow(this.inv.getStackInSlot(theSecondOutput), outputTwo.getCount()));
|
this.inv.setStackInSlot(theSecondOutput, StackUtil.grow(this.inv.getStackInSlot(theSecondOutput), outputTwo.getCount()));
|
||||||
|
|
|
@ -44,5 +44,8 @@ public class ResourceReloader implements IResourceManagerReloadListener {
|
||||||
|
|
||||||
ActuallyAdditionsAPI.MINING_LENS_RECIPES.clear();
|
ActuallyAdditionsAPI.MINING_LENS_RECIPES.clear();
|
||||||
ActuallyAdditionsAPI.MINING_LENS_RECIPES.addAll(recipeManager.getAllRecipesFor(ActuallyRecipes.Types.MINING_LENS));
|
ActuallyAdditionsAPI.MINING_LENS_RECIPES.addAll(recipeManager.getAllRecipesFor(ActuallyRecipes.Types.MINING_LENS));
|
||||||
|
|
||||||
|
ActuallyAdditionsAPI.CRUSHER_RECIPES.clear();
|
||||||
|
ActuallyAdditionsAPI.CRUSHER_RECIPES.addAll(recipeManager.getAllRecipesFor(ActuallyRecipes.Types.CRUSHING));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue