Search in sources :

Example 26 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project ConvenientAdditions by Necr0.

the class EventHandlerLuck method luck.

@SubscribeEvent
public void luck(HarvestDropsEvent e) {
    //e.getState().getBlock().getDrops(e.getWorld(), e.getPos(), e.getState(), 3);
    if (e.getHarvester() != null && !e.getHarvester().isSneaking() && !e.getHarvester().getHeldItemMainhand().isEmpty() && e.getHarvester().getHeldItemMainhand().getItem() == ModItems.itemAdventurersPickaxe) {
        int luck = (int) ModItems.itemAdventurersPickaxe.getToolProperty(e.getHarvester().getHeldItemMainhand(), "mining_luck");
        if (Helper.doesOreDictMatch(e.getState(), "ore", true) && luck > 0) {
            e.setDropChance(0f);
            for (ItemStack s : e.getState().getBlock().getDrops(e.getWorld(), e.getPos(), e.getState(), luck)) {
                double x = e.getPos().getX() + .5, y = e.getPos().getY() + .5, z = e.getPos().getZ() + .5;
                e.getWorld().spawnEntity(new EntityItem(e.getWorld(), x, y, z, s));
            }
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 27 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project ConvenientAdditions by Necr0.

the class EventHandlerSoulbound method onPlayerClone.

@SubscribeEvent
public void onPlayerClone(PlayerEvent.Clone e) {
    if (e.getEntityPlayer().getEntityWorld().isRemote || e.getEntityPlayer().getEntityWorld().getGameRules().getBoolean("keepInventory"))
        return;
    EntityPlayer original = e.getOriginal();
    EntityPlayer clone = e.getEntityPlayer();
    IItemHandler h = original.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
    for (int slot = 0; slot < h.getSlots(); slot++) {
        ItemStack stack = h.getStackInSlot(slot);
        if (stack != null && stack.getItem() instanceof ISoulbound && ((ISoulbound) stack.getItem()).isSoulbound(stack, original)) {
            IItemHandler h2 = clone.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, EnumFacing.DOWN);
            ItemStack out = tryInsert(stack, h2);
            if (out == null) {
                h.extractItem(slot, 64, false);
            } else {
                stack.setCount(out.getCount());
            }
        }
    }
}
Also used : ISoulbound(convenientadditions.api.item.ISoulbound) IItemHandler(net.minecraftforge.items.IItemHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 28 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project ConvenientAdditions by Necr0.

the class ItemClimbingClaws method onLivingUpdate.

@SubscribeEvent
public void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
    if (event.getEntityLiving() instanceof EntityPlayer) {
        EntityPlayer player = (EntityPlayer) event.getEntityLiving();
        for (SlotNotation slot : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
            ItemStack stack = slot.getItem();
            if (!stack.isEmpty() && stack.getItem() instanceof ItemClimbingClaws) {
                ItemClimbingClaws item = (ItemClimbingClaws) stack.getItem();
                if (item.wallClimbSpeed > 0) {
                    Vec3d ppos = new Vec3d(player.posX, player.posY, player.posZ);
                    Vec3d plook = player.getLookVec();
                    plook = plook.subtract(0, plook.yCoord, 0).normalize();
                    RayTraceResult r = player.world.rayTraceBlocks(ppos, ppos.add(plook.scale(.425)), false, true, false);
                    if (r != null && r.typeOfHit == RayTraceResult.Type.BLOCK) {
                        IBlockState state = player.world.getBlockState(r.getBlockPos());
                        if (state.isSideSolid(player.world, r.getBlockPos(), r.sideHit)) {
                            if (player.isSneaking()) {
                                if (player.moveForward > 0F) {
                                    player.motionY = Math.max(item.wallClimbSpeed, player.motionY);
                                } else {
                                    player.motionY = Math.max(0d, player.motionY);
                                }
                                player.fallDistance = 0;
                            } else {
                                player.motionY = Math.max(player.motionY, Math.min(player.motionY + .1d, -.15d));
                                if (player.motionY > -.666)
                                    player.fallDistance = 0;
                            }
                        }
                    }
                    break;
                }
            }
        }
        for (SlotNotation slot : InventoryIterator.getIterable(player, EnumInventory.BAUBLES)) {
            ItemStack stack = slot.getItem();
            if (!stack.isEmpty() && stack.getItem() instanceof ItemClimbingClaws) {
                ItemClimbingClaws item = (ItemClimbingClaws) stack.getItem();
                if (item.stepHeightBoost > 0) {
                    if (player.isSneaking())
                        player.stepHeight = .6f;
                    else
                        player.stepHeight = .6f + item.stepHeightBoost;
                    break;
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) SlotNotation(convenientadditions.api.inventory.SlotNotation) Vec3d(net.minecraft.util.math.Vec3d) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 29 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project VoodooCraft by Mod-DevCafeTeam.

the class CapabilityHandler method onClonePlayer.

@SuppressWarnings("all")
@SubscribeEvent
public static void onClonePlayer(net.minecraftforge.event.entity.player.PlayerEvent.Clone event) {
    //Copy capability on player death to new player
    if (event.isWasDeath() && (event.getEntityPlayer() instanceof EntityPlayerMP)) {
        EntityPlayerMP player = (EntityPlayerMP) event.getEntityPlayer();
        for (Capability<? extends ICapability> cap : VCCapabilities.getCapabilities()) {
            ICapability oldicap = event.getOriginal().getCapability(cap, null);
            ICapability icap = player.getCapability(cap, null);
            if (oldicap == null || icap == null)
                continue;
            icap.deserializeNBT(oldicap.serializeNBT());
            icap.dataChanged(player);
        }
    }
}
Also used : ICapability(mdc.voodoocraft.capability.ICapability) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 30 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project VoodooCraft by Mod-DevCafeTeam.

the class HexHandler method hurtEvent.

/**
     * Protection Hex
     */
@SubscribeEvent
public static void hurtEvent(LivingHurtEvent event) {
    EntityLivingBase entity = event.getEntityLiving();
    ItemStack stack;
    //Protection - Absorbs some damage, with a 10s cooldown
    if (event.getSource().getSourceOfDamage() != null && (stack = getDollWithHex(entity, "protection")) != null) {
        UUID uuid = entity.getUniqueID();
        Long cooldownStart = protectionCooldowns.get(uuid);
        long worldTime = entity.world.getTotalWorldTime();
        //Check if hex is ready to protect
        if (//200 ticks == 10 seconds
        cooldownStart == null || (worldTime - cooldownStart) >= 200) {
            //Protect from up to 5 hearts of damage
            float protection = 10f;
            float damage = event.getAmount();
            event.setAmount(damage <= protection ? 0 : damage - protection);
            //Sets the new cooldown start
            protectionCooldowns.put(uuid, worldTime);
            //Damage the doll
            stack.damageItem(1, entity);
        }
    }
}
Also used : EntityLivingBase(net.minecraft.entity.EntityLivingBase) ItemStack(net.minecraft.item.ItemStack) UUID(java.util.UUID) 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