mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-03-07 18:25:41 +00:00
Ensure particles only travel through a given schottky direction ONCE. Also code cleanup
This commit is contained in:
parent
4859904e6c
commit
3a611feff1
@ -3,6 +3,7 @@ package com.hbm.tileentity.machine;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
@ -360,6 +361,9 @@ public class TileEntityHadron extends TileEntityMachineBase implements IEnergyUs
|
||||
}
|
||||
worldObj.newExplosion(null, particle.posX + 0.5, particle.posY + 0.5, particle.posZ + 0.5, 10, false, false);
|
||||
|
||||
//If any particles expire, cancel any succeeding particles, since they'll confuse the player
|
||||
particlesCompleted.clear();
|
||||
|
||||
TileEntityHadron.this.state = reason;
|
||||
TileEntityHadron.this.delay = delayError;
|
||||
TileEntityHadron.this.setExpireStats(reason, particle.momentum, particle.posX, particle.posY, particle.posZ);
|
||||
@ -391,6 +395,10 @@ public class TileEntityHadron extends TileEntityMachineBase implements IEnergyUs
|
||||
//The cheapest valid route to the analysis chamber is then turned into a real particle, consuming power
|
||||
List<TileEntityHadronPower> plugs = new ArrayList<TileEntityHadronPower>();
|
||||
|
||||
//Quantum particles should only traverse a schottky direction ONCE
|
||||
//Keep a list of traversed diodes and directions
|
||||
HashMap<TileEntityHadronDiode, List<ForgeDirection>> history = new HashMap<TileEntityHadronDiode, List<ForgeDirection>>();
|
||||
|
||||
public Particle(ItemStack item1, ItemStack item2, ForgeDirection dir, int posX, int posY, int posZ) {
|
||||
this.item1 = item1.copy();
|
||||
this.item2 = item2.copy();
|
||||
@ -416,6 +424,7 @@ public class TileEntityHadron extends TileEntityMachineBase implements IEnergyUs
|
||||
p.cl1 = cl1;
|
||||
p.expired = expired;
|
||||
p.plugs = new ArrayList<TileEntityHadronPower>(plugs);
|
||||
p.history = new HashMap<TileEntityHadronDiode, List<ForgeDirection>>(history);
|
||||
p.cloned = true;
|
||||
return p;
|
||||
}
|
||||
@ -429,7 +438,7 @@ public class TileEntityHadron extends TileEntityMachineBase implements IEnergyUs
|
||||
if(expired) //just in case
|
||||
return;
|
||||
|
||||
// Recently cloned particles have already set direction, disabling this causes infinite recursion
|
||||
//Recently cloned particles have already a set direction, this prevents infinite recursion
|
||||
if(cloned) {
|
||||
cloned = false;
|
||||
} else {
|
||||
@ -721,18 +730,28 @@ public class TileEntityHadron extends TileEntityMachineBase implements IEnergyUs
|
||||
|
||||
boolean hasTurnedCurrent = false;
|
||||
|
||||
if(!p.history.containsKey(diode))
|
||||
p.history.put(diode, new ArrayList<ForgeDirection>());
|
||||
|
||||
List<ForgeDirection> usedDirections = p.history.get(diode);
|
||||
|
||||
//Instance a new particle for each required fork
|
||||
for(ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if(diode.getConfig(d.ordinal()) == DiodeConfig.OUT) {
|
||||
if(!usedDirections.contains(d) && diode.getConfig(d.ordinal()) == DiodeConfig.OUT) {
|
||||
if(!hasTurnedCurrent) {
|
||||
p.dir = d;
|
||||
hasTurnedCurrent = true;
|
||||
} else {
|
||||
particlesToAdd.add(p.clone(d));
|
||||
Particle clone = p.clone(d);
|
||||
clone.history.get(diode).add(d);
|
||||
particlesToAdd.add(clone);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Add the used direction to the main particle AFTER cloning, so the clones don't get incorrect travel history
|
||||
usedDirections.add(p.dir);
|
||||
|
||||
//If we managed to exit, keep going
|
||||
if(hasTurnedCurrent) return;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user