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;
|
2015-11-30 00:04:50 +00:00
|
|
|
import WayofTime.bloodmagic.block.BlockAltar;
|
|
|
|
import WayofTime.bloodmagic.item.ItemAltarMaker;
|
2015-12-29 19:32:35 +00:00
|
|
|
import WayofTime.bloodmagic.item.ItemBoundSword;
|
2015-11-11 18:45:46 +00:00
|
|
|
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-11-30 01:12:44 +00:00
|
|
|
import WayofTime.bloodmagic.util.ChatUtil;
|
|
|
|
import WayofTime.bloodmagic.util.helper.TextHelper;
|
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-11-30 00:04:50 +00:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
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;
|
2015-11-30 00:04:50 +00:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
2015-12-29 19:32:35 +00:00
|
|
|
import net.minecraftforge.event.world.BlockEvent;
|
2015-10-30 05:22:08 +00:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
public class EventHandler
|
|
|
|
{
|
2015-11-11 18:45:46 +00:00
|
|
|
@SubscribeEvent
|
2015-12-30 20:34:40 +00:00
|
|
|
public void onEntityDeath(LivingHurtEvent event)
|
|
|
|
{
|
2015-11-11 18:45:46 +00:00
|
|
|
int chestIndex = 2;
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (event.source.getEntity() instanceof EntityPlayer && !PlayerHelper.isFakePlayer((EntityPlayer) event.source.getEntity()))
|
|
|
|
{
|
2015-11-11 18:45:46 +00:00
|
|
|
EntityPlayer player = (EntityPlayer) event.source.getEntity();
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (player.getCurrentArmor(chestIndex) != null && player.getCurrentArmor(chestIndex).getItem() instanceof ItemPackSacrifice)
|
|
|
|
{
|
2015-11-11 18:45:46 +00:00
|
|
|
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
|
2015-12-30 20:34:40 +00:00
|
|
|
public void onBucketFill(FillBucketEvent event)
|
|
|
|
{
|
2015-10-30 05:22:08 +00:00
|
|
|
if (event.current.getItem() != Items.bucket)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ItemStack result = null;
|
|
|
|
|
|
|
|
Block block = event.world.getBlockState(event.target.getBlockPos()).getBlock();
|
|
|
|
|
2015-12-30 20:34:40 +00:00
|
|
|
if (block != null && (block.equals(ModBlocks.lifeEssence)) && block.getMetaFromState(event.world.getBlockState(event.target.getBlockPos())) == 0)
|
|
|
|
{
|
2015-10-30 05:22:08 +00:00
|
|
|
event.world.setBlockToAir(event.target.getBlockPos());
|
|
|
|
result = new ItemStack(ModItems.bucketEssence);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
event.result = result;
|
|
|
|
event.setResult(Event.Result.ALLOW);
|
|
|
|
}
|
2015-11-30 00:04:50 +00:00
|
|
|
|
|
|
|
@SubscribeEvent
|
2015-12-30 20:34:40 +00:00
|
|
|
public void harvestEvent(PlayerEvent.HarvestCheck event)
|
|
|
|
{
|
|
|
|
if (event.block != null && event.block instanceof BlockAltar && event.entityPlayer != null && event.entityPlayer instanceof EntityPlayerMP && event.entityPlayer.getCurrentEquippedItem() != null && event.entityPlayer.getCurrentEquippedItem().getItem() instanceof ItemAltarMaker)
|
|
|
|
{
|
2015-11-30 00:04:50 +00:00
|
|
|
ItemAltarMaker altarMaker = (ItemAltarMaker) event.entityPlayer.getCurrentEquippedItem().getItem();
|
2015-12-28 22:27:59 +00:00
|
|
|
ChatUtil.sendNoSpam(event.entityPlayer, TextHelper.localizeEffect("chat.BloodMagic.altarMaker.destroy", altarMaker.destroyAltar(event.entityPlayer)));
|
2015-11-30 00:04:50 +00:00
|
|
|
}
|
|
|
|
}
|
2015-10-30 05:22:08 +00:00
|
|
|
}
|