Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package WayofTime.alchemicalWizardry.api.alchemy;

import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;

public class AlchemyRecipe {

private static final int MAX_INPUT_SLOTS = 5;

private final ItemStack output;
private final ItemStack[] recipe;
private final int bloodOrbLevel;
Expand All @@ -23,35 +24,13 @@ public boolean doesRecipeMatch(ItemStack[] items, int slottedBloodOrbLevel) {
return false;
}

ItemStack[] recipe;

if (items.length < 5) {
if (items.length < MAX_INPUT_SLOTS) {
return false;
}

if (this.recipe.length != 5) {
ItemStack[] newRecipe = new ItemStack[5];

for (int i = 0; i < 5; i++) {
if (i + 1 > this.recipe.length) {
newRecipe[i] = null;
} else {
newRecipe[i] = this.recipe[i];
}
}

recipe = newRecipe;
} else {
recipe = this.recipe;
}

boolean[] checkList = new boolean[5];
boolean[] checkList = new boolean[MAX_INPUT_SLOTS];

for (int i = 0; i < 5; i++) {
checkList[i] = false;
}

for (int i = 0; i < 5; i++) {
for (int i = 0; i < Math.min(recipe.length, MAX_INPUT_SLOTS); i++) {
ItemStack recipeItemStack = recipe[i];

if (recipeItemStack == null) {
Expand All @@ -60,7 +39,7 @@ public boolean doesRecipeMatch(ItemStack[] items, int slottedBloodOrbLevel) {

boolean test = false;

for (int j = 0; j < 5; j++) {
for (int j = 0; j < MAX_INPUT_SLOTS; j++) {
if (checkList[j]) {
continue;
}
Expand All @@ -71,20 +50,6 @@ public boolean doesRecipeMatch(ItemStack[] items, int slottedBloodOrbLevel) {
continue;
}

boolean quickTest = false;

if (recipeItemStack.getItem() instanceof ItemBlock) {
if (checkedItemStack.getItem() instanceof ItemBlock) {
quickTest = true;
}
} else if (!(checkedItemStack.getItem() instanceof ItemBlock)) {
quickTest = true;
}

if (!quickTest) {
continue;
}

if ((checkedItemStack.getItemDamage() == recipeItemStack.getItemDamage()
|| OreDictionary.WILDCARD_VALUE == recipeItemStack.getItemDamage())
&& checkedItemStack.getItem() == recipeItemStack.getItem()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void registerRecipe(ItemStack output, int amountNeeded, ItemStack[
recipes.add(new AlchemyRecipe(output, amountNeeded, recipe, bloodOrbLevel));
}

public static ItemStack getResult(ItemStack[] recipe, ItemStack bloodOrb) {
public static AlchemyRecipe findRecipe(ItemStack[] recipe, ItemStack bloodOrb) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should be changing the public API this much. I'd add some methods with the old names/signatures that wrap your changed versions, like this for each of the methods that got changed:

    public static ItemStack getResult(ItemStack[] recipe, ItemStack bloodOrb) {
        findRecipe(recipe, bloodOrb).getResult();
    }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getResult and getAmountNeeded keep their names and signatures and delegate to findRecipe, which is the wrapper you sketched. I removed nothing from the api package.

I did remove one method, TEWritingTable.getRecipeForItems, which sits in common rather than api. Want it back as a wrapper over findRecipe?

if (bloodOrb == null) {
return null;
}
Expand All @@ -28,31 +28,23 @@ public static ItemStack getResult(ItemStack[] recipe, ItemStack bloodOrb) {

for (AlchemyRecipe ar : recipes) {
if (ar.doesRecipeMatch(recipe, bloodOrbLevel)) {
return (ar.getResult());
return ar;
}
}

return null;
}

public static int getAmountNeeded(ItemStack[] recipe, ItemStack bloodOrb) {
if (bloodOrb == null) {
return 0;
}

if (!(bloodOrb.getItem() instanceof IBloodOrb)) {
return 0;
}
public static ItemStack getResult(ItemStack[] recipe, ItemStack bloodOrb) {
AlchemyRecipe ar = findRecipe(recipe, bloodOrb);

int bloodOrbLevel = ((IBloodOrb) bloodOrb.getItem()).getOrbLevel();
return ar == null ? null : ar.getResult();
}

for (AlchemyRecipe ar : recipes) {
if (ar.doesRecipeMatch(recipe, bloodOrbLevel)) {
return (ar.getAmountNeeded());
}
}
public static int getAmountNeeded(ItemStack[] recipe, ItemStack bloodOrb) {
AlchemyRecipe ar = findRecipe(recipe, bloodOrb);

return 0;
return ar == null ? 0 : ar.getAmountNeeded();
}

public static ItemStack[] getRecipeForItemStack(ItemStack itemStack) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,14 +540,22 @@ public void updateEntity() {
}
}
} else {
if (!isRecipeValid()) {
ItemStack[] composedRecipe = new ItemStack[5];

System.arraycopy(inv, 1, composedRecipe, 0, 5);

AlchemyRecipe recipe = AlchemyRecipeRegistry.findRecipe(composedRecipe, inv[0]);

if (recipe == null) {
progress = 0;
return;
}

ItemStack result = recipe.getResult();

if (progress <= 0) {
progress = 0;
amountUsed = this.getAmountNeeded(getStackInSlot(0));
amountUsed = recipe.getAmountNeeded();

if (worldObj != null) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
Expand Down Expand Up @@ -580,60 +588,50 @@ public void updateEntity() {

if (progress >= progressNeeded) {
progress = 0;
this.setInventorySlotContents(6, getResultingItemStack());
this.setInventorySlotContents(6, result.copy());

ItemStack[] composedRecipe = new ItemStack[5];

System.arraycopy(inv, 1, composedRecipe, 0, 5);

this.decrementSlots(this.getRecipeForItems(composedRecipe, inv[0]));
this.decrementSlots(recipe.getRecipe());

if (worldObj != null) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
} else if (getStackInSlot(6).getItem() == getResultingItemStack().getItem()
&& getResultingItemStack().stackSize
<= (getStackInSlot(6).getMaxStackSize() - getStackInSlot(6).stackSize)) {
if (worldTime % 4 == 0) {
SpellHelper.sendIndexedParticleToAllAround(
worldObj,
xCoord,
yCoord,
zCoord,
20,
worldObj.provider.dimensionId,
1,
xCoord,
yCoord,
zCoord);
}

if (!SoulNetworkHandler.syphonFromNetworkWhileInContainer(
getStackInSlot(0),
amountUsed * acceleration)) {
return;
}

progress += acceleration;

if (progress >= progressNeeded) {
progress = 0;
ItemStack result = getResultingItemStack().copy();
result.stackSize += getStackInSlot(6).stackSize;
this.setInventorySlotContents(6, result);

ItemStack[] composedRecipe = new ItemStack[5];

System.arraycopy(inv, 1, composedRecipe, 0, 5);

this.decrementSlots(this.getRecipeForItems(composedRecipe, inv[0]));

if (worldObj != null) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
} else if (getStackInSlot(6).getItem() == result.getItem()
&& result.stackSize <= (getStackInSlot(6).getMaxStackSize() - getStackInSlot(6).stackSize)) {
if (worldTime % 4 == 0) {
SpellHelper.sendIndexedParticleToAllAround(
worldObj,
xCoord,
yCoord,
zCoord,
20,
worldObj.provider.dimensionId,
1,
xCoord,
yCoord,
zCoord);
}

if (!SoulNetworkHandler
.syphonFromNetworkWhileInContainer(getStackInSlot(0), amountUsed * acceleration)) {
return;
}

progress += acceleration;

if (progress >= progressNeeded) {
progress = 0;
ItemStack mergedResult = result.copy();
mergedResult.stackSize += getStackInSlot(6).stackSize;
this.setInventorySlotContents(6, mergedResult);

this.decrementSlots(recipe.getRecipe());

if (worldObj != null) {
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
}
}
}

Expand Down Expand Up @@ -667,26 +665,6 @@ public void decrementSlots(ItemStack[] recipe) {
}
}

public ItemStack[] getRecipeForItems(ItemStack[] recipe, ItemStack bloodOrb) {
if (bloodOrb == null) {
return null;
}

if (!(bloodOrb.getItem() instanceof IBloodOrb)) {
return null;
}

int bloodOrbLevel = ((IBloodOrb) bloodOrb.getItem()).getOrbLevel();

for (AlchemyRecipe ar : AlchemyRecipeRegistry.recipes) {
if (ar.doesRecipeMatch(recipe, bloodOrbLevel)) {
return ar.getRecipe();
}
}

return null;
}

public int getSpeedIncrease() {
return accelerationTime > 0 ? 5 : 1;
}
Expand Down