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);
}
}
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);
}
}
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;
}
}
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);
}
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);
}
}
Aggregations