Search in sources :

Example 6 with RailShape

use of net.minecraft.world.level.block.state.properties.RailShape in project Create by Creators-of-Create.

the class CartAssemblerBlockItem method tryPlaceAssembler.

public boolean tryPlaceAssembler(UseOnContext context) {
    BlockPos pos = context.getClickedPos();
    Level world = context.getLevel();
    BlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    Player player = context.getPlayer();
    if (player == null)
        return false;
    if (!(block instanceof BaseRailBlock)) {
        Lang.sendStatus(player, "block.cart_assembler.invalid");
        return false;
    }
    RailShape shape = ((BaseRailBlock) block).getRailDirection(state, world, pos, null);
    if (shape != RailShape.EAST_WEST && shape != RailShape.NORTH_SOUTH)
        return false;
    BlockState newState = AllBlocks.CART_ASSEMBLER.getDefaultState().setValue(CartAssemblerBlock.RAIL_SHAPE, shape);
    CartAssembleRailType newType = null;
    for (CartAssembleRailType type : CartAssembleRailType.values()) if (type.matches(state))
        newType = type;
    if (newType == null)
        return false;
    if (world.isClientSide)
        return true;
    newState = newState.setValue(CartAssemblerBlock.RAIL_TYPE, newType);
    if (state.hasProperty(ControllerRailBlock.BACKWARDS))
        newState = newState.setValue(CartAssemblerBlock.BACKWARDS, state.getValue(ControllerRailBlock.BACKWARDS));
    else {
        Direction direction = player.getMotionDirection();
        newState = newState.setValue(CartAssemblerBlock.BACKWARDS, direction.getAxisDirection() == AxisDirection.POSITIVE);
    }
    world.setBlockAndUpdate(pos, newState);
    if (!player.isCreative())
        context.getItemInHand().shrink(1);
    return true;
}
Also used : Player(net.minecraft.world.entity.player.Player) BlockState(net.minecraft.world.level.block.state.BlockState) BaseRailBlock(net.minecraft.world.level.block.BaseRailBlock) RailShape(net.minecraft.world.level.block.state.properties.RailShape) BaseRailBlock(net.minecraft.world.level.block.BaseRailBlock) ControllerRailBlock(com.simibubi.create.content.contraptions.components.tracks.ControllerRailBlock) Block(net.minecraft.world.level.block.Block) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) Direction(net.minecraft.core.Direction) AxisDirection(net.minecraft.core.Direction.AxisDirection)

Example 7 with RailShape

use of net.minecraft.world.level.block.state.properties.RailShape in project Create by Creators-of-Create.

the class MinecartContraptionItem method useOn.

// Taken and adjusted from MinecartItem
@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 ? ((BaseRailBlock) blockstate.getBlock()).getRailDirection(blockstate, world, blockpos, null) : RailShape.NORTH_SOUTH;
            double d0 = 0.0D;
            if (railshape.isAscending()) {
                d0 = 0.5D;
            }
            AbstractMinecart abstractminecartentity = AbstractMinecart.createMinecart(world, (double) blockpos.getX() + 0.5D, (double) blockpos.getY() + 0.0625D + d0, (double) blockpos.getZ() + 0.5D, this.minecartType);
            if (itemstack.hasCustomHoverName())
                abstractminecartentity.setCustomName(itemstack.getHoverName());
            Player player = context.getPlayer();
            world.addFreshEntity(abstractminecartentity);
            addContraptionToMinecart(world, itemstack, abstractminecartentity, player == null ? null : player.getDirection());
        }
        itemstack.shrink(1);
        return InteractionResult.SUCCESS;
    }
}
Also used : Player(net.minecraft.world.entity.player.Player) 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)

Example 8 with RailShape

use of net.minecraft.world.level.block.state.properties.RailShape in project Create by Creators-of-Create.

the class BlockStateGen method cartAssembler.

