Added an auto-crafting ritual

Fixed Blood Light sigil glitches
Fixed some issues with the Reagent HP bar not draining correctly - what was I thinking?!?
This commit is contained in:
WayofTime 2015-04-16 09:02:19 -04:00
parent d1fc806113
commit 3d89bd6b90
13 changed files with 503 additions and 55 deletions

View file

@ -1,5 +1,5 @@
#
#Sun Apr 12 20:13:33 EDT 2015
#Wed Apr 15 20:03:49 EDT 2015
mod_name=BloodMagic
forge_version=10.13.2.1232
ccc_version=1.0.4.29
@ -9,4 +9,4 @@ package_group=com.wayoftime.bloodmagic
mod_version=1.3.2Beta
minetweaker_version=Dev-1.7.10-3.0.9B
mc_version=1.7.10
build_number=3
build_number=9

View file

@ -139,6 +139,7 @@ import WayofTime.alchemicalWizardry.common.rituals.RitualEffectAnimalGrowth;
import WayofTime.alchemicalWizardry.common.rituals.RitualEffectAutoAlchemy;
import WayofTime.alchemicalWizardry.common.rituals.RitualEffectBiomeChanger;
import WayofTime.alchemicalWizardry.common.rituals.RitualEffectContainment;
import WayofTime.alchemicalWizardry.common.rituals.RitualEffectCrafting;
import WayofTime.alchemicalWizardry.common.rituals.RitualEffectCrushing;
import WayofTime.alchemicalWizardry.common.rituals.RitualEffectDemonPortal;
import WayofTime.alchemicalWizardry.common.rituals.RitualEffectEllipsoid;
@ -1387,8 +1388,10 @@ public class AlchemicalWizardry
Rituals.registerRitual("AW030FullStomach", 1, 100000, new RitualEffectFullStomach(), "Requiem of the Satiated Stomach", new AlchemyCircleRenderer(new ResourceLocation("alchemicalwizardry:textures/models/SimpleTransCircle.png"), 0, 0, 0, 255, 0, 0.501, 0.501, 0, 1.5, false));
Rituals.registerRitual("AW031Convocation",isDemonRitualCreativeOnly ? 10 : 2, 15000000, new RitualEffectDemonPortal(), "Convocation of the Damned", new AlchemyCircleRenderer(new ResourceLocation("alchemicalwizardry:textures/models/TransCircleDemon.png"), 220, 22, 22, 255, 0, 0.501, 0.501, 0, 5, false));
Rituals.registerRitual("AW032Symmetry", 2, 15000000, new RitualEffectOmegaTest(), "Symmetry of the Omega");
Rituals.registerRitual("AW033Stalling", 2, 15000000, new RitualEffectOmegaStalling(), "Omega Stalling");
// Rituals.registerRitual("AW034", 2, 100, new RitualEffectAlphaPact(), "Alpha Pact");
Rituals.registerRitual("AW033Stalling", 2, 15000000, new RitualEffectOmegaStalling(), "Duet of the Fused Souls");
Rituals.registerRitual("AW034", 2, 100, new RitualEffectCrafting(), "Ritual of Teh Crafts");
Rituals.registerRitual("AW035", 1, 10000, new RitualEffectItemRouting(), "Orchestra of the Phantom Hands");
//Rituals.registerRitual(1,100,new RitualEffectApiaryOverclock(),"Apiary Overclock"));
}

View file

@ -164,6 +164,23 @@ public class APISpellHelper
data.setFloat("BM:MaxAddedHP", maxHP);
}
public static int getPlayerReagentRegenCooldownTag(EntityPlayer player)
{
NBTTagCompound data = APISpellHelper.getPersistentDataTag(player);
if(data.hasKey("BM:ReagentRegenCooldown"))
{
return data.getInteger("BM:ReagentRegenCooldown");
}
return 0;
}
public static void setPlayerReagentRegenCooldownTag(EntityPlayer player, int amount)
{
NBTTagCompound data = APISpellHelper.getPersistentDataTag(player);
data.setInteger("BM:ReagentRegenCooldown", amount);
}
public static MovingObjectPosition raytraceFromEntity(World world, Entity player, boolean par3, double range)
{
float f = 1.0F;

View file

@ -105,21 +105,24 @@ public class AlchemicalWizardryEventHooks
@SubscribeEvent(priority=EventPriority.HIGHEST)
public void onLivingHurtEvent(LivingHurtEvent event)
{
System.out.println("IsRemote: " + event.entity.worldObj.isRemote);
if(!event.isCanceled() && event.entityLiving instanceof EntityPlayer && !event.entityLiving.worldObj.isRemote)
{
if(event.entityLiving.getHealth() > event.entityLiving.getMaxHealth())
{
event.entityLiving.setHealth(event.entityLiving.getMaxHealth());
}
EntityPlayer player = (EntityPlayer)event.entityLiving;
if(APISpellHelper.getCurrentAdditionalMaxHP(player) > 0)
{
APISpellHelper.setPlayerReagentRegenCooldownTag(player, 20 * 20);
}
float prevHp = APISpellHelper.getCurrentAdditionalHP((EntityPlayer)event.entityLiving);
if(prevHp > 0)
{
double originalDamage = event.ammount;
double initialReagentHp = prevHp;
float recalculatedAmount = ArmorProperties.ApplyArmor(player, player.inventory.armorInventory, event.source, event.ammount);
if (recalculatedAmount <= 0) return;
recalculatedAmount = SpellHelper.applyPotionDamageCalculations(player, event.source, recalculatedAmount);
recalculatedAmount = SpellHelper.applyPotionDamageCalculations(player, event.source, recalculatedAmount); //Recalculated damage
float ratio = recalculatedAmount / event.ammount;
@ -129,43 +132,43 @@ public class AlchemicalWizardryEventHooks
if(prevHp > recalculatedAmount)
{
float hp = (prevHp - recalculatedAmount);
if(hp > 0)
{
event.ammount = 0;
}else
{
event.ammount -= hp / ratio;
Reagent reagent = APISpellHelper.getPlayerReagentType(player);
OmegaParadigm paradigm = OmegaRegistry.getParadigmForReagent(reagent);
if(paradigm != null)
{
ItemStack chestStack = player.inventory.armorInventory[2];
float hp = (prevHp - recalculatedAmount); //New HP - this is obviously > 0...
if(chestStack != null && chestStack.getItem() instanceof OmegaArmour)
// event.setCanceled(true);
event.ammount = 0;
Reagent reagent = APISpellHelper.getPlayerReagentType(player);
OmegaParadigm paradigm = OmegaRegistry.getParadigmForReagent(reagent);
if(paradigm != null)
{
ItemStack chestStack = player.inventory.armorInventory[2];
if(chestStack != null && chestStack.getItem() instanceof OmegaArmour)
{
if(((OmegaArmour)chestStack.getItem()).paradigm == paradigm)
{
if(((OmegaArmour)chestStack.getItem()).paradigm == paradigm)
{
paradigm.onHPBarDepleted(player, chestStack);
}
paradigm.onHPBarDepleted(player, chestStack);
}
}
}
APISpellHelper.setCurrentAdditionalHP((EntityPlayer)event.entityLiving, Math.max(0, hp));
APISpellHelper.setCurrentAdditionalHP(player, Math.max(0, hp));
NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getAddedHPPacket(Math.max(0, hp), APISpellHelper.getCurrentAdditionalMaxHP(player)), (EntityPlayerMP)player);
APISpellHelper.setCurrentAdditionalHP(player, hp);
NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getAddedHPPacket(hp, APISpellHelper.getCurrentAdditionalMaxHP(player)), (EntityPlayerMP)player);
if(event.ammount <= 0.3)
// if(event.ammount <= 0.3)
// {
// event.ammount++;
// }
}else
{
APISpellHelper.setCurrentAdditionalHP(player, 0);
NewPacketHandler.INSTANCE.sendTo(NewPacketHandler.getAddedHPPacket(0, APISpellHelper.getCurrentAdditionalMaxHP(player)), (EntityPlayerMP)player);
event.ammount -= prevHp / ratio;
if(event.ammount < 0)
{
// if(rand.nextInt(10) == 0)
{
event.ammount++;
}
event.ammount = 0;
}
}
}
}
}
}
@ -183,12 +186,40 @@ public class AlchemicalWizardryEventHooks
if(reagentAmount > 0 && OmegaRegistry.hasParadigm(reagent))
{
int cooldown = APISpellHelper.getPlayerReagentRegenCooldownTag(player);
if(cooldown > 0)
{
float extra = 0;
if(player.isPotionActive(AlchemicalWizardry.customPotionSoulHarden))
{
extra += 0.25f * (1 + player.getActivePotionEffect(AlchemicalWizardry.customPotionSoulHarden).getAmplifier());
}
if(player.isPotionActive(AlchemicalWizardry.customPotionSoulFray))
{
extra -= 0.25f * (1 + player.getActivePotionEffect(AlchemicalWizardry.customPotionSoulFray).getAmplifier());
}
int deduction = - 1 - (extra >= 0 ? (rand.nextFloat() < extra ? 1 : 0) : (rand.nextFloat() < -extra/2 ? -1 : 0));
APISpellHelper.setPlayerReagentRegenCooldownTag(player, Math.max(cooldown + deduction, 0));
return;
}
OmegaParadigm parad = OmegaRegistry.getParadigmForReagent(reagent);
ReagentRegenConfiguration config = parad.getRegenConfig(player);
if(parad.isPlayerWearingFullSet(player))
{
if(event.entityLiving.worldObj.getWorldTime() % config.tickRate == 0)
int tickRate = config.tickRate;
if(player.isPotionActive(Potion.regeneration))
{
int i = player.getActivePotionEffect(Potion.regeneration).getAmplifier();
double factor = Math.pow(1.5, i+1);
tickRate = Math.max((int)(tickRate / factor), 1);
}
if(event.entityLiving.worldObj.getWorldTime() % tickRate == 0)
{
boolean hasHealthChanged = false;
int maxHealth = parad.getMaxAdditionalHealth();

View file

@ -99,4 +99,10 @@ public class BlockEnchantmentGlyph extends Block implements IEnchantmentGlyph
par3List.add(new ItemStack(par1, 1, i));
}
}
@Override
public int damageDropped(int metadata)
{
return metadata;
}
}

