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

83 lines
3.7 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
2016-01-03 16:05:51 +01:00
* http://ellpeck.de/actaddlicense/
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-01-03 16:05:51 +01:00
* © 2016 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.event;
2015-05-07 16:36:29 +02:00
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.ItemWingsOfTheBats;
import de.ellpeck.actuallyadditions.mod.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;
2016-01-07 18:20:59 +01:00
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
2015-05-07 16:36:29 +02:00
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
}
}