Automatic steam input for engines

This commit is contained in:
khj xiaogu 2023-03-14 16:37:44 +08:00
parent 3e7cf4c68b
commit f94adf204e
No known key found for this signature in database
GPG key ID: DEA172814EAFF426
6 changed files with 55 additions and 4 deletions

View file

@ -27,14 +27,17 @@ public class SPConfig {
public final ForgeConfigSpec.IntValue bronzeFlywheelSpeed;
public final ForgeConfigSpec.IntValue bronzeFlywheelSteamConsumptionPerTick;
public final ForgeConfigSpec.IntValue bronzeFlywheelSteamStorage;
public final ForgeConfigSpec.DoubleValue bronzeFlywheelSuckEfficiency;
public final ForgeConfigSpec.IntValue castIronFlywheelCapacity;
public final ForgeConfigSpec.IntValue castIronFlywheelSpeed;
public final ForgeConfigSpec.IntValue castIronFlywheelSteamConsumptionPerTick;
public final ForgeConfigSpec.IntValue castIronFlywheelSteamStorage;
public final ForgeConfigSpec.DoubleValue castIronFlywheelSuckEfficiency;
public final ForgeConfigSpec.IntValue steelFlywheelCapacity;
public final ForgeConfigSpec.IntValue steelFlywheelSpeed;
public final ForgeConfigSpec.IntValue steelFlywheelSteamConsumptionPerTick;
public final ForgeConfigSpec.IntValue steelFlywheelSteamStorage;
public final ForgeConfigSpec.DoubleValue steelFlywheelSuckEfficiency;
public final ForgeConfigSpec.IntValue HUPerFuelTick;
public final ForgeConfigSpec.DoubleValue steamPerWater;
@ -98,7 +101,7 @@ public class SPConfig {
bronzeFlywheelSpeed = builder.defineInRange("bronzeFlywheelSpeed", 32, 0, 8192);
bronzeFlywheelSteamConsumptionPerTick = builder.defineInRange("bronzeFlywheelSteamConsumptionPerTick", 12, 0, 8192);
bronzeFlywheelSteamStorage = builder.defineInRange("bronzeFlywheelSteamStorage", 32000, 0, 1048576);
bronzeFlywheelSuckEfficiency =builder.defineInRange("bronzeFlywheelSuckEfficiency",0.7,0,1);
}
builder.pop();
builder.push("cast_iron_flywheel");
@ -107,6 +110,7 @@ public class SPConfig {
castIronFlywheelSpeed = builder.defineInRange("castIronFlywheelSpeed", 32, 0, 8192);
castIronFlywheelSteamConsumptionPerTick = builder.defineInRange("castIronFlywheelSteamConsumptionPerTick", 24, 0, 8192);
castIronFlywheelSteamStorage = builder.defineInRange("castIronFlywheelSteamStorage", 64000, 0, 1048576);
castIronFlywheelSuckEfficiency =builder.defineInRange("castIronFlywheelSuckEfficiency",0.7,0,1);
}
builder.pop();
builder.push("steel_flywheel");
@ -115,6 +119,7 @@ public class SPConfig {
steelFlywheelSpeed = builder.defineInRange("steelFlywheelSpeed", 32, 0, 8192);
steelFlywheelSteamConsumptionPerTick = builder.defineInRange("steelFlywheelSteamConsumptionPerTick", 48, 0, 1048576);
steelFlywheelSteamStorage = builder.defineInRange("steelFlywheelSteamStorage", 96000, 0, 1048576);
steelFlywheelSuckEfficiency =builder.defineInRange("steelFlywheelSuckEfficiency",0.7,0,1);
}
builder.pop();
}

View file

