Search in sources :

Example 66 with SubscribeEvent

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

the class ItemToolTipHandler method addClipperTooltip.

/**
 * Adds tooltips to items that are clippers (implementing IClipper).
 *
 * @param event
 */
@SubscribeEvent
public void addClipperTooltip(ItemTooltipEvent event) {
    ItemStack stack = event.getItemStack();
    if (StackHelper.isValid(stack, IAgriClipperItem.class)) {
        event.getToolTip().add(AgriCore.getTranslator().translate("agricraft_tooltip.clipper1"));
        event.getToolTip().add(AgriCore.getTranslator().translate("agricraft_tooltip.clipper2"));
        event.getToolTip().add(AgriCore.getTranslator().translate("agricraft_tooltip.clipper3"));
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 67 with SubscribeEvent

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

the class AssortedHandler method attachRopeEvent.

@SubscribeEvent
public void attachRopeEvent(PlayerInteractEvent.RightClickBlock event) {
    World world = event.getWorld();
    BlockPos pos = event.getPos();
    IBlockState state = world.getBlockState(pos);
    ItemStack stack = event.getItemStack();
    EnumFacing facing = event.getFace();
    EntityPlayer player = event.getEntityPlayer();
    if (stack.getItem() == Item.getItemFromBlock(BWMBlocks.ROPE) && state.getBlock() instanceof BlockFence && state.getBlock() != ModBlocks.ropePost) {
        ModBlocks.ropePost.placeFencePost(world, pos);
        state = world.getBlockState(pos);
        int consumedRope = 1;
        if (BlockRopeSideways.canFastenBlock(state.getBlock())) {
            consumedRope += attachRope(world, pos, facing, Math.min(stack.getCount() - 1, ropeLimit));
        }
        if (!player.isCreative())
            stack.shrink(consumedRope);
        event.setCancellationResult(EnumActionResult.SUCCESS);
        event.setCanceled(true);
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) BlockFence(net.minecraft.block.BlockFence) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 68 with SubscribeEvent

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

the class AssortedHandler method onDismount.

@SubscribeEvent
public void onDismount(EntityMountEvent event) {
    Entity rider = event.getEntityMounting();
    Entity mount = event.getEntityBeingMounted();
/*if(!rider.isDead && !mount.isDead) {
            //if (event.isDismounting() && mount instanceof EntityHorse)
            //    event.setCanceled(true);
            if (event.isDismounting() && mount instanceof EntityKarateZombie && !((EntityKarateZombie) mount).tryDismount())
                event.setCanceled(true);
        }*/
}
Also used : Entity(net.minecraft.entity.Entity) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 69 with SubscribeEvent

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

the class WheatHandler method harvestBlock.

@SubscribeEvent(priority = EventPriority.LOWEST)
public static void harvestBlock(BlockEvent.HarvestDropsEvent event) {
    if (!InteractionWheat.REPLACE_WHEAT_DROPS)
        return;
    IBlockState state = event.getState();
    if (state.getBlock() != Blocks.WHEAT)
        return;
    List<ItemStack> drops = event.getDrops();
    if (drops instanceof ImmutableList)
        // Give up immediately, there's a mod that blocks all the fun.
        return;
    ListIterator<ItemStack> iterator = drops.listIterator();
    while (iterator.hasNext()) {
        ItemStack stack = iterator.next();
        if (stack.getItem() == Items.WHEAT)
            iterator.set(ModItems.materialWheat.getMaterial("hay", stack.getCount()));
        if (stack.getItem() == Items.WHEAT_SEEDS)
            iterator.set(new ItemStack(Items.WHEAT, stack.getCount()));
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ImmutableList(com.google.common.collect.ImmutableList) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 70 with SubscribeEvent

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

the class WheatHandler method breakSpeed.

@SubscribeEvent
public static void breakSpeed(PlayerEvent.BreakSpeed event) {
    if (!InteractionWheat.DIG_UP_CROPS)
        return;
    if (toolMaterialField == null)
        toolMaterialField = ReflectionHelper.findField(ItemHoe.class, "field_77843_a", "toolMaterial");
    EntityPlayer player = event.getEntityPlayer();
    if (player == null)
        return;
    IBlockState state = event.getState();
    Block block = state.getBlock();
    ItemStack tool = player.getHeldItemMainhand();
    if (tool.getItem() instanceof ItemHoe && "hoe".equals(block.getHarvestTool(state))) {
        try {
            Item.ToolMaterial material = (Item.ToolMaterial) toolMaterialField.get(tool.getItem());
            if (material != null)
                event.setNewSpeed(event.getNewSpeed() * material.getEfficiency());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : ItemHoe(net.minecraft.item.ItemHoe) EntityItem(net.minecraft.entity.item.EntityItem) Item(net.minecraft.item.Item) IBlockState(net.minecraft.block.state.IBlockState) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Block(net.minecraft.block.Block) 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