Merge pull request #1924 from Dash1269/ntmain-pa-detector-fix

PA Detector fixes and improved diagnostics
This commit is contained in:
HbmMods 2025-02-06 15:00:30 +01:00 committed by GitHub
commit fe9808f621
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 102 additions and 86 deletions

View File

@ -136,6 +136,12 @@ public class ParticleAcceleratorRecipes extends SerializableRecipe {
this.output1 = out1; this.output1 = out1;
this.output2 = out2; this.output2 = out2;
} }
// it makes more sense to have this logic here
public boolean matchesRecipe(ItemStack in1, ItemStack in2) {
return this.input1.matchesRecipe(in1, true) && this.input2.matchesRecipe(in2, true)
|| this.input1.matchesRecipe(in2, true) && this.input2.matchesRecipe(in1, true);
}
} }
@Override @Override

View File

@ -112,38 +112,42 @@ public class TileEntityPADetector extends TileEntityCooledBase implements IGUIPr
particle.invalid = true; particle.invalid = true;
//particle will crash if not perfectly focused //particle will crash if not perfectly focused
if(particle.defocus > 0) { particle.crash(PAState.CRASH_DEFOCUS); return; } if(particle.defocus > 0) { particle.crash(PAState.CRASH_DEFOCUS); return; }
if(this.power < this.usage) { particle.crash(PAState.CRASH_NOPOWER); return; } if(this.power < usage) { particle.crash(PAState.CRASH_NOPOWER); return; }
if(!isCool()) { particle.crash(PAState.CRASH_NOCOOL); return; } if(!isCool()) { particle.crash(PAState.CRASH_NOCOOL); return; }
for(ParticleAcceleratorRecipe recipe : ParticleAcceleratorRecipes.recipes) { for(ParticleAcceleratorRecipe recipe : ParticleAcceleratorRecipes.recipes) {
if(!recipe.matchesRecipe(particle.input1, particle.input2)) continue; // another W for continue
if(particle.momentum >= recipe.momentum && if(particle.momentum < recipe.momentum) {
((recipe.input1.matchesRecipe(particle.input1, true) && recipe.input2.matchesRecipe(particle.input2, true)) || this.power -= usage;
(recipe.input1.matchesRecipe(particle.input2, true) && recipe.input2.matchesRecipe(particle.input1, true)))) { particle.crash(PAState.CRASH_UNDERSPEED);
if(canAccept(recipe)) {
if(recipe.output1.getItem().hasContainerItem(recipe.output1)) this.decrStackSize(1, 1);
if(recipe.output2 != null && recipe.output2.getItem().hasContainerItem(recipe.output2)) this.decrStackSize(2, 1);
if(slots[3] == null) {
slots[3] = recipe.output1.copy();
} else {
slots[3].stackSize += recipe.output1.stackSize;
}
if(recipe.output2 != null) {
if(slots[4] == null) {
slots[4] = recipe.output2.copy();
} else {
slots[4].stackSize += recipe.output2.stackSize;
}
}
}
particle.crash(PAState.SUCCESS);
return; return;
} }
if(canAccept(recipe)) {
if(recipe.output1.getItem().hasContainerItem(recipe.output1)) this.decrStackSize(1, 1);
if(recipe.output2 != null && recipe.output2.getItem().hasContainerItem(recipe.output2)) this.decrStackSize(2, 1);
if(slots[3] == null) {
slots[3] = recipe.output1.copy();
} else {
slots[3].stackSize += recipe.output1.stackSize;
}
if(recipe.output2 != null) {
if(slots[4] == null) {
slots[4] = recipe.output2.copy();
} else {
slots[4].stackSize += recipe.output2.stackSize;
}
}
}
this.power -= usage;
particle.crash(PAState.SUCCESS);
return;
} }
this.power -= this.usage; this.power -= usage;
particle.crash(PAState.CRASH_NORECIPE);
} }
public boolean canAccept(ParticleAcceleratorRecipe recipe) { public boolean canAccept(ParticleAcceleratorRecipe recipe) {

View File

@ -34,7 +34,7 @@ public class TileEntityPASource extends TileEntityCooledBase implements IGUIProv
public int debugSpeed; public int debugSpeed;
public static enum PAState { public enum PAState {
IDLE(0x8080ff), //no particle active IDLE(0x8080ff), //no particle active
RUNNING(0xffff00), //running without further issue RUNNING(0xffff00), //running without further issue
SUCCESS(0x00ff00), //completed recipe SUCCESS(0x00ff00), //completed recipe
@ -45,11 +45,13 @@ public class TileEntityPASource extends TileEntityCooledBase implements IGUIProv
CRASH_NOCOOL(0xff0000), //crash due to lack of cooling CRASH_NOCOOL(0xff0000), //crash due to lack of cooling
CRASH_NOPOWER(0xff0000), //crash due to power outage CRASH_NOPOWER(0xff0000), //crash due to power outage
CRASH_NOCOIL(0xff0000), //crash due to no coil installed (QP, DP) CRASH_NOCOIL(0xff0000), //crash due to no coil installed (QP, DP)
CRASH_OVERSPEED(0xff0000); //crash due to coil max speed exceeded (QP, DP) CRASH_OVERSPEED(0xff0000), //crash due to coil max speed exceeded (QP, DP)
CRASH_UNDERSPEED(0xff0000), //crash due to recipe momentum requirements not being met
CRASH_NORECIPE(0xff0000); //crash due to failing to match recipe
public int color; public final int color;
private PAState(int color) { PAState(int color) {
this.color = color; this.color = color;
} }
} }

View File

@ -4865,6 +4865,10 @@ pa.crash_nocoil=No coils!
pa.crash_nocoil.desc=The particle has entered a dipole$or quadrupole which lacks coils.$Install coils to allow this part to work. pa.crash_nocoil.desc=The particle has entered a dipole$or quadrupole which lacks coils.$Install coils to allow this part to work.
pa.crash_overspeed=Overspeed! pa.crash_overspeed=Overspeed!
pa.crash_overspeed.desc=The particle has entered a dipole$or quadrupole, while its speed exceeded$the coil's rating. Install higher$tier coils, or configure the dipoles$to leave the accelerator ring sooner. pa.crash_overspeed.desc=The particle has entered a dipole$or quadrupole, while its speed exceeded$the coil's rating. Install higher$tier coils, or configure the dipoles$to leave the accelerator ring sooner.
pa.crash_norecipe=No recipe!
pa.crash_norecipe.desc=The particle entered a detector with an invalid set of inputs. Ensure the particle source inputs match a valid recipe.
pa.crash_underspeed=Underspeed!
pa.crash_underspeed.desc=The particle entered a detector with insufficient speed to perform the current recipe. Ensure the accelerator is configured correctly for the recipe.
potion.hbm_bang=! ! ! potion.hbm_bang=! ! !
potion.hbm_death=Astolfization potion.hbm_death=Astolfization