Search in sources :

Example 1 with EntityWallItem

use of net.tropicraft.core.common.entity.placeable.EntityWallItem 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 2 with EntityWallItem

use of net.tropicraft.core.common.entity.placeable.EntityWallItem 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)

Aggregations

EntityHanging (net.minecraft.entity.EntityHanging)2 ItemStack (net.minecraft.item.ItemStack)2 EntityWallItem (net.tropicraft.core.common.entity.placeable.EntityWallItem)2