Search in sources :

Example 21 with SubscribeEvent

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

the class MinecartHooks method onMinecartInteract.

@SubscribeEvent
public void onMinecartInteract(MinecartInteractEvent event) {
    EntityMinecart cart = event.getMinecart();
    EntityPlayer player = event.getPlayer();
    if (!CartToolsAPI.doesCartHaveOwner(cart))
        CartToolsAPI.setCartOwner(cart, player);
    if (!(cart instanceof EntityTunnelBore) && player.getDistanceSqToEntity(cart) > MAX_INTERACT_DIST_SQ) {
        event.setCanceled(true);
        return;
    }
    if (cart.isDead) {
        event.setCanceled(true);
        return;
    }
    if (cart.canBeRidden()) {
        //TODO: this will interfere with carts that multiple players can ride, re-evaluate
        if (cart.isBeingRidden() && player.getRidingEntity() != cart) {
            event.setCanceled(true);
            return;
        }
        if (player.getRidingEntity() != null && player.getRidingEntity() != cart) {
            event.setCanceled(true);
            return;
        }
        if (player.getRidingEntity() != cart && player.isOnLadder()) {
            event.setCanceled(true);
            return;
        }
    }
    if (!player.canEntityBeSeen(cart)) {
        event.setCanceled(true);
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityMinecart(net.minecraft.entity.item.EntityMinecart) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 22 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project Overloaded by CJ-MC-Mods.

the class ItemMultiTool method teleportDrops.

@SubscribeEvent(priority = EventPriority.LOWEST)
public void teleportDrops(@Nonnull BlockEvent.HarvestDropsEvent event) {
    if (event.isCanceled())
        return;
    EntityPlayer player = event.getHarvester();
    if (player == null || event.getHarvester().getHeldItemMainhand().getItem() != this)
        return;
    World world = event.getWorld();
    float chance = event.getDropChance();
    for (ItemStack stack : event.getDrops()) {
        if (world.rand.nextFloat() <= chance) {
            EntityItem toSpawn = new EntityItem(world, player.posX, player.posY, player.posZ, stack);
            world.spawnEntity(toSpawn);
        }
    }
    event.getDrops().clear();
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 23 with SubscribeEvent

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

the class ItemToolTipHandler method addProductInfo.

@SubscribeEvent
public void addProductInfo(ItemTooltipEvent event) {
    if (StackHelper.hasTag(event.getItemStack())) {
        final NBTTagCompound tag = StackHelper.getTag(event.getItemStack());
        if (tag.hasKey(IAgriHarvestProduct.PRODUCT_MARKER_TAG)) {
            final int minAmount = tag.getInteger(IAgriHarvestProduct.PRODUCT_MIN_TAG);
            final int maxAmount = tag.getInteger(IAgriHarvestProduct.PRODUCT_MAX_TAG);
            final double chance = tag.getDouble(IAgriHarvestProduct.PRODUCT_CHANCE_TAG);
            event.getToolTip().add(ChatFormatting.GRAY + "Chance: " + DecimalFormat.getPercentInstance().format(chance));
            event.getToolTip().add(ChatFormatting.GRAY + "Min. Amount: " + minAmount);
            event.getToolTip().add(ChatFormatting.GRAY + "Max. Amount: " + maxAmount);
        }
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 24 with SubscribeEvent

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

the class ModLoot method onLootTableLoad.

@SubscribeEvent
public void onLootTableLoad(LootTableLoadEvent event) {
    ResourceLocation n = event.getName();
    if (n.equals(LootTableList.CHESTS_END_CITY_TREASURE)) {
        if (ModConfigTools.mobCatcher_loot)
            event.getTable().getPool("main").addEntry(new LootEntryItem(ModItems.itemMobCatcherMega, 1, 3, new LootFunction[0], new LootCondition[0], ModConstants.Mod.MODID + ":megaMCD"));
    } else if (n.equals(LootTableList.CHESTS_STRONGHOLD_CORRIDOR)) {
        if (ModConfigTools.mobCatcher_loot)
            event.getTable().getPool("main").addEntry(new LootEntryItem(ModItems.itemMobCatcherHyper, 1, 3, new LootFunction[0], new LootCondition[0], ModConstants.Mod.MODID + ":hyperMCD"));
    } else if (n.equals(LootTableList.CHESTS_SIMPLE_DUNGEON)) {
        if (ModConfigTools.mobCatcher_loot) {
            event.getTable().getPool("main").addEntry(new LootEntryItem(ModItems.itemMobCatcherSuper, 1, 3, new LootFunction[0], new LootCondition[0], ModConstants.Mod.MODID + ":superMCD"));
            event.getTable().getPool("main").addEntry(new LootEntryItem(ModItems.itemMobCatcherRegular, 3, -2, new LootFunction[0], new LootCondition[0], ModConstants.Mod.MODID + ":regularMCD"));
        }
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) LootEntryItem(net.minecraft.world.storage.loot.LootEntryItem) LootFunction(net.minecraft.world.storage.loot.functions.LootFunction) LootCondition(net.minecraft.world.storage.loot.conditions.LootCondition) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 25 with SubscribeEvent

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

the class PlayerInventoryTickHandler method onPlayerInventoryTick.

@SubscribeEvent
public void onPlayerInventoryTick(TickEvent.PlayerTickEvent e) {
    EntityPlayer player = e.player;
    Iterable<SlotNotation> iter = InventoryIterator.getIterable(player, EnumInventory.MAIN);
    for (SlotNotation slot : iter) {
        ItemStack stack = slot.getItem();
        if (stack != null && stack.getItem() instanceof IPlayerInventoryTick) {
            ((IPlayerInventoryTick) stack.getItem()).onPlayerInventoryTick(stack, slot, player);
            ;
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) IPlayerInventoryTick(convenientadditions.api.item.IPlayerInventoryTick) ItemStack(net.minecraft.item.ItemStack) SlotNotation(convenientadditions.api.inventory.SlotNotation) 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