mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +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.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.hbm.blocks.ModBlocks;
|
import com.hbm.blocks.ModBlocks;
|
||||||
@ -137,10 +138,10 @@ public class TileEntityHadron extends TileEntityMachineBase implements IEnergyUs
|
|||||||
|
|
||||||
particlesToRemove.clear();
|
particlesToRemove.clear();
|
||||||
|
|
||||||
// Sort the virtual particles by momentum, and run through them until we have enough momentum to complete the recipe
|
//Sort the virtual particles by momentum, and run through them until we have enough momentum to complete the recipe
|
||||||
// If we succeed, "collapse" the cheapest particle that had enough momentum
|
//If we succeed, "collapse" the cheapest particle that had enough momentum
|
||||||
// If we fail to make anything, "collapse" the most expensive particle
|
//If we fail to make anything, "collapse" the most expensive particle
|
||||||
if (particles.isEmpty() && !particlesCompleted.isEmpty()) {
|
if(particles.isEmpty() && !particlesCompleted.isEmpty()) {
|
||||||
ItemStack[] result = null;
|
ItemStack[] result = null;
|
||||||
Particle particle = null;
|
Particle particle = null;
|
||||||
|
|
||||||
@ -174,7 +175,7 @@ public class TileEntityHadron extends TileEntityMachineBase implements IEnergyUs
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void process(Particle p, ItemStack[] result) {
|
private void process(Particle p, ItemStack[] result) {
|
||||||
// Collapse this particle to real by consuming power
|
//Collapse this particle to real by consuming power
|
||||||
p.consumePower();
|
p.consumePower();
|
||||||
|
|
||||||
if(result == null) {
|
if(result == null) {
|
||||||
@ -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);
|
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.state = reason;
|
||||||
TileEntityHadron.this.delay = delayError;
|
TileEntityHadron.this.delay = delayError;
|
||||||
TileEntityHadron.this.setExpireStats(reason, particle.momentum, particle.posX, particle.posY, particle.posZ);
|
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
|
//The cheapest valid route to the analysis chamber is then turned into a real particle, consuming power
|
||||||
List<TileEntityHadronPower> plugs = new ArrayList<TileEntityHadronPower>();
|
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) {
|
public Particle(ItemStack item1, ItemStack item2, ForgeDirection dir, int posX, int posY, int posZ) {
|
||||||
this.item1 = item1.copy();
|
this.item1 = item1.copy();
|
||||||
this.item2 = item2.copy();
|
this.item2 = item2.copy();
|
||||||
@ -416,6 +424,7 @@ public class TileEntityHadron extends TileEntityMachineBase implements IEnergyUs
|
|||||||
p.cl1 = cl1;
|
p.cl1 = cl1;
|
||||||
p.expired = expired;
|
p.expired = expired;
|
||||||
p.plugs = new ArrayList<TileEntityHadronPower>(plugs);
|
p.plugs = new ArrayList<TileEntityHadronPower>(plugs);
|
||||||
|
p.history = new HashMap<TileEntityHadronDiode, List<ForgeDirection>>(history);
|
||||||
p.cloned = true;
|
p.cloned = true;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -429,8 +438,8 @@ public class TileEntityHadron extends TileEntityMachineBase implements IEnergyUs
|
|||||||
if(expired) //just in case
|
if(expired) //just in case
|
||||||
return;
|
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) {
|
if(cloned) {
|
||||||
cloned = false;
|
cloned = false;
|
||||||
} else {
|
} else {
|
||||||
changeDirection(this);
|
changeDirection(this);
|
||||||
@ -646,7 +655,7 @@ public class TileEntityHadron extends TileEntityMachineBase implements IEnergyUs
|
|||||||
expire(p, EnumHadronState.ERROR_ANALYSIS_TOO_LONG);
|
expire(p, EnumHadronState.ERROR_ANALYSIS_TOO_LONG);
|
||||||
|
|
||||||
if(p.analysis == 2) {
|
if(p.analysis == 2) {
|
||||||
// Only pop for the first particle
|
//Only pop for the first particle
|
||||||
if(this.state != EnumHadronState.ANALYSIS) {
|
if(this.state != EnumHadronState.ANALYSIS) {
|
||||||
this.worldObj.playSoundEffect(p.posX + 0.5, p.posY + 0.5, p.posZ + 0.5, "fireworks.blast", 2.0F, 2F);
|
this.worldObj.playSoundEffect(p.posX + 0.5, p.posY + 0.5, p.posZ + 0.5, "fireworks.blast", 2.0F, 2F);
|
||||||
NBTTagCompound data = new NBTTagCompound();
|
NBTTagCompound data = new NBTTagCompound();
|
||||||
@ -721,20 +730,30 @@ public class TileEntityHadron extends TileEntityMachineBase implements IEnergyUs
|
|||||||
|
|
||||||
boolean hasTurnedCurrent = false;
|
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
|
//Instance a new particle for each required fork
|
||||||
for(ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
|
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) {
|
if(!hasTurnedCurrent) {
|
||||||
p.dir = d;
|
p.dir = d;
|
||||||
hasTurnedCurrent = true;
|
hasTurnedCurrent = true;
|
||||||
} else {
|
} 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 we managed to exit, keep going
|
||||||
if (hasTurnedCurrent) return;
|
if(hasTurnedCurrent) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//next step is air or the core, proceed
|
//next step is air or the core, proceed
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user