Search in sources :

Example 71 with EnumHand

use of net.minecraft.util.EnumHand in project Tropicraft by Tropicraft.

the class TropicraftGuiHandler method getServerGuiElement.

@Override
public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
    if (id == 0) {
        EnumHand hand = EnumHand.values()[x];
        ItemStack held = player.getHeldItem(hand);
        if (held != null && held.getItem() instanceof ItemScubaChestplateGear) {
            return new ContainerScubaHarness(player.inventory, held.getCapability(ScubaCapabilities.getGearCapability(), null), hand);
        }
    }
    return null;
}
Also used : EnumHand(net.minecraft.util.EnumHand) ItemScubaChestplateGear(net.tropicraft.core.common.item.scuba.ItemScubaChestplateGear) ItemStack(net.minecraft.item.ItemStack)

Example 72 with EnumHand

use of net.minecraft.util.EnumHand in project SpongeForge by SpongePowered.

the class SpongeForgeEventFactory method createPlayerInteractEvent.

// Bulk Event Handling
private static InteractBlockEvent createPlayerInteractEvent(Event event) {
    InteractBlockEvent spongeEvent = (InteractBlockEvent) event;
    Player player = spongeEvent.getCause().first(Player.class).orElse(null);
    // Forge doesn't support left-click AIR
    if (player == null || (spongeEvent instanceof InteractBlockEvent.Primary && spongeEvent.getTargetBlock() == BlockSnapshot.NONE)) {
        return spongeEvent;
    }
    BlockPos pos = VecHelper.toBlockPos(spongeEvent.getTargetBlock().getPosition());
    EnumFacing face = DirectionFacingProvider.getInstance().get(spongeEvent.getTargetSide()).orElse(null);
    Vec3d hitVec = null;
    final EntityPlayerMP entityPlayerMP = EntityUtil.toNative(player);
    if (spongeEvent.getInteractionPoint().isPresent()) {
        hitVec = VecHelper.toVec3d(spongeEvent.getInteractionPoint().get());
    }
    if (spongeEvent instanceof InteractBlockEvent.Primary) {
        PlayerInteractEvent.LeftClickBlock forgeEvent = new PlayerInteractEvent.LeftClickBlock(entityPlayerMP, pos, face, hitVec);
        ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
        if (forgeEvent.isCanceled()) {
            spongeEvent.setCancelled(true);
        }
    } else if (face != null && spongeEvent instanceof InteractBlockEvent.Secondary) {
        EnumHand hand = spongeEvent instanceof InteractBlockEvent.Secondary.MainHand ? EnumHand.MAIN_HAND : EnumHand.OFF_HAND;
        PlayerInteractEvent.RightClickBlock forgeEvent = new PlayerInteractEvent.RightClickBlock(entityPlayerMP, hand, pos, face, hitVec);
        ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
        if (forgeEvent.isCanceled()) {
            spongeEvent.setCancelled(true);
        }
        // Mods have higher priority
        if (forgeEvent.getUseItem() != Result.DEFAULT) {
            ((InteractBlockEvent.Secondary) spongeEvent).setUseItemResult(getTristateFromResult(forgeEvent.getUseItem()));
        }
        if (forgeEvent.getUseBlock() != Result.DEFAULT) {
            ((InteractBlockEvent.Secondary) spongeEvent).setUseBlockResult(getTristateFromResult(forgeEvent.getUseBlock()));
        }
    }
    return spongeEvent;
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumFacing(net.minecraft.util.EnumFacing) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) Vec3d(net.minecraft.util.math.Vec3d) IMixinEventBus(org.spongepowered.mod.interfaces.IMixinEventBus) InteractBlockEvent(org.spongepowered.api.event.block.InteractBlockEvent) EnumHand(net.minecraft.util.EnumHand) BlockPos(net.minecraft.util.math.BlockPos) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 73 with EnumHand

use of net.minecraft.util.EnumHand in project ClaySoldiersMod by SanAndreasP.

the class ItemDisruptor method onItemRightClick.

