Search in sources :

Example 51 with Level

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);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) Level(net.minecraft.world.level.Level) FluidState(net.minecraft.world.level.material.FluidState)

Example 52 with Level

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;
    }
}
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)

Example 53 with Level

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;
    }
}
Also used : WallItemEntity(net.tropicraft.core.common.entity.placeable.WallItemEntity) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) ItemStack(net.minecraft.world.item.ItemStack) Direction(net.minecraft.core.Direction)

Aggregations

Level (net.minecraft.world.level.Level)53 BlockPos (net.minecraft.core.BlockPos)26 ServerLevel (net.minecraft.server.level.ServerLevel)19 ItemStack (net.minecraft.world.item.ItemStack)14 BlockState (net.minecraft.world.level.block.state.BlockState)13 IOException (java.io.IOException)10 Direction (net.minecraft.core.Direction)8 ChunkPos (net.minecraft.world.level.ChunkPos)6 Path (java.nio.file.Path)5 ExecutionException (java.util.concurrent.ExecutionException)5 Nullable (javax.annotation.Nullable)5 Entity (net.minecraft.world.entity.Entity)5 Player (net.minecraft.world.entity.player.Player)5 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)5 LevelStem (net.minecraft.world.level.dimension.LevelStem)5 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)5 Map (java.util.Map)4 Set (java.util.Set)4 CompoundTag (net.minecraft.nbt.CompoundTag)4 ResourceLocation (net.minecraft.resources.ResourceLocation)4