added centrifuge recipe + moved itemUtils to its own class
This commit is contained in:
parent
91495286db
commit
fcfc6ed1df
7 changed files with 129 additions and 28 deletions
54
src/main/java/techreborn/api/CentrifugeRecipie.java
Normal file
54
src/main/java/techreborn/api/CentrifugeRecipie.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
package techreborn.api;
|
||||||
|
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
public class CentrifugeRecipie {
|
||||||
|
ItemStack inputItem;
|
||||||
|
ItemStack output1, output2, output3, output4;
|
||||||
|
int tickTime;
|
||||||
|
|
||||||
|
public CentrifugeRecipie(ItemStack inputItem, ItemStack output1, ItemStack output2, ItemStack output3, ItemStack output4, int tickTime) {
|
||||||
|
this.inputItem = inputItem;
|
||||||
|
this.output1 = output1;
|
||||||
|
this.output2 = output2;
|
||||||
|
this.output3 = output3;
|
||||||
|
this.output4 = output4;
|
||||||
|
this.tickTime = tickTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CentrifugeRecipie(Item inputItem, int inputAmount, Item output1, Item output2, Item output3, Item output4, int tickTime) {
|
||||||
|
this.inputItem = new ItemStack(inputItem, inputAmount);
|
||||||
|
this.output1 = new ItemStack(output1);
|
||||||
|
this.output2 = new ItemStack(output2);
|
||||||
|
this.output3 = new ItemStack(output3);
|
||||||
|
this.output4 = new ItemStack(output4);
|
||||||
|
this.tickTime = tickTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getInputItem() {
|
||||||
|
return inputItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getOutput1() {
|
||||||
|
return output1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getOutput2() {
|
||||||
|
return output2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getOutput3() {
|
||||||
|
return output3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getOutput4() {
|
||||||
|
return output4;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTickTime() {
|
||||||
|
return tickTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,35 @@
|
||||||
package techreborn.api;
|
package techreborn.api;
|
||||||
|
|
||||||
|
import techreborn.util.ItemUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public final class TechRebornAPI {
|
public final class TechRebornAPI {
|
||||||
|
|
||||||
|
public static ArrayList<CentrifugeRecipie> centrifugeRecipies = new ArrayList<CentrifugeRecipie>();
|
||||||
|
|
||||||
|
|
||||||
|
public static void registerCentrifugeRecipe(CentrifugeRecipie recipie){
|
||||||
|
boolean shouldAdd = true;
|
||||||
|
for(CentrifugeRecipie centrifugeRecipie : centrifugeRecipies){
|
||||||
|
if(ItemUtils.isItemEqual(centrifugeRecipie.getInputItem(), recipie.getInputItem(), false, true)){
|
||||||
|
try {
|
||||||
|
throw new RegisteredItemRecipe("Item " + recipie.getInputItem().getUnlocalizedName() + " is already being used in a recipe for the Centrifuge");
|
||||||
|
} catch (RegisteredItemRecipe registeredItemRecipe) {
|
||||||
|
registeredItemRecipe.printStackTrace();
|
||||||
|
shouldAdd = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(shouldAdd)
|
||||||
|
centrifugeRecipies.add(recipie);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RegisteredItemRecipe extends Exception
|
||||||
|
{
|
||||||
|
public RegisteredItemRecipe(String message)
|
||||||
|
{
|
||||||
|
super(message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import net.minecraft.inventory.Slot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import techreborn.client.SlotFake;
|
import techreborn.client.SlotFake;
|
||||||
import techreborn.util.FluidUtils;
|
import techreborn.util.FluidUtils;
|
||||||
|
import techreborn.util.ItemUtils;
|
||||||
|
|
||||||
|
|
||||||
public abstract class TechRebornContainer extends Container {
|
public abstract class TechRebornContainer extends Container {
|
||||||
|
@ -45,7 +46,7 @@ public abstract class TechRebornContainer extends Container {
|
||||||
for (int slotIndex = start; stackToShift.stackSize > 0 && slotIndex < end; slotIndex++) {
|
for (int slotIndex = start; stackToShift.stackSize > 0 && slotIndex < end; slotIndex++) {
|
||||||
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
Slot slot = (Slot) inventorySlots.get(slotIndex);
|
||||||
ItemStack stackInSlot = slot.getStack();
|
ItemStack stackInSlot = slot.getStack();
|
||||||
if (stackInSlot != null && FluidUtils.isItemEqual(stackInSlot, stackToShift, true, true)) {
|
if (stackInSlot != null && ItemUtils.isItemEqual(stackInSlot, stackToShift, true, true)) {
|
||||||
int resultingStackSize = stackInSlot.stackSize + stackToShift.stackSize;
|
int resultingStackSize = stackInSlot.stackSize + stackToShift.stackSize;
|
||||||
int max = Math.min(stackToShift.getMaxStackSize(), slot.getSlotStackLimit());
|
int max = Math.min(stackToShift.getMaxStackSize(), slot.getSlotStackLimit());
|
||||||
if (resultingStackSize <= max) {
|
if (resultingStackSize <= max) {
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
package techreborn.init;
|
package techreborn.init;
|
||||||
|
|
||||||
|
import net.minecraft.init.Items;
|
||||||
|
import techreborn.api.CentrifugeRecipie;
|
||||||
|
import techreborn.api.TechRebornAPI;
|
||||||
import techreborn.util.LogHelper;
|
import techreborn.util.LogHelper;
|
||||||
|
|
||||||
public class ModRecipes {
|
public class ModRecipes {
|
||||||
|
@ -35,6 +38,7 @@ public class ModRecipes {
|
||||||
|
|
||||||
public static void addMachineRecipes()
|
public static void addMachineRecipes()
|
||||||
{
|
{
|
||||||
|
TechRebornAPI.registerCentrifugeRecipe(new CentrifugeRecipie(Items.apple, 4, Items.beef, Items.baked_potato, null, null, 120));
|
||||||
LogHelper.info("Machine Recipes Added");
|
LogHelper.info("Machine Recipes Added");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import techreborn.init.ModBlocks;
|
import techreborn.init.ModBlocks;
|
||||||
import techreborn.util.FluidUtils;
|
import techreborn.util.FluidUtils;
|
||||||
import techreborn.util.Inventory;
|
import techreborn.util.Inventory;
|
||||||
|
import techreborn.util.ItemUtils;
|
||||||
|
|
||||||
|
|
||||||
public class TileQuantumChest extends TileEntity implements IInventory ,IWrenchable{
|
public class TileQuantumChest extends TileEntity implements IInventory ,IWrenchable{
|
||||||
|
@ -38,7 +39,7 @@ public class TileQuantumChest extends TileEntity implements IInventory ,IWrencha
|
||||||
if(storedItem == null){
|
if(storedItem == null){
|
||||||
storedItem = getStackInSlot(0);
|
storedItem = getStackInSlot(0);
|
||||||
setInventorySlotContents(0, null);
|
setInventorySlotContents(0, null);
|
||||||
} else if (FluidUtils.isItemEqual(storedItem, getStackInSlot(0), true, true)){
|
} else if (ItemUtils.isItemEqual(storedItem, getStackInSlot(0), true, true)){
|
||||||
if(storedItem.stackSize <=Integer.MAX_VALUE - getStackInSlot(0).stackSize){
|
if(storedItem.stackSize <=Integer.MAX_VALUE - getStackInSlot(0).stackSize){
|
||||||
storedItem.stackSize += getStackInSlot(0).stackSize;
|
storedItem.stackSize += getStackInSlot(0).stackSize;
|
||||||
decrStackSize(0, getStackInSlot(0).stackSize);
|
decrStackSize(0, getStackInSlot(0).stackSize);
|
||||||
|
@ -51,7 +52,7 @@ public class TileQuantumChest extends TileEntity implements IInventory ,IWrencha
|
||||||
itemStack.stackSize = itemStack.getMaxStackSize();
|
itemStack.stackSize = itemStack.getMaxStackSize();
|
||||||
setInventorySlotContents(1, itemStack);
|
setInventorySlotContents(1, itemStack);
|
||||||
storedItem.stackSize -= itemStack.getMaxStackSize();
|
storedItem.stackSize -= itemStack.getMaxStackSize();
|
||||||
} else if(FluidUtils.isItemEqual(getStackInSlot(1), storedItem, true, true)){
|
} else if(ItemUtils.isItemEqual(getStackInSlot(1), storedItem, true, true)){
|
||||||
int wanted = getStackInSlot(1).getMaxStackSize() - getStackInSlot(1).stackSize;
|
int wanted = getStackInSlot(1).getMaxStackSize() - getStackInSlot(1).stackSize;
|
||||||
if(storedItem.stackSize >= wanted){
|
if(storedItem.stackSize >= wanted){
|
||||||
decrStackSize(1, -wanted);
|
decrStackSize(1, -wanted);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package techreborn.util;
|
package techreborn.util;
|
||||||
|
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
import net.minecraftforge.fluids.Fluid;
|
import net.minecraftforge.fluids.Fluid;
|
||||||
|
@ -18,7 +19,7 @@ public class FluidUtils {
|
||||||
if (input != null) {
|
if (input != null) {
|
||||||
FluidStack fluidInContainer = getFluidStackInContainer(input);
|
FluidStack fluidInContainer = getFluidStackInContainer(input);
|
||||||
ItemStack emptyItem = input.getItem().getContainerItem(input);
|
ItemStack emptyItem = input.getItem().getContainerItem(input);
|
||||||
if (fluidInContainer != null && (emptyItem == null || output == null || (output.stackSize < output.getMaxStackSize() && isItemEqual(output, emptyItem, true, true)))) {
|
if (fluidInContainer != null && (emptyItem == null || output == null || (output.stackSize < output.getMaxStackSize() && ItemUtils.isItemEqual(output, emptyItem, true, true)))) {
|
||||||
int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false);
|
int used = fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, false);
|
||||||
if (used >= fluidInContainer.amount) {
|
if (used >= fluidInContainer.amount) {
|
||||||
fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, true);
|
fluidHandler.fill(ForgeDirection.UNKNOWN, fluidInContainer, true);
|
||||||
|
@ -39,7 +40,7 @@ public class FluidUtils {
|
||||||
ItemStack input = inv.getStackInSlot(inputSlot);
|
ItemStack input = inv.getStackInSlot(inputSlot);
|
||||||
ItemStack output = inv.getStackInSlot(outputSlot);
|
ItemStack output = inv.getStackInSlot(outputSlot);
|
||||||
ItemStack filled = getFilledContainer(fluidToFill, input);
|
ItemStack filled = getFilledContainer(fluidToFill, input);
|
||||||
if (filled != null && (output == null || (output.stackSize < output.getMaxStackSize() && isItemEqual(filled, output, true, true)))) {
|
if (filled != null && (output == null || (output.stackSize < output.getMaxStackSize() && ItemUtils.isItemEqual(filled, output, true, true)))) {
|
||||||
FluidStack fluidInContainer = getFluidStackInContainer(filled);
|
FluidStack fluidInContainer = getFluidStackInContainer(filled);
|
||||||
FluidStack drain = fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, false);
|
FluidStack drain = fluidHandler.drain(ForgeDirection.UNKNOWN, fluidInContainer, false);
|
||||||
if (drain != null && drain.amount == fluidInContainer.amount) {
|
if (drain != null && drain.amount == fluidInContainer.amount) {
|
||||||
|
@ -64,27 +65,4 @@ public class FluidUtils {
|
||||||
return FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid, Integer.MAX_VALUE), empty);
|
return FluidContainerRegistry.fillFluidContainer(new FluidStack(fluid, Integer.MAX_VALUE), empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isItemEqual(final ItemStack a, final ItemStack b, final boolean matchDamage, final boolean matchNBT) {
|
|
||||||
if (a == null || b == null)
|
|
||||||
return false;
|
|
||||||
if (a.getItem() != b.getItem())
|
|
||||||
return false;
|
|
||||||
if (matchNBT && !ItemStack.areItemStackTagsEqual(a, b))
|
|
||||||
return false;
|
|
||||||
if (matchDamage && a.getHasSubtypes()) {
|
|
||||||
if (isWildcard(a) || isWildcard(b))
|
|
||||||
return true;
|
|
||||||
if (a.getItemDamage() != b.getItemDamage())
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isWildcard(ItemStack stack) {
|
|
||||||
return isWildcard(stack.getItemDamage());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isWildcard(int damage) {
|
|
||||||
return damage == -1 || damage == OreDictionary.WILDCARD_VALUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
33
src/main/java/techreborn/util/ItemUtils.java
Normal file
33
src/main/java/techreborn/util/ItemUtils.java
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package techreborn.util;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mark on 12/04/15.
|
||||||
|
*/
|
||||||
|
public class ItemUtils {
|
||||||
|
public static boolean isItemEqual(final ItemStack a, final ItemStack b, final boolean matchDamage, final boolean matchNBT) {
|
||||||
|
if (a == null || b == null)
|
||||||
|
return false;
|
||||||
|
if (a.getItem() != b.getItem())
|
||||||
|
return false;
|
||||||
|
if (matchNBT && !ItemStack.areItemStackTagsEqual(a, b))
|
||||||
|
return false;
|
||||||
|
if (matchDamage && a.getHasSubtypes()) {
|
||||||
|
if (isWildcard(a) || isWildcard(b))
|
||||||
|
return true;
|
||||||
|
if (a.getItemDamage() != b.getItemDamage())
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isWildcard(ItemStack stack) {
|
||||||
|
return isWildcard(stack.getItemDamage());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isWildcard(int damage) {
|
||||||
|
return damage == -1 || damage == OreDictionary.WILDCARD_VALUE;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue