Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void slowTick(List<Player> nearby) {
sinking = false;
if(sinkProgress > 0) {
if(hasPump()) {
sinkProgress = Math.max(0, sinkProgress - pump.getPower()/10);
sinkProgress = Math.max(0, sinkProgress - Math.max(1, pump.getPower()/10));
} else {
sinkProgress -= 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,17 @@ public ComponentHandler(ConfigurationSection config) {
break;
}
}
linkPump();
}


/** Gives a sinkable hull the vehicle's pump, which keeps water out of it. */
private void linkPump() {
if(getComponent(Component.HULL) instanceof SinkableHull hull
&& getComponent(Component.PUMP) instanceof Pump pump) {
hull.setPump(pump);
}
}

public void updateModel(ActiveModel m) {
for(VehicleComponent c : components) {
c.updateModel(m);
Expand Down Expand Up @@ -142,6 +151,7 @@ public ComponentHandler(ActiveVehicle v, Entity e, ActiveModel m, IncompleteVehi
break;
}
}
linkPump();
}

public void damage(String cause, double a) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
import net.tfminecraft.vehicleframework.cache.Cache;
import net.tfminecraft.vehicleframework.data.DamageData;
import net.tfminecraft.vehicleframework.util.ConfigMerger;
import net.tfminecraft.vehicleframework.enums.Component;
import net.tfminecraft.vehicleframework.vehicles.Vehicle;
import net.tfminecraft.vehicleframework.vehicles.component.SinkableHull;
import net.tfminecraft.vehicleframework.vehicles.handlers.ComponentHandler;
import net.tfminecraft.vehicleframework.vehicles.fuel.Fuel;
import net.tfminecraft.vehicleframework.weapons.ammunition.*;
import org.bukkit.*;
Expand Down Expand Up @@ -532,7 +535,16 @@ void ammunitionAndVehicleFilesRegisterRealConfiguredTemplates() throws Exception
+ " skins: {default: {model: cart_model}}\n"
+ " states: {}\n"
+ " components: {hull: {health: 100}}\n"
+ " seats: []\n"
+ "skiff:\n"
+ " name: Skiff\n"
+ " model: default\n"
+ " skins: {default: {model: skiff_model}}\n"
+ " states: {}\n"
+ " components: {hull: {health: 100, sinkable: true}, pump: {health: 50, power: 40}}\n"
+ " seats: []\n"));
ComponentHandler skiff = VehicleLoader.getByString("skiff").getComponentHandler();
assertSame(skiff.getComponent(Component.PUMP), ((SinkableHull) skiff.getComponent(Component.HULL)).getPump());
Vehicle cart = VehicleLoader.getByString("cart");
assertNotNull(cart);
assertEquals("Cargo Cart", cart.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ void damagedEngineReportsFailedStartAndAllowsAnotherAttempt(boolean custom) {
assertFalse(hull.hasSinkProgress());
config.set("power", 0); hull.setPump(new Pump(config)); hull.getHealthData().setDamage(30);
hull.slowTick(List.of()); assertEquals(2, hull.getSinkProgress());
hull.getHealthData().setDamage(0); hull.slowTick(List.of()); assertEquals(1, hull.getSinkProgress());
}

@Test void damagedPumpAndWingsLosePowerWithoutNegativeLift() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,16 @@ void missingRequiredTemplateSectionsReportTheirVehicleAndSection(String section)
ComponentHandler sink = new ComponentHandler(vehicle, vehicle.getEntity(), model, null, sinkTemplate);
assertInstanceOf(SinkableHull.class, sink.getComponent(Component.HULL));
for (VehicleComponent component : sink.getComponents()) assertEquals(0, component.getHealthData().getDamage());
assertSame(sinkTemplate.getComponent(Component.PUMP), ((SinkableHull) sinkTemplate.getComponent(Component.HULL)).getPump());
assertSame(sink.getComponent(Component.PUMP), ((SinkableHull) sink.getComponent(Component.HULL)).getPump());
}

@Test void sinkableHullWithoutAPumpStaysUnpumped() {
YamlConfiguration config = yaml(); config.createSection("hull", componentConfig().getValues(true)); config.set("hull.sinkable", true);
ActiveVehicle vehicle = vehicle(); ComponentHandler template = new ComponentHandler(config);
ComponentHandler live = new ComponentHandler(vehicle, vehicle.getEntity(), model(0), null, template);
assertFalse(((SinkableHull) template.getComponent(Component.HULL)).hasPump());
assertFalse(((SinkableHull) live.getComponent(Component.HULL)).hasPump());
}

@Test void randomFireIgnitesAnAvailableComponentAndHandlesAnAlreadyBurningVehicle() {
Expand Down
Loading