cleanup, add warning checks for invalid item/block names in MappingRegistry

This commit is contained in:
asiekierka 2015-04-10 20:34:55 +02:00
parent 5c767249a6
commit 445957588f
3 changed files with 40 additions and 21 deletions

View file

@ -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;

View file

@ -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)) {

View file

@ -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<PipeTransportItems> pipe, double x, double y, double z) {
GL11.glPushMatrix();