Apply to shovel and axe as well

This commit is contained in:
ljfa-ag 2015-04-10 20:30:52 +02:00
parent d800e06cb8
commit 1887df3d1e
3 changed files with 30 additions and 32 deletions

View file

@ -2,6 +2,7 @@ package WayofTime.alchemicalWizardry.common.items;
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBindable;
import WayofTime.alchemicalWizardry.common.ItemType;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -25,6 +26,8 @@ import net.minecraftforge.common.ForgeHooks;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.HashMultiset;
public class BoundAxe extends ItemAxe implements IBindable
{
public float efficiencyOnProperMaterial = 12.0F;
@ -135,6 +138,8 @@ public class BoundAxe extends ItemAxe implements IBindable
boolean silkTouch = EnchantmentHelper.getSilkTouchModifier(par3EntityPlayer);
int fortuneLvl = EnchantmentHelper.getFortuneModifier(par3EntityPlayer);
HashMultiset<ItemType> dropMultiset = HashMultiset.create();
for (int i = -5; i <= 5; i++)
{
for (int j = 0; j <= 10; j++)
@ -152,27 +157,18 @@ public class BoundAxe extends ItemAxe implements IBindable
{
if (silkTouch && block.canSilkHarvest(par2World, par3EntityPlayer, posX + i, posY + j, posZ + k, meta))
{
ItemStack droppedItem = new ItemStack(block, 1, meta);
if (!par2World.isRemote)
{
par2World.spawnEntityInWorld(new EntityItem(par2World, posX, posY + par3EntityPlayer.getEyeHeight(), posZ, droppedItem));
}
dropMultiset.add(new ItemType(block, meta));
} else
{
ArrayList<ItemStack> itemDropList = block.getDrops(par2World, posX + i, posY + j, posZ + k, meta, fortuneLvl);
if (itemDropList != null)
{
for (ItemStack item : itemDropList)
{
if (!par2World.isRemote)
{
par2World.spawnEntityInWorld(new EntityItem(par2World, posX, posY + par3EntityPlayer.getEyeHeight(), posZ, item));
}
}
for (ItemStack stack : itemDropList)
dropMultiset.add(ItemType.fromStack(stack), stack.stackSize);
}
}
par2World.setBlockToAir(posX + i, posY + j, posZ + k);
}
}
@ -180,7 +176,8 @@ public class BoundAxe extends ItemAxe implements IBindable
}
}
BoundPickaxe.dropMultisetStacks(dropMultiset, par2World, posX, posY + par3EntityPlayer.getEyeHeight(), posZ);
return par1ItemStack;
}

View file

@ -184,7 +184,14 @@ public class BoundPickaxe extends ItemPickaxe implements IBindable
}
}
}
dropMultisetStacks(dropMultiset, par2World, posX, posY + par3EntityPlayer.getEyeHeight(), posZ);
return par1ItemStack;
}
public static void dropMultisetStacks(Multiset<ItemType> dropMultiset, World world, double x, double y, double z)
{
for (Multiset.Entry<ItemType> entry : dropMultiset.entrySet())
{
int count = entry.getCount();
@ -194,15 +201,13 @@ public class BoundPickaxe extends ItemPickaxe implements IBindable
//Drop in groups of maximum size
while (count >= maxStackSize)
{
par2World.spawnEntityInWorld(new EntityItem(par2World, posX, posY + par3EntityPlayer.getEyeHeight(), posZ, type.createStack(maxStackSize)));
world.spawnEntityInWorld(new EntityItem(world, x, y, z, type.createStack(maxStackSize)));
count -= maxStackSize;
}
//Drop remainder
if (count > 0)
par2World.spawnEntityInWorld(new EntityItem(par2World, posX, posY + par3EntityPlayer.getEyeHeight(), posZ, type.createStack(count)));
world.spawnEntityInWorld(new EntityItem(world, x, y, z, type.createStack(count)));
}
return par1ItemStack;
}
@Override

View file

@ -2,8 +2,10 @@ package WayofTime.alchemicalWizardry.common.items;
import WayofTime.alchemicalWizardry.AlchemicalWizardry;
import WayofTime.alchemicalWizardry.api.items.interfaces.IBindable;
import WayofTime.alchemicalWizardry.common.ItemType;
import WayofTime.alchemicalWizardry.common.spell.complex.effect.SpellHelper;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multimap;
import cpw.mods.fml.relauncher.Side;
@ -141,6 +143,8 @@ public class BoundShovel extends ItemSpade implements IBindable
boolean silkTouch = EnchantmentHelper.getSilkTouchModifier(par3EntityPlayer);
int fortuneLvl = EnchantmentHelper.getFortuneModifier(par3EntityPlayer);
HashMultiset<ItemType> dropMultiset = HashMultiset.create();
for (int i = -5; i <= 5; i++)
{
for (int j = 0; j <= 10; j++)
@ -158,25 +162,15 @@ public class BoundShovel extends ItemSpade implements IBindable
{
if (silkTouch && block.canSilkHarvest(par2World, par3EntityPlayer, posX + i, posY + j, posZ + k, meta))
{
ItemStack droppedItem = new ItemStack(block, 1, meta);
if (!par2World.isRemote)
{
par2World.spawnEntityInWorld(new EntityItem(par2World, posX, posY + par3EntityPlayer.getEyeHeight(), posZ, droppedItem));
}
dropMultiset.add(new ItemType(block, meta));
} else
{
ArrayList<ItemStack> itemDropList = block.getDrops(par2World, posX + i, posY + j, posZ + k, meta, fortuneLvl);
if (itemDropList != null)
{
for (ItemStack item : itemDropList)
{
if (!par2World.isRemote)
{
par2World.spawnEntityInWorld(new EntityItem(par2World, posX, posY + par3EntityPlayer.getEyeHeight(), posZ, item));
}
}
for (ItemStack stack : itemDropList)
dropMultiset.add(ItemType.fromStack(stack), stack.stackSize);
}
}
@ -186,6 +180,8 @@ public class BoundShovel extends ItemSpade implements IBindable
}
}
}
BoundPickaxe.dropMultisetStacks(dropMultiset, par2World, posX, posY + par3EntityPlayer.getEyeHeight(), posZ);
return par1ItemStack;
}