2015-11-02 20:39:44 +00:00
|
|
|
package WayofTime.bloodmagic.util.handler;
|
2015-10-30 05:22:08 +00:00
|
|
|
|
2015-11-11 18:45:46 +00:00
|
|
|
import WayofTime.bloodmagic.api.util.helper.PlayerHelper;
|
|
|
|
import WayofTime.bloodmagic.item.gear.ItemPackSacrifice;
|
2015-11-02 20:39:44 +00:00
|
|
|
import WayofTime.bloodmagic.registry.ModBlocks;
|
|
|
|
import WayofTime.bloodmagic.registry.ModItems;
|
2015-10-30 05:22:08 +00:00
|
|
|
import net.minecraft.block.Block;
|
2015-11-11 18:45:46 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-10-30 05:22:08 +00:00
|
|
|
import net.minecraft.init.Items;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-11-11 18:45:46 +00:00
|
|
|
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
2015-10-30 05:22:08 +00:00
|
|
|
import net.minecraftforge.event.entity.player.FillBucketEvent;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
|
|
|
|
public class EventHandler {
|
|
|
|
|
2015-11-11 18:45:46 +00:00
|
|
|
@SubscribeEvent
|
|
|
|
public void onEntityDeath(LivingHurtEvent event) {
|
|
|
|
|
|
|
|
int chestIndex = 2;
|
|
|
|
|
|
|
|
if (event.source.getEntity() instanceof EntityPlayer && !PlayerHelper.isFakePlayer((EntityPlayer) event.source.getEntity())) {
|
|
|
|
EntityPlayer player = (EntityPlayer) event.source.getEntity();
|
|
|
|
|
|
|
|
if (player.getCurrentArmor(chestIndex) != null && player.getCurrentArmor(chestIndex).getItem() instanceof ItemPackSacrifice) {
|
|
|
|
ItemPackSacrifice pack = (ItemPackSacrifice) player.getCurrentArmor(chestIndex).getItem();
|
|
|
|
|
|
|
|
boolean shouldSyphon = pack.getStoredLP(player.getCurrentArmor(chestIndex)) < pack.CAPACITY;
|
|
|
|
int totalLP = Math.round(event.ammount * pack.CONVERSION);
|
|
|
|
|
|
|
|
if (shouldSyphon)
|
|
|
|
pack.addLP(player.getCurrentArmor(chestIndex), totalLP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-30 05:22:08 +00:00
|
|
|
@SubscribeEvent
|
|
|
|
public void onBucketFill(FillBucketEvent event) {
|
|
|
|
if (event.current.getItem() != Items.bucket)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ItemStack result = null;
|
|
|
|
|
|
|
|
Block block = event.world.getBlockState(event.target.getBlockPos()).getBlock();
|
|
|
|
|
|
|
|
if (block != null && (block.equals(ModBlocks.lifeEssence)) && block.getMetaFromState(event.world.getBlockState(event.target.getBlockPos())) == 0) {
|
|
|
|
event.world.setBlockToAir(event.target.getBlockPos());
|
|
|
|
result = new ItemStack(ModItems.bucketEssence);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
event.result = result;
|
|
|
|
event.setResult(Event.Result.ALLOW);
|
|
|
|
}
|
|
|
|
}
|