use of net.minecraft.world.level.Level in project Tropicraft by Tropicraft.
the class ReedsBlock method getStateForPlacement.
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
Level world = context.getLevel();
FluidState fluid = world.getFluidState(context.getClickedPos());
return this.defaultBlockState().setValue(TYPE, this.getAppropriateTypeAt(world, context.getClickedPos())).setValue(WATERLOGGED, fluid.getType() == Fluids.WATER);
}
use of net.minecraft.world.level.Level 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;
}
}
use of net.minecraft.world.level.Level 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