Search in sources :

Example 1 with MinecartFurnace

use of net.minecraft.world.entity.vehicle.MinecartFurnace in project Create by Creators-of-Create.

the class CartAssemblerTileEntity method disassembleCart.

protected void disassembleCart(AbstractMinecart cart) {
    cart.ejectPassengers();
    if (cart instanceof MinecartFurnace) {
        CompoundTag nbt = cart.serializeNBT();
        nbt.putDouble("PushZ", cart.getDeltaMovement().x);
        nbt.putDouble("PushX", cart.getDeltaMovement().z);
        cart.deserializeNBT(nbt);
    }
}
Also used : MinecartFurnace(net.minecraft.world.entity.vehicle.MinecartFurnace) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 2 with MinecartFurnace

use of net.minecraft.world.entity.vehicle.MinecartFurnace in project Create by Creators-of-Create.

the class CartAssemblerTileEntity method assemble.

protected void assemble(Level world, BlockPos pos, AbstractMinecart cart) {
    if (!cart.getPassengers().isEmpty())
        return;
    LazyOptional<MinecartController> optional = cart.getCapability(CapabilityMinecartController.MINECART_CONTROLLER_CAPABILITY);
    if (optional.isPresent() && optional.orElse(null).isCoupledThroughContraption())
        return;
    CartMovementMode mode = CartMovementMode.values()[movementMode.value];
    MountedContraption contraption = new MountedContraption(mode);
    try {
        if (!contraption.assemble(world, pos))
            return;
        lastException = null;
        sendData();
    } catch (AssemblyException e) {
        lastException = e;
        sendData();
        return;
    }
    boolean couplingFound = contraption.connectedCart != null;
    Direction initialOrientation = CartAssemblerBlock.getHorizontalDirection(getBlockState());
    if (couplingFound) {
        cart.setPos(pos.getX() + .5f, pos.getY(), pos.getZ() + .5f);
        if (!CouplingHandler.tryToCoupleCarts(null, world, cart.getId(), contraption.connectedCart.getId()))
            return;
    }
    contraption.removeBlocksFromWorld(world, BlockPos.ZERO);
    contraption.startMoving(world);
    contraption.expandBoundsAroundAxis(Axis.Y);
    if (couplingFound) {
        Vec3 diff = contraption.connectedCart.position().subtract(cart.position());
        initialOrientation = Direction.fromYRot(Mth.atan2(diff.z, diff.x) * 180 / Math.PI);
    }
    OrientedContraptionEntity entity = OrientedContraptionEntity.create(world, contraption, initialOrientation);
    if (couplingFound)
        entity.setCouplingId(cart.getUUID());
    entity.setPos(pos.getX(), pos.getY(), pos.getZ());
    world.addFreshEntity(entity);
    entity.startRiding(cart);
    if (cart instanceof MinecartFurnace) {
        CompoundTag nbt = cart.serializeNBT();
        nbt.putDouble("PushZ", 0);
        nbt.putDouble("PushX", 0);
        cart.deserializeNBT(nbt);
    }
}
Also used : MinecartFurnace(net.minecraft.world.entity.vehicle.MinecartFurnace) AssemblyException(com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException) OrientedContraptionEntity(com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity) Vec3(net.minecraft.world.phys.Vec3) MinecartController(com.simibubi.create.content.contraptions.components.structureMovement.train.capability.MinecartController) CapabilityMinecartController(com.simibubi.create.content.contraptions.components.structureMovement.train.capability.CapabilityMinecartController) Direction(net.minecraft.core.Direction) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 3 with MinecartFurnace

use of net.minecraft.world.entity.vehicle.MinecartFurnace in project Create by Creators-of-Create.

the class ControllerRailBlock method decelerateCart.

private static void decelerateCart(BlockPos pos, AbstractMinecart cart) {
    Vec3 diff = VecHelper.getCenterOf(pos).subtract(cart.position());
    cart.setDeltaMovement(diff.x / 16f, 0, diff.z / 16f);
    if (cart instanceof MinecartFurnace) {
        MinecartFurnace fme = (MinecartFurnace) cart;
        fme.xPush = fme.zPush = 0;
    }
}
Also used : MinecartFurnace(net.minecraft.world.entity.vehicle.MinecartFurnace) Vec3(net.minecraft.world.phys.Vec3)

