Convert to threadsafe molten metal list (#120)

* Convert to threadsafe molten metal list

* back to foreach

* wrap in sync bloc
This commit is contained in:
Caedis authored and GitHub committed 2024-07-10 14:06:07 -05:00
1 parent 4f9ba9d0b7
commit c2c2f14596
4 files changed
+47 -43

No files matched your search

@@ -19,7 +19,7 @@ public class AlloyMix {
* public boolean matches(List liquids) { ArrayList list = new ArrayList(mixers); return false; }
*/
public FluidStack mix(ArrayList<FluidStack> liquids) {
public FluidStack mix(List<FluidStack> liquids) {
ArrayList<FluidStack> copyMix = new ArrayList<>(mixers);
ArrayList<Integer> effectiveAmount = new ArrayList<>();
@@ -171,7 +171,7 @@ public class Smeltery {
return instance.renderIndex.get(new ItemMetaWrapper(input));
}
public static ArrayList<FluidStack> mixMetals(ArrayList<FluidStack> moltenMetal) {
public static ArrayList<FluidStack> mixMetals(List<FluidStack> moltenMetal) {
ArrayList<FluidStack> liquids = new ArrayList<>();
for (AlloyMix alloy : instance.alloys) {
FluidStack liquid = alloy.mix(moltenMetal);
@@ -1,6 +1,7 @@
package tconstruct.smeltery.logic;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
@@ -82,7 +83,7 @@ public class SmelteryLogic extends InventoryLogic implements IActiveLogic, IFaci
public int[] meltingTemps; // values are multiplied by 10
private int tick;
public ArrayList<FluidStack> moltenMetal = new ArrayList<>();
public final List<FluidStack> moltenMetal = Collections.synchronizedList(new ArrayList<>());
public int maxLiquid;
public int currentLiquid;
@@ -59,50 +59,53 @@ public class SmelteryRender implements ISimpleBlockRenderingHandler {
float base = 0F;
int yBase = 0;
int liquidBase = 0;
for (FluidStack liquid : logic.moltenMetal) {
int liquidSize = liquid.amount;
while (liquidSize > 0) {
int cap = logic.getCapacityPerLayer();
int room = cap - liquidBase;
int countSize = Math.min(liquidSize, room);
liquidSize -= countSize;
float height = countSize > cap ? 1.0F : (float) countSize / (float) cap;
float renderBase = base;
float renderHeight = height + base;
base += height;
liquidBase += countSize;
synchronized (logic.moltenMetal) {
for (FluidStack liquid : logic.moltenMetal) {
int liquidSize = liquid.amount;
while (liquidSize > 0) {
int cap = logic.getCapacityPerLayer();
int room = cap - liquidBase;
int countSize = Math.min(liquidSize, room);
liquidSize -= countSize;
if (renderHeight < 0.01) renderHeight = 0.01f;
float height = countSize > cap ? 1.0F : (float) countSize / (float) cap;
float renderBase = base;
float renderHeight = height + base;
base += height;
liquidBase += countSize;
renderer.setRenderBounds(0, renderBase, 0, 1, renderHeight, 1);
Fluid fluid = liquid.getFluid();
for (int xi = from.x; xi <= to.x; xi++) for (int zi = from.z; zi <= to.z; zi++) {
float minX = xi == from.x ? -0.001F : 0F;
float minZ = zi == from.z ? -0.001F : 0F;
float maxX = xi == to.x ? 1.001F : 1F;
float maxZ = zi == to.z ? 1.001F : 1F;
renderer.setRenderBounds(minX, renderBase, minZ, maxX, renderHeight, maxZ);
if (fluid.canBePlacedInWorld()) BlockSkinRenderHelper
.renderMetadataBlock(fluid.getBlock(), 0, xi, from.y + yBase, zi, renderer, world);
else BlockSkinRenderHelper.renderLiquidBlock(
fluid.getStillIcon(),
fluid.getFlowingIcon(),
xi,
from.y + yBase,
zi,
renderer,
world,
false,
fluid.getColor(liquid));
if (renderHeight < 0.01) renderHeight = 0.01f;
renderer.setRenderBounds(0, renderBase, 0, 1, renderHeight, 1);
Fluid fluid = liquid.getFluid();
for (int xi = from.x; xi <= to.x; xi++) for (int zi = from.z; zi <= to.z; zi++) {
float minX = xi == from.x ? -0.001F : 0F;
float minZ = zi == from.z ? -0.001F : 0F;
float maxX = xi == to.x ? 1.001F : 1F;
float maxZ = zi == to.z ? 1.001F : 1F;
renderer.setRenderBounds(minX, renderBase, minZ, maxX, renderHeight, maxZ);
if (fluid.canBePlacedInWorld()) BlockSkinRenderHelper
.renderMetadataBlock(fluid.getBlock(), 0, xi, from.y + yBase, zi, renderer, world);
else BlockSkinRenderHelper.renderLiquidBlock(
fluid.getStillIcon(),
fluid.getFlowingIcon(),
xi,
from.y + yBase,
zi,
renderer,
world,
false,
fluid.getColor(liquid));
}
if (countSize == room) {
base = 0F;
yBase++;
liquidBase = 0;
}
ret = true;
}
if (countSize == room) {
base = 0F;
yBase++;
liquidBase = 0;
}
ret = true;
}
}
}