use of net.tropicraft.core.common.entity.BambooItemFrame in project Tropicraft by Tropicraft.
the class BambooItemFrameItem method useOn.
@Override
public InteractionResult useOn(UseOnContext context) {
BlockPos blockpos = context.getClickedPos();
Direction direction = context.getClickedFace();
BlockPos blockpos1 = blockpos.relative(direction);
Player playerentity = context.getPlayer();
ItemStack itemstack = context.getItemInHand();
if (playerentity != null && !this.mayPlace(playerentity, direction, itemstack, blockpos1)) {
return InteractionResult.FAIL;
} else {
Level world = context.getLevel();
HangingEntity hangingentity = new BambooItemFrame(world, blockpos1, direction);
CompoundTag compoundnbt = itemstack.getTag();
if (compoundnbt != null) {
EntityType.updateCustomEntityTag(world, playerentity, hangingentity, compoundnbt);
}
if (hangingentity.survives()) {
if (!world.isClientSide) {
hangingentity.playPlacementSound();
world.addFreshEntity(hangingentity);
}
itemstack.shrink(1);
}
return InteractionResult.SUCCESS;
}
}
Aggregations