From 445957588fdc2f14ab1e16ca8188f11900bcde28 Mon Sep 17 00:00:00 2001 From: asiekierka Date: Fri, 10 Apr 2015 20:34:55 +0200 Subject: [PATCH] cleanup, add warning checks for invalid item/block names in MappingRegistry --- .../api/blueprints/MappingRegistry.java | 28 ++++++++++++++++--- .../transport/network/PacketFluidUpdate.java | 11 +++++--- .../transport/render/PipeRendererTESR.java | 22 ++++++--------- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/api/buildcraft/api/blueprints/MappingRegistry.java b/api/buildcraft/api/blueprints/MappingRegistry.java index dd91cec0..be9d2b8a 100755 --- a/api/buildcraft/api/blueprints/MappingRegistry.java +++ b/api/buildcraft/api/blueprints/MappingRegistry.java @@ -243,8 +243,12 @@ public class MappingRegistry { for (Block b : idToBlock) { NBTTagCompound sub = new NBTTagCompound(); - sub.setString("name", - Block.blockRegistry.getNameForObject(b)); + String name = Block.blockRegistry.getNameForObject(b); + if (name == null || name.length() == 0) { + BCLog.logger.error("Block " + b.getUnlocalizedName() + " (" + b.getClass().getName() + ") has an empty registry name! This is a bug!"); + } else { + sub.setString("name", name); + } blocksMapping.appendTag(sub); } @@ -254,8 +258,12 @@ public class MappingRegistry { for (Item i : idToItem) { NBTTagCompound sub = new NBTTagCompound(); - sub.setString("name", - Item.itemRegistry.getNameForObject(i)); + String name = Item.itemRegistry.getNameForObject(i); + if (name == null || name.length() == 0) { + BCLog.logger.error("Item " + i.getUnlocalizedName() + " (" + i.getClass().getName() + ") has an empty registry name! This is a bug!"); + } else { + sub.setString("name", name); + } itemsMapping.appendTag(sub); } @@ -278,6 +286,12 @@ public class MappingRegistry { for (int i = 0; i < blocksMapping.tagCount(); ++i) { NBTTagCompound sub = blocksMapping.getCompoundTagAt(i); + if (!sub.hasKey("name")) { + // Keeping the order correct + idToBlock.add(null); + BCLog.logger.log(Level.WARN, "Can't load a block - corrupt blueprint!"); + continue; + } String name = sub.getString("name"); Block b = null; @@ -299,6 +313,12 @@ public class MappingRegistry { for (int i = 0; i < itemsMapping.tagCount(); ++i) { NBTTagCompound sub = itemsMapping.getCompoundTagAt(i); + if (!sub.hasKey("name")) { + // Keeping the order correct + idToItem.add(null); + BCLog.logger.log(Level.WARN, "Can't load an item - corrupt blueprint!"); + continue; + } String name = sub.getString("name"); Item item = null; diff --git a/common/buildcraft/transport/network/PacketFluidUpdate.java b/common/buildcraft/transport/network/PacketFluidUpdate.java index 618e94c0..501440a7 100644 --- a/common/buildcraft/transport/network/PacketFluidUpdate.java +++ b/common/buildcraft/transport/network/PacketFluidUpdate.java @@ -86,14 +86,18 @@ public class PacketFluidUpdate extends PacketCoordinates { if (delta.get(dir.ordinal() * FLUID_DATA_NUM + FLUID_ID_BIT)) { int id = data.readShort(); int amt = renderCache[dir.ordinal()] != null ? renderCache[dir.ordinal()].amount : 0; - int color = data.readInt(); + int color = id != 0 ? data.readInt() : 0xFFFFFF; renderCache[dir.ordinal()] = new FluidRenderData(id, amt, color); } if (delta.get(dir.ordinal() * FLUID_DATA_NUM + FLUID_AMOUNT_BIT)) { + int amt = Math.min(transLiq.getCapacity(), data.readUnsignedShort()); + if (renderCache[dir.ordinal()] != null) { - renderCache[dir.ordinal()].amount = Math.min(transLiq.getCapacity(), data.readUnsignedShort()); + renderCache[dir.ordinal()].amount = amt; + } else { + renderCache[dir.ordinal()] = new FluidRenderData(0, amt, 0xFFFFFF); } } } @@ -111,12 +115,11 @@ public class PacketFluidUpdate extends PacketCoordinates { FluidRenderData liquid = renderCache[dir.ordinal()]; if (delta.get(dir.ordinal() * FLUID_DATA_NUM + FLUID_ID_BIT)) { - if (liquid != null) { + if (liquid != null && liquid.fluidID != 0) { data.writeShort(liquid.fluidID); data.writeInt(liquid.color); } else { data.writeShort(0); - data.writeInt(0xFFFFFF); } } if (delta.get(dir.ordinal() * FLUID_DATA_NUM + FLUID_AMOUNT_BIT)) { diff --git a/common/buildcraft/transport/render/PipeRendererTESR.java b/common/buildcraft/transport/render/PipeRendererTESR.java index 139041d7..8f140ded 100644 --- a/common/buildcraft/transport/render/PipeRendererTESR.java +++ b/common/buildcraft/transport/render/PipeRendererTESR.java @@ -108,17 +108,23 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { return displayFluidLists.get(liquidId); } + Fluid fluid = FluidRegistry.getFluid(liquidId); + + if (fluid == null) { + return null; + } + DisplayFluidList d = new DisplayFluidList(); displayFluidLists.put(liquidId, d); RenderInfo block = new RenderInfo(); - Fluid fluid = FluidRegistry.getFluid(liquidId); if (fluid.getBlock() != null) { block.baseBlock = fluid.getBlock(); } else { block.baseBlock = Blocks.water; } + block.texture = fluid.getStillIcon(); float size = CoreConstants.PIPE_MAX_POS - CoreConstants.PIPE_MIN_POS; @@ -706,7 +712,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { continue; } - DisplayFluidList d = getListFromBuffer(fluidRenderData, pipe.container.getWorldObj()); + DisplayFluidList d = getDisplayFluidLists(fluidRenderData.fluidID, pipe.container.getWorldObj()); if (d == null) { continue; @@ -749,7 +755,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { FluidRenderData fluidRenderData = trans.renderCache[ForgeDirection.UNKNOWN.ordinal()]; if (fluidRenderData != null && fluidRenderData.amount > 0) { - DisplayFluidList d = getListFromBuffer(fluidRenderData, pipe.container.getWorldObj()); + DisplayFluidList d = getDisplayFluidLists(fluidRenderData.fluidID, pipe.container.getWorldObj()); if (d != null) { int stage = (int) ((float) fluidRenderData.amount / (float) (trans.getCapacity()) * (LIQUID_STAGES - 1)); @@ -772,16 +778,6 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer { GL11.glPopMatrix(); } - private DisplayFluidList getListFromBuffer(FluidRenderData stack, World world) { - int liquidId = stack.fluidID; - - if (liquidId == 0) { - return null; - } - - return getDisplayFluidLists(liquidId, world); - } - private void renderSolids(Pipe pipe, double x, double y, double z) { GL11.glPushMatrix();