Redo the ring a bit so that it now pulls items upwards

This commit is contained in:
Ellpeck 2016-07-25 14:12:52 +02:00
parent 2ce27f4735
commit 0a5c306f30

View file

@ -38,21 +38,31 @@ public class ItemMagnetRing extends ItemEnergy{
if(!items.isEmpty()){ if(!items.isEmpty()){
for(EntityItem item : items){ for(EntityItem item : items){
if(this.getEnergyStored(stack) >= energyUse){ if(this.getEnergyStored(stack) >= energyUse){
//If the Item is near enough to get picked up double x = entity.posX+0.5D-item.posX;
//(So it doesn't bounce around until it notices itself..) double y = entity.posY+1D-item.posY;
if(new Vec3d(entity.posX, entity.posY, entity.posZ).distanceTo(new Vec3d(item.posX, item.posY, item.posZ)) <= 1.5){ double z = entity.posZ+0.5D-item.posZ;
item.onCollideWithPlayer((EntityPlayer)entity);
double distance = x*x+y*y+z*z;
if(distance <= 1.5){
if(entity instanceof EntityPlayer){
item.onCollideWithPlayer((EntityPlayer)entity);
}
} }
else{ else{
double speed = 0.02; double speed = 0.035/distance;
//Move the Item closer to the Player
item.motionX += (entity.posX+0.5-item.posX)*speed;
item.motionY += (entity.posY+1.0-item.posY)*speed;
item.motionZ += (entity.posZ+0.5-item.posZ)*speed;
if(!((EntityPlayer)entity).capabilities.isCreativeMode){ item.motionX += x*speed;
this.extractEnergy(stack, energyUse, false); 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);
} }
} }
else{ else{