More fixes

This commit is contained in:
WayofTime 2014-11-20 08:27:53 -05:00
parent 75dcf143d5
commit 107cc50b05
4 changed files with 200 additions and 62 deletions

View file

@ -31,24 +31,76 @@ public class BaseCompressionHandler extends CompressionHandler
@Override
public ItemStack compressInventory(ItemStack[] inv)
{
int remaining = this.getRemainingNeeded(inv);
if(remaining <= 0)
{
this.drainInventory(inv);
return this.getResultStack();
}
return null;
}
public int getRemainingNeeded(ItemStack[] inv)
{
return iterateThroughInventory(inv, false);
}
public int drainInventory(ItemStack[] inv)
{
return iterateThroughInventory(inv, true);
}
public int iterateThroughInventory(ItemStack[] inv, boolean doDrain)
{
int needed = this.required.stackSize;
int kept = this.getLeftover();
int i = -1;
for(ItemStack invStack : inv)
{
i++;
if(invStack == null)
{
continue;
}
if(invStack.equals(invStack))
if(invStack.isItemEqual(this.required) && (invStack.getTagCompound() == null ? this.required.getTagCompound() == null : invStack.getTagCompound().equals(this.required.getTagCompound())))
{
int stackSize = invStack.stackSize;
int used = 0;
if(kept > 0)
{
int remainingFromStack = Math.max(stackSize - kept, 0);
used += stackSize - remainingFromStack;
}
kept -= used;
if(kept <= 0 && needed > 0)
{
int remainingFromStack = Math.max(stackSize - used - needed, 0);
needed -= (stackSize - used - remainingFromStack);
if(doDrain)
{
invStack.stackSize = remainingFromStack;
if(invStack.stackSize <= 0)
{
inv[i] = null;
}
}
}
if(needed <= 0)
{
return 0;
}
}
}
return null;
return needed;
}
public int getLeftover()

View file

@ -4,12 +4,14 @@ import java.util.List;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
import WayofTime.alchemicalWizardry.api.compress.CompressionRegistry;
import WayofTime.alchemicalWizardry.api.harvest.HarvestRegistry;
import WayofTime.alchemicalWizardry.api.items.interfaces.ArmourUpgrade;
import WayofTime.alchemicalWizardry.api.items.interfaces.IHolding;
@ -147,22 +149,8 @@ public class ItemPackRatSigil extends EnergyItems implements IHolding, ArmourUpg
if (par1ItemStack.stackTagCompound.getBoolean("isActive"))
{
int range = 3;
int verticalRange = 1;
int posX = (int) Math.round(par3Entity.posX - 0.5f);
int posY = (int) par3Entity.posY;
int posZ = (int) Math.round(par3Entity.posZ - 0.5f);
for (int ix = posX - range; ix <= posX + range; ix++)
{
for (int iz = posZ - range; iz <= posZ + range; iz++)
{
for (int iy = posY - verticalRange; iy <= posY + verticalRange; iy++)
{
HarvestRegistry.harvestBlock(par2World, ix, iy, iz);
}
}
}
ItemStack stack = CompressionRegistry.compressInventory(par3EntityPlayer.inventory.mainInventory);
EntityItem entityItem = new EntityItem(par2World, par3EntityPlayer.posX, par3EntityPlayer.posY, par3EntityPlayer.posZ, stack);
}
if (par2World.getWorldTime() % 200 == par1ItemStack.stackTagCompound.getInteger("worldTimeDelay") && par1ItemStack.stackTagCompound.getBoolean("isActive"))
{