2015-05-07 16:36:29 +02:00
|
|
|
package ellpeck.actuallyadditions.event;
|
|
|
|
|
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigBoolValues;
|
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
|
|
|
import ellpeck.actuallyadditions.items.InitItems;
|
2015-07-17 06:51:19 +02:00
|
|
|
import ellpeck.actuallyadditions.items.ItemWingsOfTheBats;
|
2015-05-07 16:36:29 +02:00
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
import net.minecraft.entity.passive.EntityOcelot;
|
2015-07-17 06:51:19 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-05-07 16:36:29 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
public class EntityLivingEvent{
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public void livingUpdateEvent(LivingUpdateEvent event){
|
2015-07-17 06:51:19 +02:00
|
|
|
//Ocelots dropping Hair Balls
|
2015-05-07 16:36:29 +02:00
|
|
|
if(!event.entityLiving.worldObj.isRemote){
|
|
|
|
if(event.entityLiving instanceof EntityOcelot){
|
|
|
|
EntityOcelot theOcelot = (EntityOcelot)event.entityLiving;
|
|
|
|
if(ConfigBoolValues.DO_CAT_DROPS.isEnabled() && theOcelot.isTamed()){
|
|
|
|
if(new Random().nextInt(ConfigIntValues.CAT_DROP_CHANCE.getValue())+1 == 1){
|
|
|
|
EntityItem item = new EntityItem(theOcelot.worldObj, theOcelot.posX + 0.5, theOcelot.posY + 0.5, theOcelot.posZ + 0.5, new ItemStack(InitItems.itemHairyBall));
|
|
|
|
theOcelot.worldObj.spawnEntityInWorld(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-17 06:51:19 +02:00
|
|
|
|
|
|
|
//Wings allowing Flight
|
|
|
|
if(event.entityLiving instanceof EntityPlayer){
|
|
|
|
EntityPlayer player = (EntityPlayer)event.entityLiving;
|
|
|
|
boolean wingsEquipped = ItemWingsOfTheBats.hasWingItem(player);
|
|
|
|
|
|
|
|
//If Player isn't (really) winged
|
|
|
|
if(!ItemWingsOfTheBats.isPlayerWinged(player)){
|
|
|
|
if(wingsEquipped){
|
|
|
|
//Make the Player actually winged
|
|
|
|
ItemWingsOfTheBats.addWingsToPlayer(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//If Player is (or should be) winged
|
|
|
|
else{
|
|
|
|
if(wingsEquipped){
|
|
|
|
//Allow the Player to fly when he has Wings equipped every tick
|
|
|
|
//It appears to be reset somewhere if you don't update it every tick
|
|
|
|
//but I haven't found the place where it gets reset which is slightly odd
|
|
|
|
player.capabilities.allowFlying = true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
//Make the Player not winged
|
|
|
|
ItemWingsOfTheBats.removeWingsFromPlayer(player);
|
|
|
|
//Reset Player's Values
|
|
|
|
if(!player.capabilities.isCreativeMode){
|
|
|
|
player.capabilities.allowFlying = false;
|
|
|
|
player.capabilities.isFlying = false;
|
|
|
|
//Enables Fall Damage again (Automatically gets disabled for some reason)
|
|
|
|
player.capabilities.disableDamage = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-07 16:36:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|