Search in sources :

Example 1 with MountedContraption

use of com.simibubi.create.content.contraptions.components.structureMovement.mounted.MountedContraption in project LittleContraptions by EDToaster.

the class BargeAssemblerBlockEntity method assemble.

protected void assemble(Level world, BlockPos pos, ContraptionBargeEntity barge) {
    if (!barge.getPassengers().isEmpty())
        return;
    CartAssemblerTileEntity.CartMovementMode mode = CartAssemblerTileEntity.CartMovementMode.ROTATE;
    MountedContraption contraption = new MountedContraption(mode);
    try {
        if (!contraption.assemble(world, pos)) {
            return;
        }
        lastException = null;
    } catch (AssemblyException e) {
        lastException = e;
        e.printStackTrace();
        return;
    }
    Direction initialOrientation = BargeAssemblerBlock.getHorizontalDirection(getBlockState());
    contraption.removeBlocksFromWorld(world, BlockPos.ZERO);
    contraption.startMoving(world);
    contraption.expandBoundsAroundAxis(Direction.Axis.Y);
    OrientedContraptionEntity entity = OrientedContraptionEntity.create(world, contraption, initialOrientation);
    entity.setPos(pos.getX(), pos.getY(), pos.getZ());
    world.addFreshEntity(entity);
    entity.startRiding(barge);
}
Also used : AssemblyException(com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException) MountedContraption(com.simibubi.create.content.contraptions.components.structureMovement.mounted.MountedContraption) OrientedContraptionEntity(com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity) CartAssemblerTileEntity(com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity) Direction(net.minecraft.core.Direction)

Example 2 with MountedContraption

use of com.simibubi.create.content.contraptions.components.structureMovement.mounted.MountedContraption in project Create by Creators-of-Create.

the class OrientedContraptionEntity method tickContraption.

@Override
protected void tickContraption() {
    Entity e = getVehicle();
    if (e == null)
        return;
    boolean rotationLock = false;
    boolean pauseWhileRotating = false;
    boolean wasStalled = isStalled();
    if (contraption instanceof MountedContraption) {
        MountedContraption mountedContraption = (MountedContraption) contraption;
        rotationLock = mountedContraption.rotationMode == CartMovementMode.ROTATION_LOCKED;
        pauseWhileRotating = mountedContraption.rotationMode == CartMovementMode.ROTATE_PAUSED;
    }
    Entity riding = e;
    while (riding.getVehicle() != null && !(contraption instanceof StabilizedContraption)) riding = riding.getVehicle();
    boolean isOnCoupling = false;
    UUID couplingId = getCouplingId();
    isOnCoupling = couplingId != null && riding instanceof AbstractMinecart;
    if (!attachedExtraInventories) {
        attachInventoriesFromRidingCarts(riding, isOnCoupling, couplingId);
        attachedExtraInventories = true;
    }
    boolean rotating = updateOrientation(rotationLock, wasStalled, riding, isOnCoupling);
    if (!rotating || !pauseWhileRotating)
        tickActors();
    boolean isStalled = isStalled();
    LazyOptional<MinecartController> capability = riding.getCapability(CapabilityMinecartController.MINECART_CONTROLLER_CAPABILITY);
    if (capability.isPresent()) {
        if (!level.isClientSide())
            capability.orElse(null).setStalledExternally(isStalled);
    } else {
        if (isStalled) {
            if (!wasStalled)
                motionBeforeStall = riding.getDeltaMovement();
            riding.setDeltaMovement(0, 0, 0);
        }
        if (wasStalled && !isStalled) {
            riding.setDeltaMovement(motionBeforeStall);
            motionBeforeStall = Vec3.ZERO;
        }
    }
    if (level.isClientSide)
        return;
    if (!isStalled()) {
        if (isOnCoupling) {
            Couple<MinecartController> coupledCarts = getCoupledCartsIfPresent();
            if (coupledCarts == null)
                return;
            coupledCarts.map(MinecartController::cart).forEach(this::powerFurnaceCartWithFuelFromStorage);
            return;
        }
        powerFurnaceCartWithFuelFromStorage(riding);
    }
}
Also used : Entity(net.minecraft.world.entity.Entity) MountedContraption(com.simibubi.create.content.contraptions.components.structureMovement.mounted.MountedContraption) AbstractMinecart(net.minecraft.world.entity.vehicle.AbstractMinecart) UUID(java.util.UUID) MinecartController(com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController) CapabilityMinecartController(com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController) StabilizedContraption(com.simibubi.create.content.contraptions.components.structureMovement.bearing.StabilizedContraption)

Aggregations

MountedContraption (com.simibubi.create.content.contraptions.components.structureMovement.mounted.MountedContraption)2 AssemblyException (com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException)1 OrientedContraptionEntity (com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity)1 StabilizedContraption (com.simibubi.create.content.contraptions.components.structureMovement.bearing.StabilizedContraption)1 CartAssemblerTileEntity (com.simibubi.create.content.contraptions.components.structureMovement.mounted.CartAssemblerTileEntity)1 CapabilityMinecartController (com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController)1 MinecartController (com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController)1 UUID (java.util.UUID)1 Direction (net.minecraft.core.Direction)1 Entity (net.minecraft.world.entity.Entity)1 AbstractMinecart (net.minecraft.world.entity.vehicle.AbstractMinecart)1