Search in sources :

Example 11 with BlockState

use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.

the class TileEntitySeedAnalyzer method getObserverOrientation.

@Override
public Vector2f getObserverOrientation() {
    if (this.observerOrientation == null) {
        BlockState state = this.getBlockState();
        Direction dir = BlockSeedAnalyzer.ORIENTATION.fetch(state);
        // The analyzer looking glass is tilted 22.5 degrees, therefore we have to pitch down 67.5 degrees
        this.observerOrientation = new Vector2f(67.5F, dir.getOpposite().getHorizontalAngle());
    }
    return this.observerOrientation;
}
Also used : BlockState(net.minecraft.block.BlockState) Vector2f(net.minecraft.util.math.vector.Vector2f) Direction(net.minecraft.util.Direction)

Example 12 with BlockState

use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.

the class BlockIrrigationChannelAbstract method getStateForPlacement.

@Nullable
@Override
public BlockState getStateForPlacement(BlockItemUseContext context) {
    World world = context.getWorld();
    BlockPos pos = context.getPos();
    BlockState state = this.getDefaultState();
    for (Direction dir : Direction.values()) {
        Optional<InfProperty<Boolean>> prop = getConnection(dir);
        if (prop.isPresent()) {
            TileEntity tile = world.getTileEntity(pos.offset(dir));
            if (tile instanceof TileEntityIrrigationComponent) {
                TileEntityIrrigationComponent component = (TileEntityIrrigationComponent) tile;
                if (component.isSameMaterial(context.getItem())) {
                    state = prop.get().apply(state, true);
                }
            }
        }
    }
    return state;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) InfProperty(com.infinityraider.infinitylib.block.property.InfProperty) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) IWorld(net.minecraft.world.IWorld) Direction(net.minecraft.util.Direction) Nullable(javax.annotation.Nullable)

Example 13 with BlockState

use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.

the class ItemCropSticks method placeCropSticksOnSoil.

protected ActionResultType placeCropSticksOnSoil(World world, BlockPos pos, BlockItemUseContext context) {
    // Test if the placement is valid
    BlockState newState = this.getVariant().getBlock().getStateForPlacement(context);
    if (newState == null) {
        return ActionResultType.FAIL;
    }
    // Set the block to a crop.
    final boolean success = world.setBlockState(pos, newState);
    // If there was trouble, abort.
    if (!success) {
        AgriCore.getCoreLogger().debug("ItemCrop#onItemUse failed to create the BlockCrop!");
        return ActionResultType.FAIL;
    }
    // Remove the crop used from the stack.
    this.consumeItem(context.getPlayer(), context.getHand());
    // Play placement sound.
    CropHelper.playPlantingSound(world, pos, context.getPlayer());
    // Action was a success.
    return ActionResultType.SUCCESS;
}
Also used : BlockState(net.minecraft.block.BlockState)

Example 14 with BlockState

use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.

the class ItemCropSticks method placeCropSticksOnPlant.

protected ActionResultType placeCropSticksOnPlant(World world, BlockPos pos, @Nullable PlayerEntity player, Hand hand, TileEntityCropPlant plant, BlockState state) {
    // Attempt to convert to crop sticks
    BlockState newState = this.getVariant().getBlock().getDefaultState();
    newState = BlockCropBase.PLANT.mimic(state, newState);
    newState = BlockCropBase.LIGHT.mimic(state, newState);
    newState = InfProperty.Defaults.fluidlogged().mimic(state, newState);
    world.setBlockState(pos, newState);
    // If there was trouble, reset and abort.
    TileEntity tile = world.getTileEntity(pos);
    if (!(tile instanceof TileEntityCropSticks)) {
        world.setBlockState(pos, state);
        return ActionResultType.FAIL;
    }
    // Mimic plant and weed
    ((TileEntityCropSticks) tile).mimicFrom(plant);
    // Remove the crop used from the stack
    this.consumeItem(player, hand);
    // Play placement sound.
    CropHelper.playPlantingSound(world, pos, player);
    // Action was a success.
    return ActionResultType.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState)

Example 15 with BlockState

use of net.minecraft.block.BlockState in project AgriCraft by AgriCraft.

the class ItemCropSticks method onItemUse.

@Nonnull
@Override
@SuppressWarnings("deprecation")
public ActionResultType onItemUse(@Nonnull ItemUseContext context) {
    // Fetch target world, pos, tile, and state
    World world = context.getWorld();
    BlockPos pos = context.getPos();
    TileEntity tile = world.getTileEntity(pos);
    BlockState state = world.getBlockState(pos);
    // Try placing on same block
    if (tile instanceof TileEntityCropPlant) {
        // Place on existing plant
        return this.placeCropSticksOnPlant(world, pos, context.getPlayer(), context.getHand(), (TileEntityCropPlant) tile, state);
    } else if (tile instanceof TileEntityCropSticks) {
        // Make cross crop
        return this.tryMakeCrossCrop(world, pos, context.getPlayer(), context.getHand(), (TileEntityCropSticks) tile);
    }
    // Fetch pos, tile, and state above
    pos = pos.offset(context.getFace());
    tile = world.getTileEntity(pos);
    state = world.getBlockState(pos);
    if (state.isAir(world, pos) || state.getFluidState().getFluid() == Fluids.WATER) {
        // Place on soil
        return this.placeCropSticksOnSoil(world, pos, new BlockItemUseContext(context));
    } else if (tile instanceof TileEntityCropPlant) {
        // Place on existing plant
        return this.placeCropSticksOnPlant(world, pos, context.getPlayer(), context.getHand(), (TileEntityCropPlant) tile, state);
    } else if (tile instanceof TileEntityCropSticks) {
        // Make cross crop
        return this.tryMakeCrossCrop(world, pos, context.getPlayer(), context.getHand(), (TileEntityCropSticks) tile);
    }
    return ActionResultType.FAIL;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockItemUseContext(net.minecraft.item.BlockItemUseContext) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Nonnull(javax.annotation.Nonnull)

Aggregations

BlockState (net.minecraft.block.BlockState)79 BlockPos (net.minecraft.util.math.BlockPos)32 TileEntity (net.minecraft.tileentity.TileEntity)19 Direction (net.minecraft.util.Direction)16 Nonnull (javax.annotation.Nonnull)12 CompoundNBT (net.minecraft.nbt.CompoundNBT)12 World (net.minecraft.world.World)12 ChunkPos (net.minecraft.util.math.ChunkPos)11 Block (net.minecraft.block.Block)10 Nullable (javax.annotation.Nullable)9 PlayerEntity (net.minecraft.entity.player.PlayerEntity)9 ItemStack (net.minecraft.item.ItemStack)9 HashSet (java.util.HashSet)4 Blocks (net.minecraft.block.Blocks)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 ServerWorld (net.minecraft.world.server.ServerWorld)4 IForgeBlockState (net.minecraftforge.common.extensions.IForgeBlockState)4 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)3 AgriCraft (com.infinityraider.agricraft.AgriCraft)3 BlockRayTraceResult (net.minecraft.util.math.BlockRayTraceResult)3