Skip to content

Commit

Permalink
Some null checks to avoid outright crashing with Angelica, future thr…
Browse files Browse the repository at this point in the history
…ead saftey to come (#150)
  • Loading branch information
mitchej123 authored Feb 22, 2024
1 parent 5265340 commit 05d31b2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/main/java/crazypants/enderio/conduit/ConduitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static boolean isSolidFacadeRendered(IConduitBundle bundle, EntityPlayer
}

public static boolean isFacadeHidden(IConduitBundle bundle, EntityPlayer player) {
return bundle.getFacadeId() != null && shouldHeldItemHideFacades(player);
return bundle != null && bundle.getFacadeId() != null && shouldHeldItemHideFacades(player);
}

public static ConduitDisplayMode getDisplayMode(EntityPlayer player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ public ConduitBundleRenderer(float conduitScale) {}
public void renderTileEntityAt(TileEntity te, double x, double y, double z, float partialTick) {
IConduitBundle bundle = (IConduitBundle) te;
EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;
if (bundle.hasFacade() && bundle.getFacadeId().isOpaqueCube() && !ConduitUtil.isFacadeHidden(bundle, player)) {
if (bundle == null || (bundle.hasFacade() && bundle.getFacadeId().isOpaqueCube()
&& !ConduitUtil.isFacadeHidden(bundle, player))) {
return;
}
final Tessellator tessellator = Tessellator.instance;

float brightness = -1;
for (IConduit con : bundle.getConduits()) {
Expand All @@ -84,15 +86,15 @@ public void renderTileEntityAt(TileEntity te, double x, double y, double z, floa
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);

Tessellator.instance.startDrawingQuads();
tessellator.startDrawingQuads();
}
renderer.renderDynamicEntity(this, bundle, con, x, y, z, partialTick, brightness);
}
}
}

if (brightness != -1) {
Tessellator.instance.draw();
tessellator.draw();

GL11.glShadeModel(GL11.GL_FLAT);
GL11.glPopMatrix();
Expand All @@ -104,6 +106,7 @@ public void renderTileEntityAt(TileEntity te, double x, double y, double z, floa
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId,
RenderBlocks rb) {

final Tessellator tessellator = Tessellator.instance;
int pass = RenderPassHelper.getBlockRenderPass();
if (pass == 1) {
// If the MC renderer is told that an alpha pass is required ( see
Expand All @@ -113,10 +116,10 @@ public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block b
// around is to ensure we always render something in this pass. Throwing
// in a polygon with a 0 area does the job
// See: https://github.com/MinecraftForge/MinecraftForge/issues/981
Tessellator.instance.addVertexWithUV(x, y, z, 0, 0);
Tessellator.instance.addVertexWithUV(x, y, z, 0, 0);
Tessellator.instance.addVertexWithUV(x, y, z, 0, 0);
Tessellator.instance.addVertexWithUV(x, y, z, 0, 0);
tessellator.addVertexWithUV(x, y, z, 0, 0);
tessellator.addVertexWithUV(x, y, z, 0, 0);
tessellator.addVertexWithUV(x, y, z, 0, 0);
tessellator.addVertexWithUV(x, y, z, 0, 0);
}

IConduitBundle bundle = (IConduitBundle) world.getTileEntity(x, y, z);
Expand All @@ -125,7 +128,7 @@ public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block b
boolean renderedFacade = renderFacade(x, y, z, pass, rb, bundle, player);
boolean renderConduit = !renderedFacade || ConduitUtil.isFacadeHidden(bundle, player);

if (renderConduit && (pass == 0 || rb.overrideBlockTexture != null)) {
if (bundle != null && renderConduit && (pass == 0 || rb.overrideBlockTexture != null)) {
BlockCoord loc = bundle.getLocation();
float brightness;
if (!Config.updateLightingWhenHidingFacades && bundle.hasFacade()
Expand All @@ -138,17 +141,21 @@ public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block b
return true;
}

return renderedFacade || (bundle.hasFacade() && !bundle.getFacadeId().isOpaqueCube());
return renderedFacade || (bundle != null && bundle.hasFacade() && !bundle.getFacadeId().isOpaqueCube());
}

private boolean renderFacade(int x, int y, int z, int pass, RenderBlocks rb, IConduitBundle bundle,
EntityClientPlayerMP player) {
boolean res = false;
if (bundle == null) {
return false;
}
final Tessellator tessellator = Tessellator.instance;
if (bundle.hasFacade()) {
res = true;
Block facadeId = bundle.getFacadeId();
if (ConduitUtil.isFacadeHidden(bundle, player)) {
Tessellator.instance.setColorOpaque_F(1, 1, 1);
tessellator.setColorOpaque_F(1, 1, 1);
bundle.setFacadeId(null, false);
bundle.setFacadeRenderAs(FacadeRenderState.WIRE_FRAME);

Expand Down Expand Up @@ -192,15 +199,17 @@ private boolean renderFacade(int x, int y, int z, int pass, RenderBlocks rb, ICo
public void renderConduits(IConduitBundle bundle, double x, double y, double z, float partialTick, float brightness,
RenderBlocks rb) {

Tessellator tessellator = Tessellator.instance;
if (bundle == null) return;

final Tessellator tessellator = Tessellator.instance;
tessellator.setColorOpaque_F(1, 1, 1);
tessellator.addTranslation((float) x, (float) y, (float) z);

// Conduits
Set<ForgeDirection> externals = new HashSet<ForgeDirection>();
Set<ForgeDirection> externals = new HashSet<>();
EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;

List<BoundingBox> wireBounds = new ArrayList<BoundingBox>();
List<BoundingBox> wireBounds = new ArrayList<>();

for (IConduit con : bundle.getConduits()) {

Expand All @@ -225,7 +234,8 @@ public void renderConduits(IConduitBundle bundle, double x, double y, double z,
// Internal conectors between conduits
List<CollidableComponent> connectors = bundle.getConnectors();
List<CollidableComponent> rendered = Lists.newArrayList();
for (CollidableComponent component : connectors) {
for (int i = 0; i < connectors.size(); i++) {
final CollidableComponent component = connectors.get(i);
if (component.conduitType != null) {
IConduit conduit = bundle.getConduit(component.conduitType);
if (conduit != null) {
Expand Down Expand Up @@ -261,12 +271,13 @@ public void renderConduits(IConduitBundle bundle, double x, double y, double z,
}
}
// render these after the 'normal' conduits so help with proper blending
for (BoundingBox wireBound : wireBounds) {
Tessellator.instance.setColorRGBA_F(1, 1, 1, 0.25f);
for (int i = 0; i < wireBounds.size(); i++) {
final BoundingBox wireBound = wireBounds.get(i);
tessellator.setColorRGBA_F(1, 1, 1, 0.25f);
CubeRenderer.render(wireBound, EnderIO.blockConduitFacade.getIcon(0, 0));
}

Tessellator.instance.setColorRGBA_F(1, 1, 1, 1f);
tessellator.setColorRGBA_F(1, 1, 1, 1f);
// External connection terminations
if (rb.overrideBlockTexture == null) {
for (ForgeDirection dir : externals) {
Expand All @@ -279,7 +290,8 @@ public void renderConduits(IConduitBundle bundle, double x, double y, double z,
private void renderExternalConnection(ForgeDirection dir) {
IIcon tex = EnderIO.blockConduitBundle.getConnectorIcon(ConduitConnectorType.EXTERNAL);
BoundingBox[] bbs = ConduitGeometryUtil.instance.getExternalConnectorBoundingBoxes(dir);
for (BoundingBox bb : bbs) {
for (int i = 0; i < bbs.length; i++) {
final BoundingBox bb = bbs[i];
CubeRenderer.render(bb, tex, true);
}
}
Expand Down

0 comments on commit 05d31b2

Please sign in to comment.