mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-26 14:52:58 +00:00
Some minor cleanup trying to fix what seems to be a state leak
This commit is contained in:
6 files changed
+64
-97
No files matched your search
@@ -42,14 +42,19 @@ public final class FluidRenderer {
|
||||
|
||||
public static DisplayInteger getTankDisplay(RenderData data, double scale) {
|
||||
int maxStages = getStages(data);
|
||||
int stage = Math.min(maxStages, (int) (scale * (float) maxStages));
|
||||
|
||||
int stage = Math.min(maxStages, (int) (scale * maxStages));
|
||||
DisplayInteger[] cachedCenter;
|
||||
if (cachedCenterFluids.containsKey(data)) {
|
||||
DisplayInteger[] ret = cachedCenterFluids.get(data);
|
||||
cachedCenter = cachedCenterFluids.get(data);
|
||||
|
||||
if (ret[stage] != null) {
|
||||
return ret[stage];
|
||||
if (cachedCenter[stage] != null) {
|
||||
return cachedCenter[stage];
|
||||
}
|
||||
} else {
|
||||
cachedCenterFluids.put(data, cachedCenter = new DisplayInteger[maxStages + 1]);
|
||||
}
|
||||
if (maxStages == 0) {
|
||||
maxStages = stage = 1;
|
||||
}
|
||||
|
||||
Model3D toReturn = new Model3D();
|
||||
@@ -57,21 +62,12 @@ public final class FluidRenderer {
|
||||
toReturn.setTexture(MekanismRenderer.getFluidTexture(data.fluidType, FluidType.STILL));
|
||||
|
||||
DisplayInteger display = DisplayInteger.createAndStart();
|
||||
|
||||
if (!cachedCenterFluids.containsKey(data)) {
|
||||
cachedCenterFluids.put(data, new DisplayInteger[maxStages + 1]);
|
||||
}
|
||||
|
||||
cachedCenterFluids.get(data)[stage] = display;
|
||||
|
||||
if (maxStages == 0) {
|
||||
maxStages = stage = 1;
|
||||
}
|
||||
cachedCenter[stage] = display;
|
||||
|
||||
if (data.fluidType.getFluid().getStill(data.fluidType) != null) {
|
||||
toReturn.minX = 0 + .01;
|
||||
toReturn.minY = 0 + .01;
|
||||
toReturn.minZ = 0 + .01;
|
||||
toReturn.minX = 0.01;
|
||||
toReturn.minY = 0.01;
|
||||
toReturn.minZ = 0.01;
|
||||
|
||||
toReturn.maxX = data.length - .01;
|
||||
toReturn.maxY = ((float) stage / (float) maxStages) * data.height - .01;
|
||||
|
||||
@@ -230,6 +230,7 @@ public class MekanismRenderer {
|
||||
return Minecraft.getMinecraft().getRenderPartialTicks();
|
||||
}
|
||||
|
||||
//TODO: Inline
|
||||
public static ResourceLocation getBlocksTexture() {
|
||||
return TextureMap.LOCATION_BLOCKS_TEXTURE;
|
||||
}
|
||||
@@ -343,8 +344,7 @@ public class MekanismRenderer {
|
||||
Arrays.fill(textures, tex);
|
||||
}
|
||||
|
||||
public void setTextures(TextureAtlasSprite down, TextureAtlasSprite up, TextureAtlasSprite north,
|
||||
TextureAtlasSprite south, TextureAtlasSprite west, TextureAtlasSprite east) {
|
||||
public void setTextures(TextureAtlasSprite down, TextureAtlasSprite up, TextureAtlasSprite north, TextureAtlasSprite south, TextureAtlasSprite west, TextureAtlasSprite east) {
|
||||
textures[0] = down;
|
||||
textures[1] = up;
|
||||
textures[2] = north;
|
||||
|
||||
@@ -7,7 +7,6 @@ import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import mekanism.client.render.MekanismRenderer.Model3D;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.BufferBuilder;
|
||||
@@ -254,7 +253,6 @@ public class RenderResizableCuboid {
|
||||
Vec3d transVertex = locationFormula.transformToWorld(vertex);
|
||||
BlockPos pos = convertFloor(transVertex);
|
||||
IBlockState state = access.getBlockState(pos);
|
||||
Block block = state.getBlock();
|
||||
int combindedLight = state.getPackedLightmapCoords(access, pos);
|
||||
|
||||
skyLight[0] = combindedLight / 0x10000;
|
||||
|
||||
@@ -55,12 +55,8 @@ public class RenderTeleporter extends TileEntitySpecialRenderer<TileEntityTelepo
|
||||
toReturn.setTexture(MekanismFluids.Oxygen.getSprite());
|
||||
|
||||
DisplayInteger display = DisplayInteger.createAndStart();
|
||||
|
||||
if (cachedOverlays.containsKey(type)) {
|
||||
cachedOverlays.get(type);
|
||||
} else {
|
||||
cachedOverlays.put(type, display);
|
||||
}
|
||||
//We already know it does not contain type, so add it
|
||||
cachedOverlays.put(type, display);
|
||||
|
||||
switch (type) {
|
||||
case 0: {
|
||||
|
||||
@@ -40,11 +40,17 @@ public class RenderMechanicalPipe extends RenderTransmitterBase<TileEntityMechan
|
||||
}
|
||||
|
||||
float targetScale;
|
||||
|
||||
Fluid fluid;
|
||||
FluidStack fluidStack;
|
||||
if (pipe.getTransmitter().hasTransmitterNetwork()) {
|
||||
targetScale = pipe.getTransmitter().getTransmitterNetwork().fluidScale;
|
||||
FluidNetwork network = pipe.getTransmitter().getTransmitterNetwork();
|
||||
targetScale = network.fluidScale;
|
||||
fluid = network.refFluid;
|
||||
fluidStack = network.buffer;
|
||||
} else {
|
||||
targetScale = (float) pipe.buffer.getFluidAmount() / (float) pipe.buffer.getCapacity();
|
||||
fluidStack = pipe.getBuffer();
|
||||
fluid = fluidStack == null ? null : fluidStack.getFluid();
|
||||
}
|
||||
|
||||
if (Math.abs(pipe.currentScale - targetScale) > 0.01) {
|
||||
@@ -53,22 +59,9 @@ public class RenderMechanicalPipe extends RenderTransmitterBase<TileEntityMechan
|
||||
pipe.currentScale = targetScale;
|
||||
}
|
||||
|
||||
Fluid fluid;
|
||||
FluidStack fluidStack;
|
||||
|
||||
if (pipe.getTransmitter().hasTransmitterNetwork()) {
|
||||
fluid = pipe.getTransmitter().getTransmitterNetwork().refFluid;
|
||||
fluidStack = pipe.getTransmitter().getTransmitterNetwork().buffer;
|
||||
} else {
|
||||
fluidStack = pipe.getBuffer();
|
||||
fluid = fluidStack == null ? null : fluidStack.getFluid();
|
||||
}
|
||||
|
||||
float scale = Math.min(pipe.currentScale, 1);
|
||||
|
||||
if (scale > 0.01 && fluid != null) {
|
||||
MekanismRenderHelper renderHelper = initHelper().disableBlend();
|
||||
|
||||
if (fluidStack != null) {
|
||||
renderHelper.enableGlow(fluidStack).color(fluidStack);
|
||||
} else {
|
||||
@@ -79,47 +72,35 @@ public class RenderMechanicalPipe extends RenderTransmitterBase<TileEntityMechan
|
||||
renderHelper.translate(x, y, z);
|
||||
|
||||
boolean gas = fluid.isGaseous();
|
||||
|
||||
for (EnumFacing side : EnumFacing.VALUES) {
|
||||
if (pipe.getConnectionType(side) == ConnectionType.NORMAL) {
|
||||
DisplayInteger[] displayLists = getListAndRender(side, fluidStack);
|
||||
|
||||
if (displayLists != null) {
|
||||
if (!gas) {
|
||||
displayLists[Math.max(3, (int) (scale * (stages - 1)))].render();
|
||||
} else {
|
||||
renderHelper.colorAlpha(scale);
|
||||
displayLists[stages - 1].render();
|
||||
}
|
||||
}
|
||||
renderDisplayLists(getListAndRender(side, fluidStack), renderHelper, scale, gas);
|
||||
} else if (pipe.getConnectionType(side) != ConnectionType.NONE) {
|
||||
renderHelper.translateAll(0.5);
|
||||
Tessellator tessellator = Tessellator.getInstance();
|
||||
BufferBuilder worldRenderer = tessellator.getBuffer();
|
||||
|
||||
if (renderFluidInOut(worldRenderer, side, pipe)) {
|
||||
tessellator.draw();
|
||||
}
|
||||
|
||||
renderHelper.translateAll(-0.5);
|
||||
}
|
||||
}
|
||||
|
||||
DisplayInteger[] displayLists = getListAndRender(null, fluidStack);
|
||||
|
||||
if (displayLists != null) {
|
||||
if (!gas) {
|
||||
displayLists[Math.max(3, (int) (scale * (stages - 1)))].render();
|
||||
} else {
|
||||
renderHelper.colorAlpha(scale);
|
||||
displayLists[stages - 1].render();
|
||||
}
|
||||
}
|
||||
|
||||
renderDisplayLists(getListAndRender(null, fluidStack), renderHelper, scale, gas);
|
||||
renderHelper.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
private void renderDisplayLists(DisplayInteger[] displayLists, MekanismRenderHelper renderHelper, float scale, boolean gas) {
|
||||
if (displayLists != null) {
|
||||
if (gas) {
|
||||
renderHelper.colorAlpha(scale);
|
||||
displayLists[stages - 1].render();
|
||||
} else {
|
||||
displayLists[Math.max(3, (int) (scale * (stages - 1)))].render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private DisplayInteger[] getListAndRender(EnumFacing side, FluidStack fluid) {
|
||||
if (fluid == null) {
|
||||
return null;
|
||||
@@ -249,10 +230,8 @@ public class RenderMechanicalPipe extends RenderTransmitterBase<TileEntityMechan
|
||||
c.setRGBFromInt(color);
|
||||
}
|
||||
renderTransparency(renderer, tex, getModelForSide(pipe, side), c);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -56,14 +56,14 @@ public class TileEntityDynamicTank extends TileEntityMultiblock<SynchronizedTank
|
||||
public void onUpdate() {
|
||||
super.onUpdate();
|
||||
if (world.isRemote) {
|
||||
if (structure != null && clientHasStructure && isRendering) {
|
||||
float targetScale = (float) (structure.fluidStored != null ? structure.fluidStored.amount : 0) / clientCapacity;
|
||||
if (Math.abs(prevScale - targetScale) > 0.01) {
|
||||
prevScale = (9 * prevScale + targetScale) / 10;
|
||||
if (clientHasStructure && isRendering) {
|
||||
if (structure != null) {
|
||||
float targetScale = (float) (structure.fluidStored != null ? structure.fluidStored.amount : 0) / clientCapacity;
|
||||
if (Math.abs(prevScale - targetScale) > 0.01) {
|
||||
prevScale = (9 * prevScale + targetScale) / 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!clientHasStructure || !isRendering) {
|
||||
} else {
|
||||
for (ValveData data : valveViewing) {
|
||||
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank) data.location.getTileEntity(world);
|
||||
if (tileEntity != null) {
|
||||
@@ -72,29 +72,27 @@ public class TileEntityDynamicTank extends TileEntityMultiblock<SynchronizedTank
|
||||
}
|
||||
valveViewing.clear();
|
||||
}
|
||||
} else {
|
||||
if (structure != null) {
|
||||
if (structure.fluidStored != null && structure.fluidStored.amount <= 0) {
|
||||
structure.fluidStored = null;
|
||||
markDirty();
|
||||
}
|
||||
if (isRendering) {
|
||||
boolean needsValveUpdate = false;
|
||||
for (ValveData data : structure.valves) {
|
||||
if (data.activeTicks > 0) {
|
||||
data.activeTicks--;
|
||||
}
|
||||
if (data.activeTicks > 0 != data.prevActive) {
|
||||
needsValveUpdate = true;
|
||||
}
|
||||
data.prevActive = data.activeTicks > 0;
|
||||
} else if (structure != null) {
|
||||
if (structure.fluidStored != null && structure.fluidStored.amount <= 0) {
|
||||
structure.fluidStored = null;
|
||||
markDirty();
|
||||
}
|
||||
if (isRendering) {
|
||||
boolean needsValveUpdate = false;
|
||||
for (ValveData data : structure.valves) {
|
||||
if (data.activeTicks > 0) {
|
||||
data.activeTicks--;
|
||||
}
|
||||
if (needsValveUpdate || structure.needsRenderUpdate()) {
|
||||
sendPacketToRenderer();
|
||||
if (data.activeTicks > 0 != data.prevActive) {
|
||||
needsValveUpdate = true;
|
||||
}
|
||||
structure.prevFluid = structure.fluidStored != null ? structure.fluidStored.copy() : null;
|
||||
manageInventory();
|
||||
data.prevActive = data.activeTicks > 0;
|
||||
}
|
||||
if (needsValveUpdate || structure.needsRenderUpdate()) {
|
||||
sendPacketToRenderer();
|
||||
}
|
||||
structure.prevFluid = structure.fluidStored != null ? structure.fluidStored.copy() : null;
|
||||
manageInventory();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user