View file

@ -161,6 +161,8 @@ public abstract class OmegaArmour extends BoundArmour
SoulNetworkHandler.checkAndSetItemOwner(omegaStack, SoulNetworkHandler.getOwnerName(boundStack));
this.setItemEnchantability(omegaStack, Math.min(enchantability, 70));
EnchantmentHelper.setEnchantments(new HashMap(), omegaStack);
List enchantList = new ArrayList();
int adjustedEnchantLevel = Math.min(enchantmentLevel, 30);

View file

@ -124,11 +124,11 @@ public class OmegaArmourEarth extends OmegaArmour
public float getHealthBoostModifierForLevel(int yLevel)
{
return (float) (0.05 * Math.max(-0.5, -((float)yLevel)/64f * 1.5f + 5.5f));
return 0.05f * (yLevel <= 50 ? 1.5f : yLevel >= 100 ? -0.5f : 0.5f);
}
public float getDamageModifierForLevel(int yLevel)
{
return 0.02f * ((((float)yLevel)/64f) * 1.5f - 1);
return 0.03f * (yLevel <= 50 ? 1.5f : yLevel >= 100 ? -0.5f : 0.5f);
}
}

View file

@ -49,7 +49,6 @@ public class ItemBloodLightSigil extends EnergyItems implements IHolding
@Override
public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
System.out.println("Being called");
if(!EnergyItems.checkAndSetItemOwner(par1ItemStack, par2EntityPlayer) || !EnergyItems.syphonBatteries(par1ItemStack, par2EntityPlayer, getEnergyUsed()))
{
return true;
@ -96,7 +95,7 @@ public class ItemBloodLightSigil extends EnergyItems implements IHolding
@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
if (EnergyItems.checkAndSetItemOwner(par1ItemStack, par3EntityPlayer) || par3EntityPlayer.isSneaking())
if (!EnergyItems.checkAndSetItemOwner(par1ItemStack, par3EntityPlayer) || par3EntityPlayer.isSneaking())
{
return par1ItemStack;
}

View file

@ -35,7 +35,7 @@ public class OmegaParadigm
this.leggings.setReagent(reagent);
this.boots.setReagent(reagent);
this.config = new ReagentRegenConfiguration(20, 10, 1);
this.config = new ReagentRegenConfiguration(100, 1, 10);
}
public boolean convertPlayerArmour(EntityPlayer player, int x, int y, int z, int stability, int affinity, int enchantability, int enchantmentLevel)

