Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/com/mrcrayfish/vehicle/VehicleConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mrcrayfish.vehicle;

import java.util.Map;
import net.minecraftforge.common.config.Config;
import net.minecraftforge.common.config.ConfigManager;
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
Expand All @@ -26,6 +27,11 @@ public class VehicleConfig

public static class Server
{
@Config.Name("fuel list")
@Config.Comment("fuel: <Fuel Consumption Factor>")
@Config.LangKey(Reference.MOD_ID + ".config.server.fuel_list")
public Map<String, Double> fuel_list = VehicleFuel.getDefaultFuels();

@Config.Name("Fuel Enabled")
@Config.Comment("If true, vehicles will require fuel for them to be driven.")
@Config.LangKey(Reference.MOD_ID + ".config.server.fuel_enabled")
Expand Down Expand Up @@ -73,11 +79,13 @@ public static class Server
@Config.RangeInt(min = 1)
public int pumpTransferAmount = 50;

/*
@Config.Name("Fuel Consumption Factor")
@Config.Comment("Change the amount of fuel vehicles consumes by multiplying the consumption rate by this factor")
@Config.LangKey(Reference.MOD_ID + ".config.erver.fuel_consumption_modifier")
@Config.RangeDouble(min = 0.0)
public double fuelConsumptionFactor = 1.0;
*/
}

public static class Client
Expand Down
60 changes: 60 additions & 0 deletions src/main/java/com/mrcrayfish/vehicle/VehicleFuel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.mrcrayfish.vehicle;

import java.util.HashMap;
import java.util.Map;

import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;

public class VehicleFuel
{
public static double DEFAULT_CONSUMPTION_FACTOR = 100.0;
public static Map<String, Double> getDefaultFuels()
{
Map<String,Double> fuelMap = new HashMap<>();
fuelMap.put("fuelium", 1.0);
fuelMap.put("lava", 10.0);
return fuelMap;
}

public static String getFluidName(FluidTank tank)
{
return getFluidName(tank.getFluid());
}
public static String getFluidName(FluidStack fluid)
{
return getFluidName(fluid.getFluid());
}
private static String getFluidName(Fluid fluid)
{
return fluid.getName();
}
public static boolean isFuel(FluidStack fluid)
{
return isFuel(fluid.getFluid());
}

private static boolean isFuel(Fluid fluid)
{
return isFuel(fluid.getName());
}

public static boolean isFuel(FluidTank tank)
{
return isFuel(tank.getFluid());
}
private static boolean isFuel(String fuelName)
{
return VehicleConfig.SERVER.fuel_list.containsKey(fuelName);
}
public static double getFuelConsumptionFactorForFuel(String fuelName)
{
if (isFuel(fuelName))
{
return VehicleConfig.SERVER.fuel_list.get(fuelName);
}
return DEFAULT_CONSUMPTION_FACTOR;
}

}
4 changes: 3 additions & 1 deletion src/main/java/com/mrcrayfish/vehicle/block/BlockGasPump.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mrcrayfish.vehicle.block;

