Search in sources :

Example 1 with SubscribeEvent

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

the class CommandForWheeledRobotNavigationImplementation method onRenderTick.

/** Called for each screen redraw - approximately three times as often as the other tick events, 
     * under normal conditions.<br>
     * This is where we want to update our yaw/pitch, in order to get smooth panning etc
     * (which is how Minecraft itself does it).
     * The speed of the render ticks is not guaranteed, and can vary from machine to machine, so
     * we try to account for this in the calculations.
     * @param ev the RenderTickEvent object for this tick
     */
@SubscribeEvent
public void onRenderTick(TickEvent.RenderTickEvent ev) {
    if (ev.phase == Phase.START) {
        if (this.isOverriding()) {
            EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
            if (player != null) {
                updateYawAndPitch();
                player.rotationPitch = this.mCameraPitch;
                player.rotationYaw = this.mYaw;
            }
        }
    }
}
Also used : EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with SubscribeEvent

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

the class UniversalBucket method onFillBucket.

// low priority so other mods can handle their stuff first
@SubscribeEvent(priority = EventPriority.LOW)
public void onFillBucket(FillBucketEvent event) {
    if (event.getResult() != Event.Result.DEFAULT) {
        // event was already handled
        return;
    }
    // not for us to handle
    ItemStack emptyBucket = event.getEmptyBucket();
    if (emptyBucket.isEmpty() || !emptyBucket.isItemEqual(getEmpty()) || (isNbtSensitive() && ItemStack.areItemStackTagsEqual(emptyBucket, getEmpty()))) {
        return;
    }
    // needs to target a block
    RayTraceResult target = event.getTarget();
    if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK) {
        return;
    }
    World world = event.getWorld();
    BlockPos pos = target.getBlockPos();
    ItemStack singleBucket = emptyBucket.copy();
    singleBucket.setCount(1);
    FluidActionResult filledResult = FluidUtil.tryPickUpFluid(singleBucket, event.getEntityPlayer(), world, pos, target.sideHit);
    if (filledResult.isSuccess()) {
        event.setResult(Event.Result.ALLOW);
        event.setFilledBucket(filledResult.getResult());
    } else {
        // cancel event, otherwise the vanilla minecraft ItemBucket would
        // convert it into a water/lava bucket depending on the blocks material
        event.setCanceled(true);
    }
}
Also used : RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with SubscribeEvent

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

the class DynBucketTest method onBucketFill.

@SubscribeEvent
public void onBucketFill(FillBucketEvent event) {
    RayTraceResult target = event.getTarget();
    if (target != null) {
        IBlockState state = event.getWorld().getBlockState(target.getBlockPos());
        if (state.getBlock() instanceof IFluidBlock) {
            Fluid fluid = ((IFluidBlock) state.getBlock()).getFluid();
            FluidStack fs = new FluidStack(fluid, Fluid.BUCKET_VOLUME);
            ItemStack bucket = event.getEmptyBucket();
            IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(bucket);
            if (fluidHandler != null) {
                int fillAmount = fluidHandler.fill(fs, true);
                if (fillAmount > 0) {
                    ItemStack filledBucket = fluidHandler.getContainer();
                    event.setFilledBucket(filledBucket);
                    event.setResult(Result.ALLOW);
                }
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidHandlerItem(net.minecraftforge.fluids.capability.IFluidHandlerItem) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) Fluid(net.minecraftforge.fluids.Fluid) TestFluid(net.minecraftforge.debug.ModelFluidDebug.TestFluid) RayTraceResult(net.minecraft.util.math.RayTraceResult) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with SubscribeEvent

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

the class LootTablesDebug method lootLoad.

@SubscribeEvent
public void lootLoad(LootTableLoadEvent event) {
    if (!event.getName().equals(LootTableList.CHESTS_SPAWN_BONUS_CHEST))
        return;
    // Remove axes and replace with chestpeice, First vanilla entry is always called "main"
    //Note: This CAN NPE if another mod removes things
    LootPool main = event.getTable().getPool("main");
    main.removeEntry("minecraft:wooden_axe");
    main.removeEntry("minecraft:stone_axe");
    main.addEntry(new LootEntryItem(Items.DIAMOND_CHESTPLATE, 1, 0, new LootFunction[0], new LootCondition[0], MODID + ":diamond_chestplate"));
    // Get rid of all building mats. Which is pool #3, index starts at 0, but 0 is named "main"
    event.getTable().removePool("pool3");
}
Also used : LootEntryItem(net.minecraft.world.storage.loot.LootEntryItem) LootFunction(net.minecraft.world.storage.loot.functions.LootFunction) LootPool(net.minecraft.world.storage.loot.LootPool) LootCondition(net.minecraft.world.storage.loot.conditions.LootCondition) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with SubscribeEvent

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

the class PlayerInteractEventTest method rightClickBlock.

@SubscribeEvent
public void rightClickBlock(PlayerInteractEvent.RightClickBlock evt) {
    if (!ENABLE)
        return;
    logger.info("HIT VEC: {}", evt.getHitVec());
    // Shift right clicking dropper with an item in hand should still open the dropper contrary to normal mechanics
    // The item in hand is used as well (not specifying anything would not use the item)
    TileEntity te = evt.getWorld().getTileEntity(evt.getPos());
    if (te instanceof TileEntityDropper) {
        evt.setUseBlock(Event.Result.ALLOW);
        evt.setUseItem(Event.Result.ALLOW);
    }
    // Same as above, except the item should no longer be used
    if (te instanceof TileEntityChest) {
        evt.setUseBlock(Event.Result.ALLOW);
        // could be left out as well
        evt.setUseItem(Event.Result.DENY);
    }
    // If you dual wield flints and steels and right click a chest nothing should happen
    if (evt.getItemStack() != null && evt.getItemStack().getItem() == Items.FLINT_AND_STEEL)
        evt.setUseBlock(Event.Result.DENY);
    // Opening a TE will also place a painting on the TE if possible
    if (evt.getHand() == EnumHand.MAIN_HAND && evt.getItemStack() != null && evt.getItemStack().getItem() == Items.PAINTING) {
        evt.setUseItem(Event.Result.ALLOW);
    }
    // Sword in main hand, spawn egg in offhand -> nothing should happen
    if (evt.getItemStack() != null && evt.getItemStack().getItem() == Items.SPAWN_EGG) {
        evt.setCanceled(true);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityChest(net.minecraft.tileentity.TileEntityChest) TileEntityDropper(net.minecraft.tileentity.TileEntityDropper) 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