public static NonNullBiConsumer<DataGenContext<Block, CartAssemblerBlock>, RegistrateBlockstateProvider> cartAssembler() {
    return (c, p) -> p.getVariantBuilder(c.get()).forAllStates(state -> {
        CartAssembleRailType type = state.getValue(CartAssemblerBlock.RAIL_TYPE);
        Boolean powered = state.getValue(CartAssemblerBlock.POWERED);
        Boolean backwards = state.getValue(CartAssemblerBlock.BACKWARDS);
        RailShape shape = state.getValue(CartAssemblerBlock.RAIL_SHAPE);
        int yRotation = shape == RailShape.EAST_WEST ? 270 : 0;
        if (backwards)
            yRotation += 180;
        return ConfiguredModel.builder().modelFile(p.models().getExistingFile(p.modLoc("block/" + c.getName() + "/block_" + type.getSerializedName() + (powered ? "_powered" : "")))).rotationY(yRotation % 360).build();
    });
}
Also used : RadialChassisBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.RadialChassisBlock) ResourceLocation(net.minecraft.resources.ResourceLocation) MultiPartBlockStateBuilder(net.minecraftforge.client.model.generators.MultiPartBlockStateBuilder) Direction(net.minecraft.core.Direction) ModelFile(net.minecraftforge.client.model.generators.ModelFile) BiFunction(java.util.function.BiFunction) Pointing(com.simibubi.create.foundation.utility.Pointing) BlockState(net.minecraft.world.level.block.state.BlockState) HashMap(java.util.HashMap) EncasedPipeBlock(com.simibubi.create.content.contraptions.fluids.pipes.EncasedPipeBlock) Function(java.util.function.Function) LinearChassisBlock(com.simibubi.create.content.contraptions.components.structureMovement.chassis.LinearChassisBlock) CartAssemblerBlock(com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerBlock) Axis(net.minecraft.core.Direction.Axis) BooleanProperty(net.minecraft.world.level.block.state.properties.BooleanProperty) AxisDirection(net.minecraft.core.Direction.AxisDirection) Vector(java.util.Vector) Pair(org.apache.commons.lang3.tuple.Pair) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) FluidPipeBlock(com.simibubi.create.content.contraptions.fluids.pipes.FluidPipeBlock) DataGenContext(com.tterrag.registrate.providers.DataGenContext) BlockStateProperties(net.minecraft.world.level.block.state.properties.BlockStateProperties) IdentityHashMap(java.util.IdentityHashMap) Iterate(com.simibubi.create.foundation.utility.Iterate) ImmutableMap(com.google.common.collect.ImmutableMap) BlazeBurnerBlock(com.simibubi.create.content.contraptions.processing.burner.BlazeBurnerBlock) RegistrateBlockstateProvider(com.tterrag.registrate.providers.RegistrateBlockstateProvider) RailShape(net.minecraft.world.level.block.state.properties.RailShape) List(java.util.List) NonNullBiConsumer(com.tterrag.registrate.util.nullness.NonNullBiConsumer) ConfiguredModel(net.minecraftforge.client.model.generators.ConfiguredModel) DirectionalAxisKineticBlock(com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock) Block(net.minecraft.world.level.block.Block) CartAssembleRailType(com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssembleRailType) RailShape(net.minecraft.world.level.block.state.properties.RailShape) CartAssembleRailType(com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssembleRailType)

Example 9 with RailShape

use of net.minecraft.world.level.block.state.properties.RailShape 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 10 with RailShape

use of net.minecraft.world.level.block.state.properties.RailShape 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

RailShape (net.minecraft.world.level.block.state.properties.RailShape)14 BlockState (net.minecraft.world.level.block.state.BlockState)9 BaseRailBlock (net.minecraft.world.level.block.BaseRailBlock)8 BlockPos (net.minecraft.core.BlockPos)7 AbstractMinecart (net.minecraft.world.entity.vehicle.AbstractMinecart)6 Direction (net.minecraft.core.Direction)5 Vec3 (net.minecraft.world.phys.Vec3)5 Level (net.minecraft.world.level.Level)4 Nonnull (javax.annotation.Nonnull)2 AxisDirection (net.minecraft.core.Direction.AxisDirection)2 Vec3i (net.minecraft.core.Vec3i)2 Player (net.minecraft.world.entity.player.Player)2 ItemStack (net.minecraft.world.item.ItemStack)2 Block (net.minecraft.world.level.block.Block)2 EntityPoolMinecart (vazkii.botania.common.entity.EntityPoolMinecart)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 DirectionalAxisKineticBlock (com.simibubi.create.content.contraptions.base.DirectionalAxisKineticBlock)1 StabilizedContraption (com.simibubi.create.content.contraptions.components.structureMovement.bearing.StabilizedContraption)1 LinearChassisBlock (com.simibubi.create.content.contraptions.components.structureMovement.chassis.LinearChassisBlock)1