mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +01:00
Made the magnet ring even more useful by making it pick up items directly
This commit is contained in:
parent
cc554241f7
commit
3e8d89c390
1 changed files with 17 additions and 34 deletions
|
@ -29,43 +29,26 @@ public class ItemMagnetRing extends ItemEnergy{
|
|||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){
|
||||
int energyUse = 10;
|
||||
if(entity instanceof EntityPlayer && !world.isRemote){
|
||||
EntityPlayer player = (EntityPlayer)entity;
|
||||
|
||||
if(!entity.isSneaking()){
|
||||
//Get all the Items in the area
|
||||
int range = 8;
|
||||
int range = 5;
|
||||
ArrayList<EntityItem> items = (ArrayList<EntityItem>)world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(entity.posX-range, entity.posY-range, entity.posZ-range, entity.posX+range, entity.posY+range, entity.posZ+range));
|
||||
if(!items.isEmpty()){
|
||||
for(EntityItem item : items){
|
||||
if(this.getEnergyStored(stack) >= energyUse){
|
||||
double x = entity.posX-item.posX;
|
||||
double y = entity.posY+1D-item.posY;
|
||||
double z = entity.posZ-item.posZ;
|
||||
if(!item.isDead && !item.cannotPickup()){
|
||||
int energyForItem = 350*item.getEntityItem().stackSize;
|
||||
|
||||
double distance = x*x+y*y+z*z;
|
||||
if(distance <= 1.5){
|
||||
if(entity instanceof EntityPlayer){
|
||||
item.onCollideWithPlayer((EntityPlayer)entity);
|
||||
}
|
||||
}
|
||||
else{
|
||||
double speed = 0.065/distance;
|
||||
if(this.getEnergyStored(stack) >= energyForItem){
|
||||
item.onCollideWithPlayer(player);
|
||||
|
||||
item.motionX += x*speed;
|
||||
if(y >= 0){
|
||||
item.motionY = 0.125;
|
||||
}
|
||||
else{
|
||||
item.motionY += y*speed;
|
||||
}
|
||||
item.motionZ += z*speed;
|
||||
}
|
||||
|
||||
if(!(entity instanceof EntityPlayer) || !((EntityPlayer)entity).capabilities.isCreativeMode){
|
||||
this.extractEnergy(stack, energyUse, false);
|
||||
if(!player.capabilities.isCreativeMode){
|
||||
this.extractEnergy(stack, energyForItem, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue