ActuallyAdditions/src/main/java/ellpeck/actuallyadditions/event/EntityLivingEvent.java

83 lines
3.6 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
* This file ("EntityLivingEvent.java") is part of the Actually Additions Mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2015-11-02 20:55:19 +01:00
* © 2015 Ellpeck
2015-08-29 14:33:25 +02:00
*/
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.items.InitItems;
2015-07-17 06:51:19 +02:00
import ellpeck.actuallyadditions.items.ItemWingsOfTheBats;
2015-11-22 18:58:23 +01:00
import ellpeck.actuallyadditions.util.Util;
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;
2015-10-07 20:11:25 +02:00
import java.util.UUID;
2015-05-07 16:36:29 +02:00
public class EntityLivingEvent{
@SubscribeEvent
public void livingUpdateEvent(LivingUpdateEvent event){
2015-07-17 06:51:19 +02:00
//Ocelots dropping Hair Balls
if(event.entityLiving != null && event.entityLiving.worldObj != null && !event.entityLiving.worldObj.isRemote){
2015-10-07 20:11:25 +02:00
if((event.entityLiving instanceof EntityOcelot && ((EntityOcelot)event.entityLiving).isTamed()) || (event.entityLiving instanceof EntityPlayer && event.entityLiving.getUniqueID().equals(/*KittyVanCat*/ UUID.fromString("681d4e20-10ef-40c9-a0a5-ba2f1995ef44")))){
if(ConfigBoolValues.DO_CAT_DROPS.isEnabled()){
if(Util.RANDOM.nextInt(5000)+1 == 1){
2015-10-07 20:11:25 +02:00
EntityItem item = new EntityItem(event.entityLiving.worldObj, event.entityLiving.posX+0.5, event.entityLiving.posY+0.5, event.entityLiving.posZ+0.5, new ItemStack(InitItems.itemHairyBall));
event.entityLiving.worldObj.spawnEntityInWorld(item);
2015-05-07 16:36:29 +02:00
}
}
}
}
2015-07-17 06:51:19 +02:00
//Wings allowing Flight
this.doWingStuff(event);
}
/**
* Makes players be able to fly if they have Wings Of The Bats equipped
2015-09-27 20:00:14 +02:00
* (Partially excerpted from Botania's Wing System by Vazkii (as I had fiddled around with the system and couldn't make it work) with permission, thanks!)
*/
private void doWingStuff(LivingUpdateEvent event){
2015-07-17 06:51:19 +02:00
if(event.entityLiving instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer)event.entityLiving;
2015-07-17 13:24:33 +02:00
boolean wingsEquipped = ItemWingsOfTheBats.getWingItem(player) != null;
2015-07-17 06:51:19 +02:00
//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
2015-07-17 06:51:19 +02:00
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
}
}