@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand hand) {
    ItemStack itemStackIn = playerIn.getHeldItem(hand);
    NBTTagCompound nbt = itemStackIn.getOrCreateSubCompound("disruptor");
    long lastTimeMillis = nbt.getLong("lastActivated");
    long currTimeMillis = System.currentTimeMillis();
    if (lastTimeMillis + 2_000 < currTimeMillis) {
        if (!worldIn.isRemote) {
            AxisAlignedBB aabb = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 64.0D, 64.0D, 64.0D).offset(playerIn.posX, playerIn.posY, playerIn.posZ).offset(-32.0D, -32.0D, -32.0D);
            worldIn.getEntitiesWithinAABB(EntityCreature.class, aabb).stream().filter(entity -> entity instanceof IDisruptable).map(entity -> (IDisruptable) entity).collect(Collectors.toList()).forEach(IDisruptable::disrupt);
            nbt.setLong("lastActivated", currTimeMillis);
            if (itemStackIn.isItemStackDamageable()) {
                itemStackIn.damageItem(1, playerIn);
            }
        }
        return ActionResult.newResult(EnumActionResult.SUCCESS, itemStackIn);
    } else {
        return super.onItemRightClick(worldIn, playerIn, hand);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IItemPropertyGetter(net.minecraft.item.IItemPropertyGetter) Arrays(java.util.Arrays) Item(net.minecraft.item.Item) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Constants(net.minecraftforge.common.util.Constants) EnumHand(net.minecraft.util.EnumHand) ItemStack(net.minecraft.item.ItemStack) OreDictionary(net.minecraftforge.oredict.OreDictionary) CsmConstants(de.sanandrew.mods.claysoldiers.api.CsmConstants) CreativeTabs(net.minecraft.creativetab.CreativeTabs) NonNullList(net.minecraft.util.NonNullList) CsmCreativeTabs(de.sanandrew.mods.claysoldiers.util.CsmCreativeTabs) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) CsmConfiguration(de.sanandrew.mods.claysoldiers.util.CsmConfiguration) World(net.minecraft.world.World) Collectors(java.util.stream.Collectors) ActionResult(net.minecraft.util.ActionResult) ItemRegistry(de.sanandrew.mods.claysoldiers.registry.ItemRegistry) IDisruptable(de.sanandrew.mods.claysoldiers.api.IDisruptable) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EnumActionResult(net.minecraft.util.EnumActionResult) ResourceLocation(net.minecraft.util.ResourceLocation) EntityCreature(net.minecraft.entity.EntityCreature) Configuration(net.minecraftforge.common.config.Configuration) ItemStackUtils(de.sanandrew.mods.sanlib.lib.util.ItemStackUtils) IDisruptable(de.sanandrew.mods.claysoldiers.api.IDisruptable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) EntityCreature(net.minecraft.entity.EntityCreature)

Example 74 with EnumHand

use of net.minecraft.util.EnumHand in project Solar by ArekkuusuJerii.

