use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project SilentGems by SilentChaos512.
the class GemsCommonEvents method onPlayerLoggedIn.
@SubscribeEvent
public void onPlayerLoggedIn(PlayerLoggedInEvent event) {
Greetings.greetPlayer(event.player);
SilentGems.instance.logHelper.info("Recalculating tool and armor stats for " + event.player.getDisplayNameString());
// Recalculate tool stats.
for (ItemStack stack : PlayerHelper.getNonEmptyStacks(event.player)) {
if (stack != null) {
if (stack.getItem() instanceof ITool)
ToolHelper.recalculateStats(stack);
if (stack.getItem() instanceof IArmor)
ArmorHelper.recalculateStats(stack);
}
}
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project SilentGems by SilentChaos512.
the class GemsCommonEvents method onItemPickup.
@SubscribeEvent
public void onItemPickup(EntityItemPickupEvent event) {
ItemStack entityStack = event.getItem().getItem();
if (entityStack.getItem() instanceof ItemBlock) {
for (ItemStack stack : PlayerHelper.getNonEmptyStacks(event.getEntityPlayer())) {
if (stack.getItem() instanceof ItemBlockPlacer) {
ItemBlockPlacer itemPlacer = (ItemBlockPlacer) stack.getItem();
if (itemPlacer.getAutoFillMode(stack)) {
IBlockState state = ((ItemBlock) entityStack.getItem()).getBlock().getStateFromMeta(entityStack.getItemDamage());
if (state.equals(itemPlacer.getBlockPlaced(stack))) {
// Absorb blocks into block placer.
int amountAbsorbed = itemPlacer.absorbBlocks(stack, entityStack);
if (amountAbsorbed > 0) {
StackHelper.shrink(entityStack, amountAbsorbed);
if (StackHelper.getCount(entityStack) <= 0) {
event.getItem().setDead();
}
event.getEntityPlayer().world.playSound(null, event.getItem().getPosition(), SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2f, (SilentGems.random.nextFloat() - SilentGems.random.nextFloat()) * 1.4F + 2.0F);
break;
}
}
}
}
}
}
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project SilentGems by SilentChaos512.
the class GemsCommonEvents method onBlockDrops.
@SubscribeEvent
public void onBlockDrops(BlockEvent.HarvestDropsEvent event) {
ItemSoulGem.Soul soul = ModItems.soulGem.getSoul(event);
Block block = event.getState().getBlock();
boolean isCrop = block instanceof BlockCrops;
boolean isMature = isCrop && ((BlockCrops) block).isMaxAge(event.getState());
if (soul != null && (!isCrop || (isCrop && isMature))) {
float dropRate = soul.getDropRate() * (1f + 0.15f * event.getFortuneLevel());
if (SilentGems.random.nextFloat() < dropRate) {
event.getDrops().add(soul.getStack());
}
}
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project SilentGems by SilentChaos512.
the class GemsCommonEvents method onLivingUpdate.
@SubscribeEvent
public void onLivingUpdate(LivingUpdateEvent event) {
EntityLivingBase entity = event.getEntityLiving();
if (!entity.world.isRemote) {
// Rabbit coffee
if (entity instanceof EntityRabbit) {
EntityRabbit rabbit = (EntityRabbit) event.getEntityLiving();
ModuleCoffee.tickRabbit(rabbit);
}
}
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project SilentGems by SilentChaos512.
the class ShieldEventHandler method onBlockDamage.
@SubscribeEvent(priority = EventPriority.LOW)
public void onBlockDamage(LivingHurtEvent event) {
if (!(event.getEntityLiving() instanceof EntityPlayer)) {
return;
}
ItemGemShield item = ModItems.shield;
DamageSource source = event.getSource();
EntityPlayer player = (EntityPlayer) event.getEntityLiving();
ItemStack shield = player.getActiveItemStack();
float damage = event.getAmount();
// Block magic damage?
if (item.shouldBlockDamage(event.getEntityLiving()) && source.isMagicDamage()) {
float protection = ToolHelper.getMagicProtection(shield);
damage = damage < 2f ? 1f : damage / 2f;
event.setAmount(event.getAmount() * MathHelper.clamp(1f - protection, 0f, 1f));
} else {
damage = 0f;
}
// Rebound damage?
if (source.getImmediateSource() != null) {
float melee = item.getMeleeDamage(shield);
if (melee > 0f) {
source.getImmediateSource().attackEntityFrom(DamageSource.causeThornsDamage(player), melee);
damage += 1f;
}
}
// Damage the shield.
ToolHelper.attemptDamageTool(shield, Math.round(damage), player);
}
Aggregations