View file

@ -37,13 +37,6 @@ public class OmegaParadigmEarth extends OmegaParadigm
{
player.addPotionEffect(new PotionEffect(Potion.regeneration.id, 200, 0, true));
}
// if(player.isInWater())
// {
// player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 200, 2, true));
// player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 200, 2, true));
// player.addPotionEffect(new PotionEffect(Potion.weakness.id, 200, 1, true));
// }
}
if(player.posY > 100)

View file

@ -0,0 +1,309 @@
package WayofTime.alchemicalWizardry.common.rituals;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary;
import WayofTime.alchemicalWizardry.api.Int3;
import WayofTime.alchemicalWizardry.api.rituals.IMasterRitualStone;
import WayofTime.alchemicalWizardry.api.rituals.RitualComponent;
import WayofTime.alchemicalWizardry.api.rituals.RitualEffect;
import WayofTime.alchemicalWizardry.api.soulNetwork.SoulNetworkHandler;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
public class RitualEffectCrafting extends RitualEffect
{
public static final boolean isTesting = false;
public static final boolean limitToSingleStack = false;
public static final int potentiaDrain = 2;
@Override
public void performEffect(IMasterRitualStone ritualStone)
{
String owner = ritualStone.getOwner();
int currentEssence = SoulNetworkHandler.getCurrentEssence(owner);
World world = ritualStone.getWorld();
int x = ritualStone.getXCoord();
int y = ritualStone.getYCoord();
int z = ritualStone.getZCoord();
if(world.getWorldTime() % 1 != 0)
{
return;
}
if (currentEssence < this.getCostPerRefresh())
{
SoulNetworkHandler.causeNauseaToPlayer(owner);
} else
{
int slotDesignation = 0;
int direction = ritualStone.getDirection();
boolean canContinue = false;
ItemStack[] recipe = new ItemStack[9];
InventoryCrafting inventory = new InventoryCrafting(new Container()
{
public boolean canInteractWith(EntityPlayer player)
{
return false;
}
}, 3, 3);
for(int i=-1; i<=1; i++)
{
for(int j=-1; j<=1; j++)
{
TileEntity inv = world.getTileEntity(x + j, y + 2, z + i);
if(inv instanceof IInventory)
{
int gridSpace = (i+1)*3 + (j+1);
if(((IInventory) inv).getSizeInventory() < slotDesignation || !((IInventory) inv).isItemValidForSlot(slotDesignation, ((IInventory) inv).getStackInSlot(slotDesignation)))
{
continue;
}else
{
ItemStack invStack = ((IInventory) inv).getStackInSlot(slotDesignation);
if(invStack != null)
{
inventory.setInventorySlotContents(gridSpace, invStack);
recipe[gridSpace] = invStack;
canContinue = true;
}
}
}
}
}
if(!canContinue)
{
return;
}
ItemStack returnStack = CraftingManager.getInstance().findMatchingRecipe(inventory, world);
if (returnStack != null)
{
IInventory outputInv = null;
List<IInventory> invList = new ArrayList();
TileEntity northEntity = world.getTileEntity(x, y-1, z - 2);
TileEntity southEntity = world.getTileEntity(x, y-1, z + 2);
TileEntity eastEntity = world.getTileEntity(x + 2, y-1, z);
TileEntity westEntity = world.getTileEntity(x - 2, y-1, z);
if(southEntity instanceof IInventory)
{
outputInv = (IInventory)southEntity;
}
if(northEntity instanceof IInventory)
{
invList.add((IInventory)northEntity);
}
if (outputInv != null && (!limitToSingleStack ? SpellHelper.canInsertStackFullyIntoInventory(returnStack, outputInv, ForgeDirection.DOWN) : SpellHelper.canInsertStackFullyIntoInventory(returnStack, outputInv, ForgeDirection.DOWN, true, returnStack.getMaxStackSize())))
{
Map<Integer, Map<Integer, Integer>> syphonMap = new HashMap(); //Inventory, Slot, how much claimed
for(int n = 0; n < recipe.length; n++) //Look for the correct items
{
ItemStack recipeStack = recipe[n];
if(recipeStack == null)
{
continue;
}
boolean isItemTaken = false;
for(int i = 0; i < invList.size(); i++)
{
if(isItemTaken)
{
break;
}
IInventory inputInv = invList.get(i);
if(inputInv == null)
{
continue;
}
for(int j = 0; j < inputInv.getSizeInventory(); j++)
{
if(!inputInv.isItemValidForSlot(j, recipeStack))
{
continue;
}
ItemStack invItem = inputInv.getStackInSlot(j);
if(invItem == null)
{
continue;
}
if(this.areItemsEqualForCrafting(recipeStack, invItem))
{
System.out.println("Item is equal and valid");
//TODO
inventory.setInventorySlotContents(n, invItem);
ItemStack returnedStack = CraftingManager.getInstance().findMatchingRecipe(inventory, world);
if(returnedStack == null || returnedStack.getItem() == null || returnedStack.getItem() != returnStack.getItem())
{
continue;
}
Map<Integer, Integer> slotMap = syphonMap.get(i);
if(slotMap == null)
{
slotMap = new HashMap();
syphonMap.put(i, slotMap);
}
if(slotMap.containsKey(j))
{
int syphoned = slotMap.get(j);
if(invItem.stackSize - syphoned > 0)
{
slotMap.put(j, syphoned + 1);
isItemTaken = true;
break;
}
}else
{
slotMap.put(j, 1);
isItemTaken = true;
break;
}
}
}
}
if(!isItemTaken)
{
// System.out.println("Item is not available!");
return;
}
}
/* The recipe is valid and the items have been found */
System.out.println("Valid!");
SpellHelper.insertStackIntoInventory(CraftingManager.getInstance().findMatchingRecipe(inventory, world), outputInv, ForgeDirection.DOWN);
for(Entry<Integer, Map<Integer, Integer>> entry1 : syphonMap.entrySet())
{
IInventory inputInv = invList.get(entry1.getKey());
for(Entry<Integer, Integer> entry2 : entry1.getValue().entrySet())
{
ItemStack drainedStack = inputInv.getStackInSlot(entry2.getKey());
Item item = drainedStack.getItem();
if(item.hasContainerItem(drainedStack))
{
inputInv.setInventorySlotContents(entry2.getKey(), item.getContainerItem(drainedStack));
}else
{
drainedStack.stackSize -= entry2.getValue();
if(drainedStack.stackSize <= 0)
{
inputInv.setInventorySlotContents(entry2.getKey(), null);
}
}
}
}
SoulNetworkHandler.syphonFromNetwork(owner, this.getCostPerRefresh());
world.markBlockForUpdate(x, y-1, z + 2);
world.markBlockForUpdate(x, y-1, z - 2);
world.markBlockForUpdate(x + 2, y-1, z);
world.markBlockForUpdate(x - 2, y-1, z);
}
}
}
}
@Override
public int getCostPerRefresh()
{
return 0;
}
@Override
public List<RitualComponent> getRitualComponentList()
{
ArrayList<RitualComponent> autoCraftingRitual = new ArrayList();
this.addCornerRunes(autoCraftingRitual, 1, 1, RitualComponent.EARTH);
this.addParallelRunes(autoCraftingRitual, 1, 1, RitualComponent.EARTH);
autoCraftingRitual.add(new RitualComponent(0, 1, 0, RitualComponent.AIR));
this.addOffsetRunes(autoCraftingRitual, 1, 2, -1, RitualComponent.FIRE);
this.addCornerRunes(autoCraftingRitual, 1, -1, RitualComponent.FIRE);
autoCraftingRitual.add(new RitualComponent(-1, -1, 0, RitualComponent.EARTH));
autoCraftingRitual.add(new RitualComponent(1, -1, 0, RitualComponent.EARTH));
autoCraftingRitual.add(new RitualComponent(0, -1, -1, RitualComponent.EARTH));
autoCraftingRitual.add(new RitualComponent(0, -1, 0, RitualComponent.FIRE));
autoCraftingRitual.add(new RitualComponent(0, -1, 1, RitualComponent.WATER));
return autoCraftingRitual;
}
public boolean areItemsEqualForCrafting(ItemStack stack1, ItemStack stack2)
{
if (stack1 == null)
{
return false;
}
if (stack2 == null)
{
return true;
}
if (stack1.isItemStackDamageable() ^ stack2.isItemStackDamageable())
{
return false;
}
return stack1.getItem() == stack2.getItem() && (stack1.getItem().getHasSubtypes() ? stack1.getItemDamage() == stack2.getItemDamage() : true);
}
public boolean areItemStacksEqualWithWildcard(ItemStack recipeStack, ItemStack comparedStack)
{
return recipeStack.isItemEqual(comparedStack) || (recipeStack.getItemDamage() == OreDictionary.WILDCARD_VALUE && recipeStack.getItem() == comparedStack.getItem());
}
public Int3 getSlotPositionForDirection(int slot, int direction)
{
int x = slot % 3 - 1;
int z = slot / 3 - 1;
switch(direction)
{
case 1: //NORTH-facing
return new Int3(x, 2, z);
case 2: //EAST-facing
return new Int3(-z, 2, x);
case 3: //SOUTH-facing
return new Int3(-x, 2, -z);
case 4: //WEST-facing
return new Int3(z, 2, -x);
}
return new Int3(0,0,0);
}
}