@ -49,7 +49,7 @@ import net.minecraftforge.fluids.capability.templates.FluidTank;
public abstract class BoilerTileEntity extends TileEntity
implements IHeatReceiver, ITickableTileEntity, IHaveGoggleInformation {
FluidTank input = new FluidTank(10000, s -> s.getFluid() == Fluids.WATER);
FluidTank output = new FluidTank(10000);
public FluidTank output = new FluidTank(10000);
private IFluidHandler ft = new IFluidHandler() {
@Override
public int getTanks() {

View file

@ -53,4 +53,9 @@ public class BronzeSteamEngineTileEntity extends SteamEngineTileEntity {
public int getSteamStorage() {
return SPConfig.COMMON.bronzeFlywheelSteamStorage.get();
}
@Override
public double getSuckEfficiency() {
return SPConfig.COMMON.bronzeFlywheelSuckEfficiency.get();
}
}

View file

@ -53,4 +53,9 @@ public class CastIronSteamEngineTileEntity extends SteamEngineTileEntity {
public int getSteamStorage() {
return SPConfig.COMMON.castIronFlywheelSteamStorage.get();
}
@Override
public double getSuckEfficiency() {
return SPConfig.COMMON.castIronFlywheelSuckEfficiency.get();
}
}

View file

@ -30,6 +30,7 @@ import com.simibubi.create.content.contraptions.components.flywheel.engine.Engin
import com.simibubi.create.content.contraptions.goggles.IHaveGoggleInformation;
import com.teammoeg.steampowered.FluidRegistry;
import com.teammoeg.steampowered.client.Particles;
import com.teammoeg.steampowered.content.boiler.BoilerTileEntity;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
@ -44,6 +45,7 @@ import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
@ -121,6 +123,7 @@ public abstract class SteamEngineTileEntity extends EngineTileEntity implements
if(level == null)return;
if (!level.isClientSide) {
BlockState state = this.level.getBlockState(this.worldPosition);
if(this.poweredWheel==null)attachWheel();
if (this.poweredWheel == null || this.poweredWheel.isRemoved()) {
if(this.appliedSpeed!=0||this.appliedCapacity!=0) {
this.appliedCapacity = 0;
@ -135,6 +138,15 @@ public abstract class SteamEngineTileEntity extends EngineTileEntity implements
if(state.getValue(SteamEngineBlock.LIT))
this.level.setBlockAndUpdate(this.worldPosition, state.setValue(SteamEngineBlock.LIT, false));
} else {
Direction engineFacing = this.getBlockState().getValue(EngineBlock.FACING);
BlockPos boilerPos = this.worldPosition.relative(engineFacing, -1);
FluidTank tank=this.tank;
if(this.tank.isEmpty()) {
TileEntity te=this.getWorld().getBlockEntity(boilerPos);
if(te instanceof BoilerTileEntity) {
tank=((BoilerTileEntity)te).output;
}
}
if(heatup==0&&tank.getFluidAmount()/this.getSteamConsumptionPerTick()<40)
return;
@ -142,9 +154,14 @@ public abstract class SteamEngineTileEntity extends EngineTileEntity implements
.getAmount() >= this.getSteamConsumptionPerTick()) {
if (heatup >= 60) {
float spd=this.getGeneratingSpeed();
if(this.tank!=tank)
spd=MathHelper.ceil(spd*this.getSuckEfficiency());
this.appliedCapacity = this.getGeneratingCapacity();
this.appliedSpeed = this.getGeneratingSpeed();
this.refreshWheelSpeed();
if(this.appliedSpeed!=spd) {
this.appliedSpeed = this.getGeneratingSpeed();
this.refreshWheelSpeed();
}
} else {
heatup++;
this.setChanged();
@ -241,6 +258,7 @@ public abstract class SteamEngineTileEntity extends EngineTileEntity implements
Direction engineFacing = this.getBlockState().getValue(EngineBlock.FACING);
BlockPos wheelPos = this.worldPosition.relative(engineFacing, 2);
BlockState wheelState = this.level.getBlockState(wheelPos);
if (this.getFlywheel() == wheelState.getBlock()) {
Direction wheelFacing = wheelState.getValue(FlywheelBlock.HORIZONTAL_FACING);
if (wheelFacing.getAxis() == engineFacing.getClockWise().getAxis()) {
@ -256,12 +274,17 @@ public abstract class SteamEngineTileEntity extends EngineTileEntity implements
this.poweredWheel = (FlywheelTileEntity) te;
this.refreshWheelSpeed();
return;
}
}
}
}
}
if(poweredWheel!=null&&!poweredWheel.isRemoved()) {
this.poweredWheel.setRotation(0, 0);
this.poweredWheel =null;
}
}
public abstract Block getFlywheel();
@ -273,4 +296,12 @@ public abstract class SteamEngineTileEntity extends EngineTileEntity implements
public abstract int getSteamConsumptionPerTick();
public abstract int getSteamStorage();
public abstract double getSuckEfficiency();
@Override
public void lazyTick() {
super.lazyTick();
this.attachWheel();
}
}

View file

@ -53,4 +53,9 @@ public class SteelSteamEngineTileEntity extends SteamEngineTileEntity {
public int getSteamStorage() {
return SPConfig.COMMON.steelFlywheelSteamStorage.get();
}
@Override
public double getSuckEfficiency() {
return SPConfig.COMMON.steelFlywheelSuckEfficiency.get();
}
}