Search in sources :

Example 96 with SubscribeEvent

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);
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) ITool(net.silentchaos512.gems.api.ITool) IArmor(net.silentchaos512.gems.api.IArmor) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 97 with SubscribeEvent

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;
                        }
                    }
                }
            }
        }
    }
}
Also used : ItemBlockPlacer(net.silentchaos512.gems.item.ItemBlockPlacer) IBlockState(net.minecraft.block.state.IBlockState) ItemStack(net.minecraft.item.ItemStack) ItemBlock(net.minecraft.item.ItemBlock) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 98 with SubscribeEvent

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());
        }
    }
}
Also used : Soul(net.silentchaos512.gems.item.ItemSoulGem.Soul) BlockCrops(net.minecraft.block.BlockCrops) ItemSoulGem(net.silentchaos512.gems.item.ItemSoulGem) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 99 with SubscribeEvent

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);
        }
    }
}
Also used : EntityRabbit(net.minecraft.entity.passive.EntityRabbit) EntityLivingBase(net.minecraft.entity.EntityLivingBase) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 100 with SubscribeEvent

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);
}
Also used : ItemGemShield(net.silentchaos512.gems.item.tool.ItemGemShield) DamageSource(net.minecraft.util.DamageSource) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1135 ItemStack (net.minecraft.item.ItemStack)316 EntityPlayer (net.minecraft.entity.player.EntityPlayer)314 World (net.minecraft.world.World)196 BlockPos (net.minecraft.util.math.BlockPos)179 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)136 IBlockState (net.minecraft.block.state.IBlockState)120 ResourceLocation (net.minecraft.util.ResourceLocation)102 Entity (net.minecraft.entity.Entity)93 Block (net.minecraft.block.Block)86 EntityLivingBase (net.minecraft.entity.EntityLivingBase)84 Minecraft (net.minecraft.client.Minecraft)72 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)66 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)64 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)55 Item (net.minecraft.item.Item)53 EntityItem (net.minecraft.entity.item.EntityItem)48 TileEntity (net.minecraft.tileentity.TileEntity)46 TextComponentString (net.minecraft.util.text.TextComponentString)42 Random (java.util.Random)37