use of net.tropicraft.core.common.entity.placeable.WallItemEntity in project Tropicraft by Tropicraft.
the class AshenMaskItem method useOn.
/**
* Called when this item is used when targetting a Block
*/
@Override
public InteractionResult useOn(UseOnContext context) {
BlockPos pos = context.getClickedPos();
Direction direction = context.getClickedFace();
BlockPos offsetPos = pos.relative(direction);
Player player = context.getPlayer();
ItemStack itemStack = context.getItemInHand();
if (player != null && !this.canPlace(player, direction, itemStack, offsetPos)) {
return InteractionResult.FAIL;
} else {
Level world = context.getLevel();
WallItemEntity wallItem = new WallItemEntity(world, offsetPos, direction);
wallItem.setItem(itemStack);
if (wallItem.survives()) {
if (!world.isClientSide) {
wallItem.playPlacementSound();
world.addFreshEntity(wallItem);
}
itemStack.shrink(1);
}
return InteractionResult.SUCCESS;
}
}
use of net.tropicraft.core.common.entity.placeable.WallItemEntity in project Tropicraft by Tropicraft.
the class ShellItem method useOn.
@Override
public InteractionResult useOn(final UseOnContext context) {
final Direction facing = context.getClickedFace();
final ItemStack stack = context.getPlayer().getItemInHand(context.getHand());
final BlockPos pos = context.getClickedPos().relative(facing);
// Must set the world coordinates here, or onValidSurface will be false.
final Level world = context.getLevel();
final WallItemEntity hangingEntity = new WallItemEntity(world, pos, facing);
hangingEntity.setItem(stack);
if (!context.getPlayer().mayUseItemAt(pos, facing, stack)) {
return InteractionResult.FAIL;
} else {
if (hangingEntity.survives()) {
if (!world.isClientSide) {
world.addFreshEntity(hangingEntity);
}
stack.shrink(1);
}
return InteractionResult.SUCCESS;
}
}
Aggregations