Added SoulForgeRecipe (basically a modified ShapelessOreRecipe, so is compatible with the oredictionary), and worked on the shift-clicking into the inventory.
This commit is contained in:
parent
a9feeade13
commit
7b8646659a
|
@ -0,0 +1,142 @@
|
||||||
|
package WayofTime.bloodmagic.api.recipe;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
public class SoulForgeRecipe
|
||||||
|
{
|
||||||
|
protected ItemStack output = null;
|
||||||
|
protected ArrayList<Object> input = new ArrayList<Object>();
|
||||||
|
@Getter
|
||||||
|
protected double minimumSouls;
|
||||||
|
@Getter
|
||||||
|
protected double soulsDrained;
|
||||||
|
|
||||||
|
public SoulForgeRecipe(Block result, double minSouls, double drain, Object... recipe)
|
||||||
|
{
|
||||||
|
this(new ItemStack(result), minSouls, drain, recipe);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SoulForgeRecipe(Item result, double minSouls, double drain, Object... recipe)
|
||||||
|
{
|
||||||
|
this(new ItemStack(result), minSouls, drain, recipe);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SoulForgeRecipe(ItemStack result, double minSouls, double drain, Object... recipe)
|
||||||
|
{
|
||||||
|
output = result.copy();
|
||||||
|
for (Object in : recipe)
|
||||||
|
{
|
||||||
|
if (in instanceof ItemStack)
|
||||||
|
{
|
||||||
|
input.add(((ItemStack) in).copy());
|
||||||
|
} else if (in instanceof Item)
|
||||||
|
{
|
||||||
|
input.add(new ItemStack((Item) in));
|
||||||
|
} else if (in instanceof Block)
|
||||||
|
{
|
||||||
|
input.add(new ItemStack((Block) in));
|
||||||
|
} else if (in instanceof String)
|
||||||
|
{
|
||||||
|
input.add(OreDictionary.getOres((String) in));
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
String ret = "Invalid soul forge recipe: ";
|
||||||
|
for (Object tmp : recipe)
|
||||||
|
{
|
||||||
|
ret += tmp + ", ";
|
||||||
|
}
|
||||||
|
ret += output;
|
||||||
|
throw new RuntimeException(ret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the size of the recipe area
|
||||||
|
*/
|
||||||
|
public int getRecipeSize()
|
||||||
|
{
|
||||||
|
return input.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ItemStack getRecipeOutput()
|
||||||
|
{
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to check if a recipe matches current crafting inventory. World and
|
||||||
|
* BlockPos are for future-proofing
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public boolean matches(List<ItemStack> checkedList, World world, BlockPos pos)
|
||||||
|
{
|
||||||
|
ArrayList<Object> required = new ArrayList<Object>(input);
|
||||||
|
|
||||||
|
for (int x = 0; x < checkedList.size(); x++)
|
||||||
|
{
|
||||||
|
ItemStack slot = checkedList.get(x);
|
||||||
|
|
||||||
|
if (slot != null)
|
||||||
|
{
|
||||||
|
boolean inRecipe = false;
|
||||||
|
Iterator<Object> req = required.iterator();
|
||||||
|
|
||||||
|
while (req.hasNext())
|
||||||
|
{
|
||||||
|
boolean match = false;
|
||||||
|
|
||||||
|
Object next = req.next();
|
||||||
|
|
||||||
|
if (next instanceof ItemStack)
|
||||||
|
{
|
||||||
|
match = OreDictionary.itemMatches((ItemStack) next, slot, false);
|
||||||
|
} else if (next instanceof List)
|
||||||
|
{
|
||||||
|
Iterator<ItemStack> itr = ((List<ItemStack>) next).iterator();
|
||||||
|
while (itr.hasNext() && !match)
|
||||||
|
{
|
||||||
|
match = OreDictionary.itemMatches(itr.next(), slot, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match)
|
||||||
|
{
|
||||||
|
inRecipe = true;
|
||||||
|
required.remove(next);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!inRecipe)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return required.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the input for this recipe, any mod accessing this value should
|
||||||
|
* never manipulate the values in this array as it will effect the recipe
|
||||||
|
* itself.
|
||||||
|
*
|
||||||
|
* @return The recipes input vales.
|
||||||
|
*/
|
||||||
|
public ArrayList<Object> getInput()
|
||||||
|
{
|
||||||
|
return this.input;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package WayofTime.bloodmagic.api.registry;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import WayofTime.bloodmagic.api.recipe.SoulForgeRecipe;
|
||||||
|
|
||||||
|
public class SoulForgeRecipeRegistry
|
||||||
|
{
|
||||||
|
public static List<SoulForgeRecipe> recipeList = new ArrayList<SoulForgeRecipe>();
|
||||||
|
|
||||||
|
public static void registerRecipe(SoulForgeRecipe recipe)
|
||||||
|
{
|
||||||
|
recipeList.add(recipe);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void registerRecipe(ItemStack outputStack, double minimulSouls, double drain, Object... objects)
|
||||||
|
{
|
||||||
|
registerRecipe(new SoulForgeRecipe(outputStack, minimulSouls, drain, objects));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SoulForgeRecipe getMatchingRecipe(List<ItemStack> itemList, World world, BlockPos pos)
|
||||||
|
{
|
||||||
|
for (SoulForgeRecipe recipe : recipeList)
|
||||||
|
{
|
||||||
|
if (recipe.matches(itemList, world, pos))
|
||||||
|
{
|
||||||
|
return recipe;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,7 +5,6 @@ import net.minecraft.client.renderer.GlStateManager;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraft.util.StatCollector;
|
|
||||||
import net.minecraftforge.fml.relauncher.Side;
|
import net.minecraftforge.fml.relauncher.Side;
|
||||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||||
import WayofTime.bloodmagic.api.Constants;
|
import WayofTime.bloodmagic.api.Constants;
|
||||||
|
|
|
@ -1,10 +1,23 @@
|
||||||
package WayofTime.bloodmagic.tile;
|
package WayofTime.bloodmagic.tile;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.ITickable;
|
import net.minecraft.util.ITickable;
|
||||||
|
import WayofTime.bloodmagic.api.recipe.SoulForgeRecipe;
|
||||||
|
import WayofTime.bloodmagic.api.registry.SoulForgeRecipeRegistry;
|
||||||
|
import WayofTime.bloodmagic.api.soul.ISoul;
|
||||||
|
import WayofTime.bloodmagic.api.soul.ISoulGem;
|
||||||
|
|
||||||
public class TileSoulForge extends TileInventory implements ITickable
|
public class TileSoulForge extends TileInventory implements ITickable
|
||||||
{
|
{
|
||||||
|
public static final int soulSlot = 4;
|
||||||
|
public static final int outputSlot = 5;
|
||||||
|
|
||||||
|
//Input slots are from 0 to 3.
|
||||||
|
|
||||||
public TileSoulForge()
|
public TileSoulForge()
|
||||||
{
|
{
|
||||||
super(6, "soulForge");
|
super(6, "soulForge");
|
||||||
|
@ -25,6 +38,95 @@ public class TileSoulForge extends TileInventory implements ITickable
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
|
if (!hasSoulGemOrSoul())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
double soulsInGem = getSouls();
|
||||||
|
|
||||||
|
List<ItemStack> inputList = new ArrayList<ItemStack>();
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
if (getStackInSlot(i) != null)
|
||||||
|
{
|
||||||
|
inputList.add(getStackInSlot(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SoulForgeRecipe recipe = SoulForgeRecipeRegistry.getMatchingRecipe(inputList, getWorld(), getPos());
|
||||||
|
if (recipe != null && recipe.getMinimumSouls() <= soulsInGem)
|
||||||
|
{
|
||||||
|
ItemStack outputStack = recipe.getRecipeOutput();
|
||||||
|
if (getStackInSlot(outputSlot) == null)
|
||||||
|
{
|
||||||
|
setInventorySlotContents(outputSlot, outputStack);
|
||||||
|
consumeInventory();
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasSoulGemOrSoul()
|
||||||
|
{
|
||||||
|
ItemStack soulStack = getStackInSlot(soulSlot);
|
||||||
|
|
||||||
|
if (soulStack != null)
|
||||||
|
{
|
||||||
|
if (soulStack.getItem() instanceof ISoul || soulStack.getItem() instanceof ISoulGem)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getSouls()
|
||||||
|
{
|
||||||
|
ItemStack soulStack = getStackInSlot(soulSlot);
|
||||||
|
|
||||||
|
if (soulStack != null)
|
||||||
|
{
|
||||||
|
if (soulStack.getItem() instanceof ISoul)
|
||||||
|
{
|
||||||
|
ISoul soul = (ISoul) soulStack.getItem();
|
||||||
|
return soul.getSouls(soulStack);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (soulStack.getItem() instanceof ISoulGem)
|
||||||
|
{
|
||||||
|
ISoulGem soul = (ISoulGem) soulStack.getItem();
|
||||||
|
return soul.getSouls(soulStack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void consumeInventory()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
ItemStack inputStack = getStackInSlot(i);
|
||||||
|
if (inputStack != null)
|
||||||
|
{
|
||||||
|
if (inputStack.getItem().hasContainerItem(inputStack))
|
||||||
|
{
|
||||||
|
setInventorySlotContents(i, inputStack.getItem().getContainerItem(inputStack));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
inputStack.stackSize--;
|
||||||
|
if (inputStack.stackSize <= 0)
|
||||||
|
{
|
||||||
|
setInventorySlotContents(i, null);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import net.minecraft.inventory.Slot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import WayofTime.bloodmagic.api.soul.ISoul;
|
import WayofTime.bloodmagic.api.soul.ISoul;
|
||||||
import WayofTime.bloodmagic.api.soul.ISoulGem;
|
import WayofTime.bloodmagic.api.soul.ISoulGem;
|
||||||
import WayofTime.bloodmagic.item.ItemTelepositionFocus;
|
import WayofTime.bloodmagic.tile.TileSoulForge;
|
||||||
|
|
||||||
public class ContainerSoulForge extends Container
|
public class ContainerSoulForge extends Container
|
||||||
{
|
{
|
||||||
|
@ -17,7 +17,12 @@ public class ContainerSoulForge extends Container
|
||||||
public ContainerSoulForge(InventoryPlayer inventoryPlayer, IInventory tileForge)
|
public ContainerSoulForge(InventoryPlayer inventoryPlayer, IInventory tileForge)
|
||||||
{
|
{
|
||||||
this.tileForge = tileForge;
|
this.tileForge = tileForge;
|
||||||
this.addSlotToContainer(new SlotSoul(tileForge, 0, 152, 51));
|
this.addSlotToContainer(new Slot(tileForge, 0, 8, 15));
|
||||||
|
this.addSlotToContainer(new Slot(tileForge, 1, 80, 15));
|
||||||
|
this.addSlotToContainer(new Slot(tileForge, 2, 80, 87));
|
||||||
|
this.addSlotToContainer(new Slot(tileForge, 3, 8, 87));
|
||||||
|
this.addSlotToContainer(new SlotSoul(tileForge, TileSoulForge.soulSlot, 152, 51));
|
||||||
|
this.addSlotToContainer(new SlotOutput(tileForge, TileSoulForge.outputSlot, 44, 51));
|
||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
|
@ -34,48 +39,58 @@ public class ContainerSoulForge extends Container
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack transferStackInSlot(EntityPlayer player, int slot)
|
public ItemStack transferStackInSlot(EntityPlayer playerIn, int index)
|
||||||
{
|
{
|
||||||
ItemStack stack = null;
|
ItemStack itemstack = null;
|
||||||
Slot slotObject = inventorySlots.get(slot);
|
Slot slot = (Slot) this.inventorySlots.get(index);
|
||||||
int slots = inventorySlots.size();
|
|
||||||
|
|
||||||
if (slotObject != null && slotObject.getHasStack())
|
if (slot != null && slot.getHasStack())
|
||||||
{
|
{
|
||||||
ItemStack stackInSlot = slotObject.getStack();
|
ItemStack itemstack1 = slot.getStack();
|
||||||
stack = stackInSlot.copy();
|
itemstack = itemstack1.copy();
|
||||||
|
|
||||||
if (stack.getItem() instanceof ItemTelepositionFocus)
|
if (index == 5)
|
||||||
{
|
{
|
||||||
if (slot <= slots)
|
if (!this.mergeItemStack(itemstack1, 6, 6 + 36, true))
|
||||||
{
|
|
||||||
if (!this.mergeItemStack(stackInSlot, 0, slots, false))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else if (!this.mergeItemStack(stackInSlot, slots, 36 + slots, false))
|
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (stackInSlot.stackSize == 0)
|
slot.onSlotChange(itemstack1, itemstack);
|
||||||
|
} else if (index > 5)
|
||||||
{
|
{
|
||||||
slotObject.putStack(null);
|
if (itemstack1.getItem() instanceof ISoul || itemstack1.getItem() instanceof ISoulGem)
|
||||||
} else
|
{
|
||||||
{
|
if (!this.mergeItemStack(itemstack1, 4, 5, false))
|
||||||
slotObject.onSlotChanged();
|
{
|
||||||
}
|
return null;
|
||||||
|
}
|
||||||
if (stackInSlot.stackSize == stack.stackSize)
|
} else if (!this.mergeItemStack(itemstack1, 0, 4, false))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else if (!this.mergeItemStack(itemstack1, 6, 42, false))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
slotObject.onPickupFromSlot(player, stackInSlot);
|
if (itemstack1.stackSize == 0)
|
||||||
|
{
|
||||||
|
slot.putStack((ItemStack) null);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
slot.onSlotChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (itemstack1.stackSize == itemstack.stackSize)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
slot.onPickupFromSlot(playerIn, itemstack1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return stack;
|
return itemstack;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -97,4 +112,18 @@ public class ContainerSoulForge extends Container
|
||||||
return itemStack.getItem() instanceof ISoulGem || itemStack.getItem() instanceof ISoul;
|
return itemStack.getItem() instanceof ISoulGem || itemStack.getItem() instanceof ISoul;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class SlotOutput extends Slot
|
||||||
|
{
|
||||||
|
public SlotOutput(IInventory inventory, int slotIndex, int x, int y)
|
||||||
|
{
|
||||||
|
super(inventory, slotIndex, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isItemValid(ItemStack stack)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 474 B After Width: | Height: | Size: 841 B |
Binary file not shown.
Before Width: | Height: | Size: 841 B |
Loading…
Reference in a new issue