Example 4 with MinecartFurnace

use of net.minecraft.world.entity.vehicle.MinecartFurnace in project Create by Creators-of-Create.

the class ControllerRailBlock method onMinecartPass.

@Override
public void onMinecartPass(BlockState state, Level world, BlockPos pos, AbstractMinecart cart) {
    if (world.isClientSide)
        return;
    Vec3 accelerationVec = Vec3.atLowerCornerOf(getAccelerationVector(state));
    double targetSpeed = cart.getMaxSpeedWithRail() * state.getValue(POWER) / 15f;
    if (cart instanceof MinecartFurnace) {
        MinecartFurnace fme = (MinecartFurnace) cart;
        fme.xPush = accelerationVec.x;
        fme.zPush = accelerationVec.z;
    }
    Vec3 motion = cart.getDeltaMovement();
    if ((motion.dot(accelerationVec) >= 0 || motion.lengthSqr() < 0.0001) && targetSpeed > 0)
        cart.setDeltaMovement(accelerationVec.scale(targetSpeed));
    else
        decelerateCart(pos, cart);
}
Also used : MinecartFurnace(net.minecraft.world.entity.vehicle.MinecartFurnace) Vec3(net.minecraft.world.phys.Vec3)

Example 5 with MinecartFurnace

use of net.minecraft.world.entity.vehicle.MinecartFurnace in project Create by Creators-of-Create.

the class OrientedContraptionEntity method powerFurnaceCartWithFuelFromStorage.

protected void powerFurnaceCartWithFuelFromStorage(Entity riding) {
    if (!(riding instanceof MinecartFurnace))
        return;
    MinecartFurnace furnaceCart = (MinecartFurnace) riding;
    // Notify to not trigger serialization side-effects
    isSerializingFurnaceCart = true;
    CompoundTag nbt = furnaceCart.serializeNBT();
    isSerializingFurnaceCart = false;
    int fuel = nbt.getInt("Fuel");
    int fuelBefore = fuel;
    double pushX = nbt.getDouble("PushX");
    double pushZ = nbt.getDouble("PushZ");
    int i = Mth.floor(furnaceCart.getX());
    int j = Mth.floor(furnaceCart.getY());
    int k = Mth.floor(furnaceCart.getZ());
    if (furnaceCart.level.getBlockState(new BlockPos(i, j - 1, k)).is(BlockTags.RAILS))
        --j;
    BlockPos blockpos = new BlockPos(i, j, k);
    BlockState blockstate = this.level.getBlockState(blockpos);
    if (furnaceCart.canUseRail() && blockstate.is(BlockTags.RAILS))
        if (fuel > 1)
            riding.setDeltaMovement(riding.getDeltaMovement().normalize().scale(1));
    if (fuel < 5 && contraption != null) {
        ItemStack coal = ItemHelper.extract(contraption.inventory, FUEL_ITEMS, 1, false);
        if (!coal.isEmpty())
            fuel += 3600;
    }
    if (fuel != fuelBefore || pushX != 0 || pushZ != 0) {
        nbt.putInt("Fuel", fuel);
        nbt.putDouble("PushX", 0);
        nbt.putDouble("PushZ", 0);
        furnaceCart.deserializeNBT(nbt);
    }
}
Also used : MinecartFurnace(net.minecraft.world.entity.vehicle.MinecartFurnace) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) ItemStack(net.minecraft.world.item.ItemStack) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

MinecartFurnace (net.minecraft.world.entity.vehicle.MinecartFurnace)5 CompoundTag (net.minecraft.nbt.CompoundTag)3 Vec3 (net.minecraft.world.phys.Vec3)3 AssemblyException (com.simibubi.create.content.contraptions.components.structureMovement.AssemblyException)1 OrientedContraptionEntity (com.simibubi.create.content.contraptions.components.structureMovement.OrientedContraptionEntity)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 BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 ItemStack (net.minecraft.world.item.ItemStack)1 BlockState (net.minecraft.world.level.block.state.BlockState)1