Search in sources :

Example 16 with BlockState

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

the class ItemChannelValve method onItemUse.

@Nonnull
@Override
public ActionResultType onItemUse(@Nonnull ItemUseContext context) {
    World world = context.getWorld();
    BlockPos pos = context.getPos();
    BlockState state = world.getBlockState(context.getPos());
    if (state.getBlock() instanceof BlockIrrigationChannelAbstract) {
        if (!BlockIrrigationChannelAbstract.VALVE.fetch(state).hasValve()) {
            world.setBlockState(pos, BlockIrrigationChannelAbstract.VALVE.apply(state, BlockIrrigationChannelAbstract.Valve.OPEN));
            if (world.isRemote()) {
                TileEntity tile = world.getTileEntity(pos);
                if (tile instanceof TileEntityIrrigationChannel) {
                    ((TileEntityIrrigationChannel) tile).setValveState(TileEntityIrrigationChannel.ValveState.OPEN);
                }
            }
            if (context.getPlayer() != null && !context.getPlayer().isCreative()) {
                context.getPlayer().getHeldItem(context.getHand()).shrink(1);
            }
            return ActionResultType.SUCCESS;
        }
    }
    return super.onItemUse(context);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Nonnull(javax.annotation.Nonnull)

Example 17 with BlockState

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

the class TileEntitySeedAnalyzer method calculateObserverPosition.

protected Vector3d calculateObserverPosition(double fov) {
    // calculate offset from the center of the looking glass based on fov
    double d = 0.75 * (0.5 / Math.tan(Math.PI * fov / 360));
    double dy = d * MathHelper.sin((float) Math.PI * 67.5F / 180);
    double dx = d * MathHelper.cos((float) Math.PI * 67.5F / 180);
    // fetch orientation, to determine the center of the looking glass
    BlockState state = this.getBlockState();
    Direction dir = BlockSeedAnalyzer.ORIENTATION.fetch(state);
    // apply observer position (center of looking glass + fov offset)
    return this.observerPosition = new Vector3d(this.getPos().getX() + 0.5 + (dx + 0.3125) * dir.getXOffset(), this.getPos().getY() + 0.6875 + dy, this.getPos().getZ() + 0.5 + (dx + 0.3125) * dir.getZOffset());
}
Also used : BlockState(net.minecraft.block.BlockState) Vector3d(net.minecraft.util.math.vector.Vector3d) Direction(net.minecraft.util.Direction)

Example 18 with BlockState

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

the class TileEntitySeedAnalyzerSeedRenderer method renderGenome.

protected void renderGenome(TileEntitySeedAnalyzer tile, float partialTick, MatrixStack transforms, IRenderTypeBuffer buffer) {
    // fetch genes
    List<IAgriGenePair<?>> genes = tile.getGenesToRender();
    if (genes == null) {
        // should never be possible
        return;
    }
    // push a new matrix to the stack
    transforms.push();
    // fetch helpers
    SeedAnalyzerViewPointHandler viewHandler = SeedAnalyzerViewPointHandler.getInstance();
    AgriGenomeRenderer renderer = AgriGenomeRenderer.getInstance();
    // fetch scroll position
    int index = viewHandler.getScrollIndex();
    float partial = viewHandler.getPartialScrollProgress(partialTick);
    // fetch orientation
    BlockState state = tile.getBlockState();
    Direction dir = BlockSeedAnalyzer.ORIENTATION.fetch(state);
    // helix dimensions
    float h = Constants.HALF;
    float r = h / 10;
    // transform to the desired position
    float dx = Constants.HALF + Constants.UNIT * dir.getXOffset();
    float dy = 5 * Constants.UNIT;
    float dz = Constants.HALF + Constants.UNIT * dir.getZOffset();
    transforms.translate(dx, dy, dz);
    transforms.rotate(new Quaternion(Vector3f.YP, tile.getHorizontalAngle(), true));
    // render the helix
    renderer.renderDoubleHelix(genes, transforms, buffer, index, partial, r, h, 1.0F, false);
    // render the text
    if (index >= 0 && index < genes.size()) {
        transforms.push();
        transforms.translate(0, 0, -3 * Constants.UNIT);
        transforms.rotate(TEXT_ROTATION);
        float scale = 2.0F / Math.max(this.getScaledWindowWidth(), this.getScaledWindowHeight());
        transforms.scale(scale, scale, 1);
        renderer.renderTextOverlay(transforms, genes.get(index));
        transforms.pop();
    }
    // pop the matrix off the stack
    transforms.pop();
}
Also used : IAgriGenePair(com.infinityraider.agricraft.api.v1.genetics.IAgriGenePair) BlockState(net.minecraft.block.BlockState) Quaternion(net.minecraft.util.math.vector.Quaternion) SeedAnalyzerViewPointHandler(com.infinityraider.agricraft.handler.SeedAnalyzerViewPointHandler) Direction(net.minecraft.util.Direction) AgriGenomeRenderer(com.infinityraider.agricraft.render.plant.AgriGenomeRenderer)

Example 19 with BlockState

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

the class GreenHouseHandler method checkAndFormGreenHouse.

public void checkAndFormGreenHouse(World world, BlockPos pos) {
    BlockState state = world.getBlockState(pos);
    if (!state.getBlock().isAir(state, world, pos)) {
        return;
    }
    new GreenHouseFormer(world, pos).getGreenHouse().ifPresent(greenHouse -> {
        if (greenHouse.isValid()) {
            CapabilityGreenHouseData.getInstance().addGreenHouse(world, greenHouse);
            greenHouse.convertAirBlocks(world);
        }
    });
}
Also used : BlockState(net.minecraft.block.BlockState)

Example 20 with BlockState

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

the class VanillaSeedConversionHandler method runPlantingConversion.

protected boolean runPlantingConversion(World world, BlockPos pos, ItemStack stack, PlayerEntity player, Hand hand) {
    return !AgriCraft.instance.getConfig().convertSeedsOnlyInAnalyzer() && AgriApi.getGenomeAdapterizer().valueOf(stack).map(seed -> {
        // The player is attempting to plant a seed, convert it to an agricraft crop
        return AgriApi.getSoil(world, pos.down()).map(soil -> {
            // check if there are crop sticks above
            MutableBoolean consumed = new MutableBoolean(false);
            boolean cropSticks = AgriApi.getCrop(world, pos).map(crop -> {
                if (!crop.hasPlant() && !crop.isCrossCrop() && crop.plantGenome(seed, player)) {
                    if (player == null || !player.isCreative()) {
                        stack.shrink(1);
                        consumed.setValue(true);
                    }
                    if (player != null) {
                        player.swingArm(hand);
                    }
                }
                return true;
            }).orElse(false);
            // if there were crop sticks, return the result of the crop sticks action
            if (cropSticks) {
                return consumed.getValue();
            }
            // no crop sticks, try planting as a plant
            BlockState newState = AgriCraft.instance.getModBlockRegistry().crop_plant.getStateForPlacement(world, pos);
            if (newState != null && world.setBlockState(pos, newState, 11)) {
                boolean planted = AgriApi.getCrop(world, pos).map(crop -> crop.plantGenome(seed, player)).orElse(false);
                if (planted) {
                    // reduce stack size
                    if (player == null || !player.isCreative()) {
                        stack.shrink(1);
                    }
                    // return success
                    return true;
                } else {
                    world.setBlockState(pos, Blocks.AIR.getDefaultState());
                }
            }
            return false;
        }).orElse(false);
    }).orElse(false);
}
Also used : AgriCraft(com.infinityraider.agricraft.AgriCraft) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) Item(net.minecraft.item.Item) World(net.minecraft.world.World) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) Sets(com.google.common.collect.Sets) Blocks(net.minecraft.block.Blocks) ItemStack(net.minecraft.item.ItemStack) TileEntitySeedAnalyzer(com.infinityraider.agricraft.content.core.TileEntitySeedAnalyzer) EventPriority(net.minecraftforge.eventbus.api.EventPriority) Event(net.minecraftforge.eventbus.api.Event) TileEntity(net.minecraft.tileentity.TileEntity) Hand(net.minecraft.util.Hand) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) BlockState(net.minecraft.block.BlockState) PlayerInteractEvent(net.minecraftforge.event.entity.player.PlayerInteractEvent) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) IAgriSeedItem(com.infinityraider.agricraft.api.v1.content.items.IAgriSeedItem) BlockState(net.minecraft.block.BlockState) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean)

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