Search in sources :

Example 1 with EntityPoolMinecart

use of vazkii.botania.common.entity.EntityPoolMinecart in project Botania by VazkiiMods.

the class BehaviourPoolMinecart method execute.

@Nonnull
@Override
public ItemStack execute(BlockSource source, ItemStack stack) {
    Direction enumfacing = source.getBlockState().getValue(DispenserBlock.FACING);
    Level world = source.getLevel();
    double d0 = source.x() + (double) enumfacing.getStepX() * 1.125D;
    double d1 = Math.floor(source.y()) + (double) enumfacing.getStepY();
    double d2 = source.z() + (double) enumfacing.getStepZ() * 1.125D;
    BlockPos blockpos = source.getPos().relative(enumfacing);
    BlockState iblockstate = world.getBlockState(blockpos);
    RailShape railshape = iblockstate.getBlock() instanceof BaseRailBlock ? iblockstate.getValue(((BaseRailBlock) iblockstate.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH;
    double d3;
    if (iblockstate.is(BlockTags.RAILS)) {
        if (railshape.isAscending()) {
            d3 = 0.6D;
        } else {
            d3 = 0.1D;
        }
    } else {
        if (!iblockstate.isAir() || !world.getBlockState(blockpos.below()).is(BlockTags.RAILS)) {
            return this.behaviourDefaultDispenseItem.dispense(source, stack);
        }
        BlockState iblockstate1 = world.getBlockState(blockpos.below());
        RailShape railshape1 = iblockstate1.getBlock() instanceof BaseRailBlock ? iblockstate1.getValue(((BaseRailBlock) iblockstate1.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH;
        if (enumfacing != Direction.DOWN && railshape1.isAscending()) {
            d3 = -0.4D;
        } else {
            d3 = -0.9D;
        }
    }
    AbstractMinecart entityminecart = new EntityPoolMinecart(world, d0, d1 + d3, d2);
    if (stack.hasCustomHoverName()) {
        entityminecart.setCustomName(stack.getHoverName());
    }
    world.addFreshEntity(entityminecart);
    stack.shrink(1);
    return stack;
}
Also used : EntityPoolMinecart(vazkii.botania.common.entity.EntityPoolMinecart) BlockState(net.minecraft.world.level.block.state.BlockState) BaseRailBlock(net.minecraft.world.level.block.BaseRailBlock) AbstractMinecart(net.minecraft.world.entity.vehicle.AbstractMinecart) RailShape(net.minecraft.world.level.block.state.properties.RailShape) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) Nonnull(javax.annotation.Nonnull)

Example 2 with EntityPoolMinecart

use of vazkii.botania.common.entity.EntityPoolMinecart in project Botania by VazkiiMods.

the class ItemPoolMinecart method useOn.

// [VanillaCopy] MinecartItem
@Nonnull
@Override
public InteractionResult useOn(UseOnContext context) {
    Level world = context.getLevel();
    BlockPos blockPos = context.getClickedPos();
    BlockState blockState = world.getBlockState(blockPos);
    if (!blockState.is(BlockTags.RAILS)) {
        return InteractionResult.FAIL;
    } else {
        ItemStack itemStack = context.getItemInHand();
        if (!world.isClientSide) {
            RailShape railShape = blockState.getBlock() instanceof BaseRailBlock ? blockState.getValue(((BaseRailBlock) blockState.getBlock()).getShapeProperty()) : RailShape.NORTH_SOUTH;
            double d = 0.0D;
            if (railShape.isAscending()) {
                d = 0.5D;
            }
            AbstractMinecart abstractMinecartEntity = new EntityPoolMinecart(world, (double) blockPos.getX() + 0.5D, (double) blockPos.getY() + 0.0625D + d, (double) blockPos.getZ() + 0.5D);
            if (itemStack.hasCustomHoverName()) {
                abstractMinecartEntity.setCustomName(itemStack.getHoverName());
            }
            world.addFreshEntity(abstractMinecartEntity);
        }
        itemStack.shrink(1);
        return InteractionResult.sidedSuccess(world.isClientSide);
    }
}
Also used : EntityPoolMinecart(vazkii.botania.common.entity.EntityPoolMinecart) BlockState(net.minecraft.world.level.block.state.BlockState) BaseRailBlock(net.minecraft.world.level.block.BaseRailBlock) AbstractMinecart(net.minecraft.world.entity.vehicle.AbstractMinecart) RailShape(net.minecraft.world.level.block.state.properties.RailShape) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)2 BlockPos (net.minecraft.core.BlockPos)2 AbstractMinecart (net.minecraft.world.entity.vehicle.AbstractMinecart)2 Level (net.minecraft.world.level.Level)2 BaseRailBlock (net.minecraft.world.level.block.BaseRailBlock)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 RailShape (net.minecraft.world.level.block.state.properties.RailShape)2 EntityPoolMinecart (vazkii.botania.common.entity.EntityPoolMinecart)2 Direction (net.minecraft.core.Direction)1 ItemStack (net.minecraft.world.item.ItemStack)1