Search in sources :

Example 1 with BambooItemFrame

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;
    }
}
Also used : HangingEntity(net.minecraft.world.entity.decoration.HangingEntity) Player(net.minecraft.world.entity.player.Player) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction) BambooItemFrame(net.tropicraft.core.common.entity.BambooItemFrame) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 HangingEntity (net.minecraft.world.entity.decoration.HangingEntity)1 Player (net.minecraft.world.entity.player.Player)1 ItemStack (net.minecraft.world.item.ItemStack)1 Level (net.minecraft.world.level.Level)1 BambooItemFrame (net.tropicraft.core.common.entity.BambooItemFrame)1