View file

@ -66,9 +66,13 @@ public class RitualEffectSoulBound extends RitualEffect
if (BindingRegistry.isRequiredItemValid(itemStack))
{
ritualStone.setVar1(BindingRegistry.getIndexForItem(itemStack) + 1);
itemStack.stackSize--;
world.addWeatherEffect(new EntityLightningBolt(world, x, y + 1, z));
ritualStone.setCooldown(ritualStone.getCooldown() - 1);
item.setDead();
if(itemStack.stackSize <= 0)
{
item.setDead();
}
break;
}

View file

@ -466,9 +466,7 @@ public class SpellHelper
return false;
}
boolean tagsEqual = ItemStack.areItemStackTagsEqual(stack1, stack2);
return stack1.getItem() == stack2.getItem() && tagsEqual && stack1.getItemDamage() == stack2.getItemDamage();
return stack1.getItem() == stack2.getItem() && stack1.getItemDamage() == stack2.getItemDamage() && ItemStack.areItemStackTagsEqual(stack1, stack2);
}
/**
@ -577,6 +575,92 @@ public class SpellHelper
return stack;
}
public static boolean canInsertStackFullyIntoInventory(ItemStack stack, IInventory inventory, ForgeDirection dir)
{
return canInsertStackFullyIntoInventory(stack, inventory, dir, false, 0);
}
public static boolean canInsertStackFullyIntoInventory(ItemStack stack, IInventory inventory, ForgeDirection dir, boolean fillToLimit, int limit)
{
if (stack == null)
{
return true;
}
int itemsLeft = stack.stackSize;
boolean[] canBeInserted = new boolean[inventory.getSizeInventory()];
if(inventory instanceof ISidedInventory)
{
int[] array = ((ISidedInventory)inventory).getAccessibleSlotsFromSide(dir.ordinal());
for(int in : array)
{
canBeInserted[in] = inventory.isItemValidForSlot(in, stack) && ((ISidedInventory)inventory).canInsertItem(in, stack, dir.ordinal());
}
}else
{
for(int i=0; i<canBeInserted.length; i++)
{
canBeInserted[i] = inventory.isItemValidForSlot(i, stack);
}
}
int numberMatching = 0;
if(fillToLimit)
{
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
if(!canBeInserted[i])
{
continue;
}
ItemStack invStack = inventory.getStackInSlot(i);
if(invStack != null && canCombine(stack, invStack))
{
numberMatching += invStack.stackSize;
}
}
}
if(fillToLimit && limit < stack.stackSize + numberMatching)
{
return false;
}
for (int i = 0; i < inventory.getSizeInventory(); i++)
{
if(!canBeInserted[i])
{
continue;
}
ItemStack invStack = inventory.getStackInSlot(i);
boolean canCombine = canCombine(stack, invStack);
if(canCombine)
{
if(invStack == null)
{
itemsLeft = 0;
}else
{
itemsLeft -= (invStack.getMaxStackSize() - invStack.stackSize);
}
}
if(itemsLeft <= 0)
{
return true;
}
}
return false;
}
public static ItemStack insertStackIntoInventory(ItemStack stack, IInventory inventory, ForgeDirection dir, int limit)
{
if (stack == null)