import com.mrcrayfish.vehicle.VehicleFuel;
import com.mrcrayfish.vehicle.init.ModFluids;
import com.mrcrayfish.vehicle.init.ModSounds;
import com.mrcrayfish.vehicle.item.ItemJerryCan;
Expand Down Expand Up @@ -116,7 +117,8 @@ else if(state.getValue(FACING).rotateY().equals(face))
if(handler instanceof FluidTank)
{
FluidTank tank = (FluidTank) handler;
if(tank.getFluid() != null && tank.getFluid().getFluid() != ModFluids.FUELIUM)
//if(tank.getFluid() != null && tank.getFluid().getFluid() != ModFluids.FUELIUM)
if (tank.getFluid() != null && !VehicleFuel.isFuel(tank))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mrcrayfish.vehicle.entity;

import com.mrcrayfish.vehicle.VehicleConfig;
import com.mrcrayfish.vehicle.VehicleFuel;
import com.mrcrayfish.vehicle.VehicleMod;
import com.mrcrayfish.vehicle.block.BlockVehicleCrate;
import com.mrcrayfish.vehicle.client.SpecialModels;
Expand Down Expand Up @@ -87,6 +88,7 @@ public abstract class EntityPoweredVehicle extends EntityVehicle implements IInv
protected static final DataParameter<Boolean> REQUIRES_FUEL = EntityDataManager.createKey(EntityPoweredVehicle.class, DataSerializers.BOOLEAN);
protected static final DataParameter<Float> CURRENT_FUEL = EntityDataManager.createKey(EntityPoweredVehicle.class, DataSerializers.FLOAT);
protected static final DataParameter<Float> FUEL_CAPACITY = EntityDataManager.createKey(EntityPoweredVehicle.class, DataSerializers.FLOAT);
protected static final DataParameter<String> CURRENT_FUEL_NAME = EntityDataManager.createKey(EntityPoweredVehicle.class, DataSerializers.STRING);
protected static final DataParameter<Boolean> NEEDS_KEY = EntityDataManager.createKey(EntityPoweredVehicle.class, DataSerializers.BOOLEAN);
protected static final DataParameter<ItemStack> KEY_STACK = EntityDataManager.createKey(EntityPoweredVehicle.class, DataSerializers.ITEM_STACK);
protected static final DataParameter<Boolean> HAS_WHEELS = EntityDataManager.createKey(EntityPoweredVehicle.class, DataSerializers.BOOLEAN);
Expand Down Expand Up @@ -166,6 +168,7 @@ public void entityInit()
this.dataManager.register(HORN, false);
this.dataManager.register(REQUIRES_FUEL, VehicleConfig.SERVER.fuelEnabled);
this.dataManager.register(CURRENT_FUEL, 0F);
this.dataManager.register(CURRENT_FUEL_NAME, "");
this.dataManager.register(FUEL_CAPACITY, 15000F);
this.dataManager.register(NEEDS_KEY, false);
this.dataManager.register(KEY_STACK, ItemStack.EMPTY);
Expand Down Expand Up @@ -249,7 +252,7 @@ public void fuelVehicle(EntityPlayer player, EnumHand hand)
FluidStack stack = gasPumpTank.getFluidTank().drain(200, true);
if(stack != null)
{
stack.amount = this.addFuel(stack.amount);
stack.amount = this.addFuel(stack.getFluid().getName(), stack.amount);
if(stack.amount > 0)
{
gasPumpTank.getFluidTank().fill(stack, true);
Expand All @@ -261,12 +264,14 @@ public void fuelVehicle(EntityPlayer player, EnumHand hand)
}

ItemStack stack = player.getHeldItem(hand);
if(!stack.isEmpty() && stack.getItem() instanceof ItemJerryCan)
//if(!stack.isEmpty() && stack.getItem() instanceof ItemJerryCan)
if(!stack.isEmpty() && stack.getItem() instanceof ItemJerryCan && this.getCurrentFuelName() == ModFluids.FUELIUM.getName())
{
ItemJerryCan jerryCan = (ItemJerryCan) stack.getItem();
int rate = jerryCan.getFillRate(stack);
int drained = jerryCan.drain(stack, rate);
int remaining = this.addFuel(drained);
//int remaining = this.addFuel(drained);
int remaining = this.addFuel(ModFluids.FUELIUM.getName(), drained);
jerryCan.fill(stack, remaining);
}
}
Expand Down Expand Up @@ -442,9 +447,15 @@ else if (deltaRot >= 180.0D)
float currentSpeed = Math.abs(Math.min(this.getSpeed(), this.getMaxSpeed()));
float normalSpeed = Math.max(0.05F, currentSpeed / this.getMaxSpeed());
float currentFuel = this.getCurrentFuel();
currentFuel -= fuelConsumption * normalSpeed * VehicleConfig.SERVER.fuelConsumptionFactor;
if(currentFuel < 0F) currentFuel = 0F;
//currentFuel -= fuelConsumption * normalSpeed * VehicleConfig.SERVER.fuelConsumptionFactor;
double consume = fuelConsumption * normalSpeed * VehicleFuel.getFuelConsumptionFactorForFuel(this.getCurrentFuelName());
currentFuel -= consume;
if(currentFuel < 0F)
{
currentFuel = 0F;
}
this.setCurrentFuel(currentFuel);
//System.out.println("currentSpeed:"+currentSpeed+", normalSpeed:"+normalSpeed+", this.getCurrentFuelName():"+this.getCurrentFuelName()+"/"+VehicleFuel.getFuelConsumptionFactorForFuel(this.getCurrentFuelName())+",consume:"+consume+" currentFuel:"+currentFuel);
}

