Commit 482111ac authored by Dennis Bonke's avatar Dennis Bonke

Fixed server crash.

parent 2e873ec8
......@@ -6,6 +6,7 @@ import com.advancedmods.advancedtools.AdvancedTools;
import com.advancedmods.advancedtools.common.generic.ATItem;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
/**
......@@ -23,22 +24,29 @@ public class RingOfFlight extends ATItem implements IBauble {
return BaubleType.RING;
}
/*@Override
public void onEquippedOrLoadedIntoWorld(ItemStack stack, EntityLivingBase entity) {
startFlying((EntityPlayer) entity);
}*/
@Override
public void onWornTick(ItemStack itemStack, EntityLivingBase entityLivingBase) {
// NO-OP
if(entityLivingBase instanceof EntityPlayer) {
EntityPlayer player = ((EntityPlayer) entityLivingBase);
if(!player.capabilities.allowFlying) {
startFlying(player);
}
}
}
@Override
public void onEquipped(ItemStack itemStack, EntityLivingBase entityLivingBase) {
Minecraft mc = Minecraft.getMinecraft();
mc.thePlayer.capabilities.allowFlying = true;
startFlying((EntityPlayer) entityLivingBase);
}
@Override
public void onUnequipped(ItemStack itemStack, EntityLivingBase entityLivingBase) {
Minecraft mc = Minecraft.getMinecraft();
mc.thePlayer.capabilities.isFlying = false;
mc.thePlayer.capabilities.allowFlying = false;
stopFlying((EntityPlayer) entityLivingBase);
}
@Override
......@@ -50,4 +58,20 @@ public class RingOfFlight extends ATItem implements IBauble {
public boolean canUnequip(ItemStack itemStack, EntityLivingBase entityLivingBase) {
return true;
}
private void startFlying(EntityPlayer player) {
player.capabilities.allowFlying = true;
if(!player.getEntityWorld().isRemote) {
player.sendPlayerAbilities();
}
}
private void stopFlying(EntityPlayer player) {
player.capabilities.allowFlying = false;
player.capabilities.isFlying = false;
if(!player.getEntityWorld().isRemote) {
player.sendPlayerAbilities();
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment