Search in sources :

Example 1 with TileEntityDropper

use of net.minecraft.tileentity.TileEntityDropper 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

TileEntity (net.minecraft.tileentity.TileEntity)1 TileEntityChest (net.minecraft.tileentity.TileEntityChest)1 TileEntityDropper (net.minecraft.tileentity.TileEntityDropper)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1