the class BlockQelaion method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (world.isRemote)
        return true;
    ItemStack stack = player.getHeldItem(hand);
    if (stack.getItem() == ModItems.QELAION) {
        Optional<TileQelaion> optional = getTile(TileQelaion.class, world, pos);
        if (optional.isPresent()) {
            TileQelaion qelaion = optional.get();
            Optional<UUID> nodes = ((IEntangledStack) stack.getItem()).getKey(stack);
            Optional<UUID> parent = qelaion.getKey();
            if (nodes.isPresent() && parent.isPresent()) {
                qelaion.setNodes(nodes.get());
                return true;
            }
            return false;
        }
    } else if (stack.isEmpty()) {
        getTile(TileQelaion.class, world, pos).ifPresent(qelaion -> {
            if (!player.isSneaking()) {
                qelaion.put(facing);
            } else
                qelaion.setNodes(null);
        });
    }
    return false;
}
Also used : TileQelaion(arekkuusu.solar.common.block.tile.TileQelaion) DummyBakedRegistry(arekkuusu.solar.client.util.baker.DummyBakedRegistry) Item(net.minecraft.item.Item) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IEntangledStack(arekkuusu.solar.api.entanglement.IEntangledStack) EnumHand(net.minecraft.util.EnumHand) FXUtil(arekkuusu.solar.client.effect.FXUtil) LibNames(arekkuusu.solar.common.lib.LibNames) ModelHandler(arekkuusu.solar.client.util.helper.ModelHandler) BlockStateContainer(net.minecraft.block.state.BlockStateContainer) Random(java.util.Random) Quat(net.katsstuff.mirror.data.Quat) ItemStack(net.minecraft.item.ItemStack) BakedQelaion(arekkuusu.solar.client.util.baker.baked.BakedQelaion) NBTHelper(arekkuusu.solar.api.helper.NBTHelper) ModItems(arekkuusu.solar.common.item.ModItems) Side(net.minecraftforge.fml.relauncher.Side) NonNullList(net.minecraft.util.NonNullList) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) Light(arekkuusu.solar.client.effect.Light) IBlockAccess(net.minecraft.world.IBlockAccess) Nullable(javax.annotation.Nullable) Direction(arekkuusu.solar.api.state.Direction) World(net.minecraft.world.World) Vector3(net.katsstuff.mirror.data.Vector3) PropertyBool(net.minecraft.block.properties.PropertyBool) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) UUID(java.util.UUID) IBlockState(net.minecraft.block.state.IBlockState) MinecraftForge(net.minecraftforge.common.MinecraftForge) List(java.util.List) FixedMaterial(arekkuusu.solar.api.util.FixedMaterial) TileQelaion(arekkuusu.solar.common.block.tile.TileQelaion) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Optional(java.util.Optional) TileEntity(net.minecraft.tileentity.TileEntity) IEntangledStack(arekkuusu.solar.api.entanglement.IEntangledStack) ItemStack(net.minecraft.item.ItemStack) UUID(java.util.UUID)

Example 75 with EnumHand

use of net.minecraft.util.EnumHand in project ForestryMC by ForestryMC.

the class GuiHandler method getServerGuiElement.

@Override
@Nullable
public Object getServerGuiElement(int guiData, EntityPlayer player, World world, int x, int y, int z) {
    GuiId guiId = decodeGuiID(guiData);
    if (guiId == null) {
        return null;
    }
    short data = decodeGuiData(guiData);
    BlockPos pos = new BlockPos(x, y, z);
    switch(guiId.getGuiType()) {
        case Item:
            {
                for (EnumHand hand : EnumHand.values()) {
                    ItemStack heldItem = player.getHeldItem(hand);
                    if (!heldItem.isEmpty()) {
                        Item item = heldItem.getItem();
                        if (guiId.getGuiHandlerClass().isInstance(item)) {
                            return ((IGuiHandlerItem) item).getContainer(player, heldItem, data);
                        }
                    }
                }
                break;
            }
        case Tile:
            {
                TileEntity tileEntity = TileUtil.getTile(world, pos);
                if (guiId.getGuiHandlerClass().isInstance(tileEntity)) {
                    return ((IGuiHandlerTile) tileEntity).getContainer(player, data);
                }
                break;
            }
        case Entity:
            {
                Entity entity = world.getEntityByID(x);
                if (guiId.getGuiHandlerClass().isInstance(entity)) {
                    return ((IGuiHandlerEntity) entity).getContainer(player, data);
                }
                break;
            }
    }
    return null;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Item(net.minecraft.item.Item) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EnumHand(net.minecraft.util.EnumHand) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Nullable(javax.annotation.Nullable)

Aggregations

EnumHand (net.minecraft.util.EnumHand)117 ItemStack (net.minecraft.item.ItemStack)62 EntityPlayer (net.minecraft.entity.player.EntityPlayer)55 BlockPos (net.minecraft.util.math.BlockPos)45 EnumFacing (net.minecraft.util.EnumFacing)32 Vec3d (net.minecraft.util.math.Vec3d)24 World (net.minecraft.world.World)24 Entity (net.minecraft.entity.Entity)23 RayTraceResult (net.minecraft.util.math.RayTraceResult)21 EntityLivingBase (net.minecraft.entity.EntityLivingBase)19 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)19 Item (net.minecraft.item.Item)18 CPacketPlayerTryUseItemOnBlock (net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock)18 IBlockState (net.minecraft.block.state.IBlockState)17 TileEntity (net.minecraft.tileentity.TileEntity)16 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)15 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)14 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)13 List (java.util.List)12 Block (net.minecraft.block.Block)11