Make payload blocks run onDestroyed() of the block payload it carries when destroyed. (#8253)
* Payloads go boom. * When a payload unit dies too * Keep the functionality, but limit it to a rule
This commit is contained in:
@@ -60,6 +60,11 @@ abstract class PayloadComp implements Posc, Rotc, Hitboxc, Unitc{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy(){
|
||||
if(Vars.state.rules.unitPayloadsExplode) payloads.each(Payload::destroyed);
|
||||
}
|
||||
|
||||
float payloadUsed(){
|
||||
return payloads.sumf(p -> p.size() * p.size());
|
||||
}
|
||||
|
||||
@@ -59,6 +59,8 @@ public class Rules{
|
||||
public boolean unitAmmo = false;
|
||||
/** EXPERIMENTAL! If true, blocks will update in units and share power. */
|
||||
public boolean unitPayloadUpdate = false;
|
||||
/** If true, units' payloads are destroy()ed when the unit is destroyed. */
|
||||
public boolean unitPayloadsExplode = false;
|
||||
/** Whether cores add to unit limit */
|
||||
public boolean unitCapVariable = true;
|
||||
/** If true, unit spawn points are shown. */
|
||||
|
||||
@@ -233,6 +233,7 @@ public class CustomRulesDialog extends BaseDialog{
|
||||
|
||||
title("@rules.title.unit");
|
||||
check("@rules.unitcapvariable", b -> rules.unitCapVariable = b, () -> rules.unitCapVariable);
|
||||
check("@rules.unitpayloadsexplode", b -> rules.unitPayloadsExplode = b, () -> rules.unitPayloadsExplode);
|
||||
numberi("@rules.unitcap", f -> rules.unitCap = f, () -> rules.unitCap, -999, 999);
|
||||
number("@rules.unitdamagemultiplier", f -> rules.unitDamageMultiplier = f, () -> rules.unitDamageMultiplier);
|
||||
number("@rules.unitcrashdamagemultiplier", f -> rules.unitCrashDamageMultiplier = f, () -> rules.unitCrashDamageMultiplier);
|
||||
|
||||
@@ -51,6 +51,11 @@ public class BuildPayload implements Payload{
|
||||
build.updatePayload(unitHolder, buildingHolder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyed(){
|
||||
build.onDestroyed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack[] requirements(){
|
||||
return build.block.requirements;
|
||||
|
||||
@@ -54,6 +54,8 @@ public interface Payload extends Position{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
default void destroyed(){};
|
||||
|
||||
/** writes the payload for saving. */
|
||||
void write(Writes write);
|
||||
|
||||
|
||||
@@ -151,6 +151,12 @@ public class PayloadBlock extends Block{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyed(){
|
||||
if(payload != null) payload.destroyed();
|
||||
super.onDestroyed();
|
||||
}
|
||||
|
||||
public boolean blends(int direction){
|
||||
return PayloadBlock.blends(this, direction);
|
||||
}
|
||||
|
||||
@@ -190,6 +190,12 @@ public class PayloadConveyor extends Block{
|
||||
super.draw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyed(){
|
||||
if(item != null) item.destroyed();
|
||||
super.onDestroyed();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
super.draw();
|
||||
|
||||
Reference in New Issue
Block a user