diff --git a/src/main/java/com/mrcrayfish/vehicle/VehicleConfig.java b/src/main/java/com/mrcrayfish/vehicle/VehicleConfig.java index 5b0c5fa44..8070a6e8c 100644 --- a/src/main/java/com/mrcrayfish/vehicle/VehicleConfig.java +++ b/src/main/java/com/mrcrayfish/vehicle/VehicleConfig.java @@ -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; @@ -26,6 +27,11 @@ public class VehicleConfig public static class Server { + @Config.Name("fuel list") + @Config.Comment("fuel: ") + @Config.LangKey(Reference.MOD_ID + ".config.server.fuel_list") + public Map 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") @@ -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 diff --git a/src/main/java/com/mrcrayfish/vehicle/VehicleFuel.java b/src/main/java/com/mrcrayfish/vehicle/VehicleFuel.java new file mode 100644 index 000000000..886547107 --- /dev/null +++ b/src/main/java/com/mrcrayfish/vehicle/VehicleFuel.java @@ -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 getDefaultFuels() + { + Map 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; + } + + } diff --git a/src/main/java/com/mrcrayfish/vehicle/block/BlockGasPump.java b/src/main/java/com/mrcrayfish/vehicle/block/BlockGasPump.java index 5ba47bcc9..67f438933 100644 --- a/src/main/java/com/mrcrayfish/vehicle/block/BlockGasPump.java +++ b/src/main/java/com/mrcrayfish/vehicle/block/BlockGasPump.java @@ -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; @@ -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; } diff --git a/src/main/java/com/mrcrayfish/vehicle/entity/EntityPoweredVehicle.java b/src/main/java/com/mrcrayfish/vehicle/entity/EntityPoweredVehicle.java index 377c4fdb1..ac1b192b9 100644 --- a/src/main/java/com/mrcrayfish/vehicle/entity/EntityPoweredVehicle.java +++ b/src/main/java/com/mrcrayfish/vehicle/entity/EntityPoweredVehicle.java @@ -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; @@ -87,6 +88,7 @@ public abstract class EntityPoweredVehicle extends EntityVehicle implements IInv protected static final DataParameter REQUIRES_FUEL = EntityDataManager.createKey(EntityPoweredVehicle.class, DataSerializers.BOOLEAN); protected static final DataParameter CURRENT_FUEL = EntityDataManager.createKey(EntityPoweredVehicle.class, DataSerializers.FLOAT); protected static final DataParameter FUEL_CAPACITY = EntityDataManager.createKey(EntityPoweredVehicle.class, DataSerializers.FLOAT); + protected static final DataParameter CURRENT_FUEL_NAME = EntityDataManager.createKey(EntityPoweredVehicle.class, DataSerializers.STRING); protected static final DataParameter NEEDS_KEY = EntityDataManager.createKey(EntityPoweredVehicle.class, DataSerializers.BOOLEAN); protected static final DataParameter KEY_STACK = EntityDataManager.createKey(EntityPoweredVehicle.class, DataSerializers.ITEM_STACK); protected static final DataParameter HAS_WHEELS = EntityDataManager.createKey(EntityPoweredVehicle.class, DataSerializers.BOOLEAN); @@ -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); @@ -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); @@ -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); } } @@ -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(); @@ -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")); @@ -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()); @@ -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); @@ -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; } diff --git a/src/main/java/com/mrcrayfish/vehicle/tileentity/TileEntityGasPumpTank.java b/src/main/java/com/mrcrayfish/vehicle/tileentity/TileEntityGasPumpTank.java index 5614bdfc0..8bf82e3b2 100644 --- a/src/main/java/com/mrcrayfish/vehicle/tileentity/TileEntityGasPumpTank.java +++ b/src/main/java/com/mrcrayfish/vehicle/tileentity/TileEntityGasPumpTank.java @@ -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; @@ -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);