this.prevAcceleration = this.getAcceleration();
Expand Down Expand Up @@ -713,6 +724,10 @@ protected void readEntityFromNBT(NBTTagCompound compound)
{
this.setCurrentFuel(compound.getFloat("currentFuel"));
}
if(compound.hasKey("currentFuelName", Constants.NBT.TAG_STRING))
{
this.setCurrentFuelName(compound.getString("currentFuelName"));
}
if(compound.hasKey("fuelCapacity", Constants.NBT.TAG_INT))
{
this.setFuelCapacity(compound.getInteger("fuelCapacity"));
Expand Down Expand Up @@ -744,6 +759,7 @@ protected void writeEntityToNBT(NBTTagCompound compound)
compound.setFloat("stepHeight", this.stepHeight);
compound.setBoolean("requiresFuel", this.requiresFuel());
compound.setFloat("currentFuel", this.getCurrentFuel());
compound.setString("currentFuelName", this.getCurrentFuelName());
compound.setFloat("fuelCapacity", this.getFuelCapacity());
compound.setBoolean("keyNeeded", this.isKeyNeeded());
CommonUtils.writeItemStackToTag(compound, "keyStack", this.getKeyStack());
Expand Down Expand Up @@ -1038,6 +1054,16 @@ public float getCurrentFuel()
return this.dataManager.get(CURRENT_FUEL);
}

public void setCurrentFuelName(String fuel)
{
this.dataManager.set(CURRENT_FUEL_NAME, fuel);
}

public String getCurrentFuelName()
{
return this.dataManager.get(CURRENT_FUEL_NAME);
}

public void setFuelCapacity(float capacity)
{
this.dataManager.set(FUEL_CAPACITY, capacity);
Expand All @@ -1058,15 +1084,24 @@ public float getFuelConsumption()
return fuelConsumption;
}

public int addFuel(int fuel)
public int addFuel(String fuelName,int fuel)
{
//System.out.println("addFuel ("+fuelName+", "+fuel+") getCurrentFuelName:"+this.getCurrentFuelName());
if(!this.requiresFuel())
return fuel;
float currentFuel = this.getCurrentFuel();
//System.out.println("currentFuel:"+currentFuel);
if (currentFuel > 0.0 && this.getCurrentFuelName() != fuelName)
{
//System.out.println("ret0");
return 0;
}
currentFuel += fuel;
int remaining = Math.max(0, Math.round(currentFuel - this.getFuelCapacity()));
currentFuel = Math.min(currentFuel, this.getFuelCapacity());
this.setCurrentFuel(currentFuel);
this.setCurrentFuelName(fuelName);
//System.out.println("ret remaining: "+remaining);
return remaining;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mrcrayfish.vehicle.tileentity;

import com.mrcrayfish.vehicle.init.ModFluids;
import com.mrcrayfish.vehicle.VehicleFuel;
//import com.mrcrayfish.vehicle.init.ModFluids;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
Expand All @@ -23,7 +24,8 @@ protected void onContentsChanged()
@Override
public boolean canFillFluidType(FluidStack fluid)
{
return fluid.getFluid() == ModFluids.FUELIUM;
//return fluid.getFluid() == ModFluids.FUELIUM;
return VehicleFuel.isFuel(fluid);
}
};
tank.setCanFill(true);
Expand Down