-
Notifications
You must be signed in to change notification settings - Fork 755
/
BehaviorDispenseArmorCopy.java
52 lines (46 loc) · 2.26 KB
/
BehaviorDispenseArmorCopy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package tconstruct.library.armor;
import java.util.List;
import net.minecraft.block.BlockDispenser;
import net.minecraft.command.IEntitySelector;
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
import net.minecraft.dispenser.IBlockSource;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.EnumFacing;
final class BehaviorDispenseArmorCopy extends BehaviorDefaultDispenseItem
{
/**
* Dispense the specified stack, play the dispense sound and spawn particles.
*/
protected ItemStack dispenseStack (IBlockSource par1IBlockSource, ItemStack par2ItemStack)
{
EnumFacing enumfacing = BlockDispenser.func_149937_b(par1IBlockSource.getBlockMetadata());
int i = par1IBlockSource.getXInt() + enumfacing.getFrontOffsetX();
int j = par1IBlockSource.getYInt() + enumfacing.getFrontOffsetY();
int k = par1IBlockSource.getZInt() + enumfacing.getFrontOffsetZ();
AxisAlignedBB axisalignedbb = AxisAlignedBB.getAABBPool().getAABB((double) i, (double) j, (double) k, (double) (i + 1), (double) (j + 1), (double) (k + 1));
List list = par1IBlockSource.getWorld().selectEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb, new IEntitySelector.ArmoredMob(par2ItemStack));
if (list.size() > 0)
{
EntityLivingBase entitylivingbase = (EntityLivingBase) list.get(0);
int l = entitylivingbase instanceof EntityPlayer ? 1 : 0;
int i1 = EntityLiving.getArmorPosition(par2ItemStack);
ItemStack itemstack1 = par2ItemStack.copy();
itemstack1.stackSize = 1;
entitylivingbase.setCurrentItemOrArmor(i1, itemstack1); //BUGFIX Forge: Vanilla bug fix associated with fixed setCurrentItemOrArmor indexs for players.
if (entitylivingbase instanceof EntityLiving)
{
((EntityLiving) entitylivingbase).setEquipmentDropChance(i1, 2.0F);
}
--par2ItemStack.stackSize;
return par2ItemStack;
}
else
{
return super.dispenseStack(par1IBlockSource, par2ItemStack);
}
}
}