Search in sources :

Example 6 with EntityHanging

use of net.minecraft.entity.EntityHanging in project Tropicraft by Tropicraft.

the class ItemAshenMask method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (facing.getAxis().isVertical()) {
        return EnumActionResult.FAIL;
    } else {
        ItemStack stack = playerIn.getHeldItem(hand);
        // It's a wall, place the shell on it.
        pos = pos.offset(facing);
        // Must set the world coordinates here, or onValidSurface will be false.
        EntityHanging entityhanging = new EntityWallItem(worldIn, pos, facing, stack);
        if (!playerIn.canPlayerEdit(pos, facing, stack)) {
            return EnumActionResult.FAIL;
        } else {
            if (entityhanging != null && entityhanging.onValidSurface()) {
                if (!worldIn.isRemote) {
                    worldIn.spawnEntity(entityhanging);
                }
                stack.shrink(1);
            }
            return EnumActionResult.SUCCESS;
        }
    }
}
Also used : EntityWallItem(net.tropicraft.core.common.entity.placeable.EntityWallItem) EntityHanging(net.minecraft.entity.EntityHanging) ItemStack(net.minecraft.item.ItemStack)

Example 7 with EntityHanging

use of net.minecraft.entity.EntityHanging in project Tropicraft by Tropicraft.

the class ItemShell method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (facing.getAxis().isVertical()) {
        return EnumActionResult.FAIL;
    } else {
        // It's a wall, place the shell on it.
        ItemStack stack = playerIn.getHeldItem(hand);
        pos = pos.offset(facing);
        // Must set the world coordinates here, or onValidSurface will be false.
        EntityHanging entityhanging = new EntityWallItem(worldIn, pos, facing, stack);
        if (!playerIn.canPlayerEdit(pos, facing, stack)) {
            return EnumActionResult.FAIL;
        } else {
            if (entityhanging != null && entityhanging.onValidSurface()) {
                if (!worldIn.isRemote) {
                    worldIn.spawnEntity(entityhanging);
                }
                stack.shrink(1);
            }
            return EnumActionResult.SUCCESS;
        }
    }
}
Also used : EntityWallItem(net.tropicraft.core.common.entity.placeable.EntityWallItem) EntityHanging(net.minecraft.entity.EntityHanging) ItemStack(net.minecraft.item.ItemStack)

Example 8 with EntityHanging

use of net.minecraft.entity.EntityHanging in project Minestuck by mraof.

the class ItemHanging method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    BlockPos blockPos = pos.offset(facing);
    if (facing != EnumFacing.DOWN && facing != EnumFacing.UP && player.canPlayerEdit(blockPos, facing, stack)) {
        EntityHanging entityhanging = this.createEntity(worldIn, blockPos, facing, stack);
        if (entityhanging != null && entityhanging.onValidSurface()) {
            if (!worldIn.isRemote) {
                entityhanging.playPlaceSound();
                worldIn.spawnEntity(entityhanging);
            }
            stack.shrink(1);
        }
        return EnumActionResult.SUCCESS;
    } else {
        return EnumActionResult.FAIL;
    }
}
Also used : EntityHanging(net.minecraft.entity.EntityHanging) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Aggregations

EntityHanging (net.minecraft.entity.EntityHanging)8 BlockPos (net.minecraft.util.math.BlockPos)5 ItemStack (net.minecraft.item.ItemStack)4 Entity (net.minecraft.entity.Entity)2 Vec3d (net.minecraft.util.math.Vec3d)2 EntityWallItem (net.tropicraft.core.common.entity.placeable.EntityWallItem)2 SchematicEntity (buildcraft.api.blueprints.SchematicEntity)1 ItemBasicStructure (com.wuest.prefab.Items.Structures.ItemBasicStructure)1 BuildBlock (com.wuest.prefab.StructureGen.BuildBlock)1 BuildEntity (com.wuest.prefab.StructureGen.BuildEntity)1 BuildTileEntity (com.wuest.prefab.StructureGen.BuildTileEntity)1 Structure (com.wuest.prefab.StructureGen.Structure)1 ArrayList (java.util.ArrayList)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityItemFrame (net.minecraft.entity.item.EntityItemFrame)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 SPacketUpdateTileEntity (net.minecraft.network.play.server.SPacketUpdateTileEntity)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1