mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 16:58: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
|
@Override
|
||||||
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){
|
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()){
|
if(!entity.isSneaking()){
|
||||||
//Get all the Items in the area
|
//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));
|
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()){
|
if(!items.isEmpty()){
|
||||||
for(EntityItem item : items){
|
for(EntityItem item : items){
|
||||||
if(this.getEnergyStored(stack) >= energyUse){
|
if(!item.isDead && !item.cannotPickup()){
|
||||||
double x = entity.posX-item.posX;
|
int energyForItem = 350*item.getEntityItem().stackSize;
|
||||||
double y = entity.posY+1D-item.posY;
|
|
||||||
double z = entity.posZ-item.posZ;
|
|
||||||
|
|
||||||
double distance = x*x+y*y+z*z;
|
if(this.getEnergyStored(stack) >= energyForItem){
|
||||||
if(distance <= 1.5){
|
item.onCollideWithPlayer(player);
|
||||||
if(entity instanceof EntityPlayer){
|
|
||||||
item.onCollideWithPlayer((EntityPlayer)entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
double speed = 0.065/distance;
|
|
||||||
|
|
||||||
item.motionX += x*speed;
|
if(!player.capabilities.isCreativeMode){
|
||||||
if(y >= 0){
|
this.extractEnergy(stack, energyForItem, false);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue