From bf09121354b4d1bc3c34a86eac9e42d54d06724e Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Sun, 2 Oct 2011 04:25:21 +0100 Subject: [PATCH] Attempt to fix any damage caused by misplaced tile entities --- src/main/java/net/minecraft/server/Chunk.java | 5 +- .../net/minecraft/server/WorldServer.java | 56 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java index 4982e6d664..939fa69f90 100644 --- a/src/main/java/net/minecraft/server/Chunk.java +++ b/src/main/java/net/minecraft/server/Chunk.java @@ -605,7 +605,10 @@ public class Chunk { tileentity.n(); this.tileEntities.put(chunkposition, tileentity); } else { - System.out.println("Attempted to place a tile entity where there was no entity tile!"); + // CraftBukkit start + System.out.println("Attempted to place a tile entity (" + tileentity + ") at " + tileentity.x + "," + tileentity.y + "," + tileentity.z + + " (" + org.bukkit.Material.getMaterial(getTypeId(i, j, k)) + ") where there was no entity tile!"); + // CraftBukkit end } } diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java index fcc3fd8212..569190c8b4 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -36,6 +36,62 @@ public class WorldServer extends World implements BlockChangeDelegate { return height; } + @Override + public TileEntity getTileEntity(int i, int j, int k) { + TileEntity result = super.getTileEntity(i, j, k); + int type = getTypeId(i, j, k); + + if (type == Block.CHEST.id) { + if (!(result instanceof TileEntityChest)) { + result = fixTileEntity(i, j, k, type, result); + } + } else if (type == Block.FURNACE.id) { + if (!(result instanceof TileEntityFurnace)) { + result = fixTileEntity(i, j, k, type, result); + } + } else if (type == Block.PISTON_MOVING.id) { + if (!(result instanceof TileEntityPiston)) { + result = fixTileEntity(i, j, k, type, result); + } + } else if (type == Block.DISPENSER.id) { + if (!(result instanceof TileEntityDispenser)) { + result = fixTileEntity(i, j, k, type, result); + } + } else if (type == Block.JUKEBOX.id) { + if (!(result instanceof TileEntityRecordPlayer)) { + result = fixTileEntity(i, j, k, type, result); + } + } else if (type == Block.NOTE_BLOCK.id) { + if (!(result instanceof TileEntityNote)) { + result = fixTileEntity(i, j, k, type, result); + } + } else if (type == Block.MOB_SPAWNER.id) { + if (!(result instanceof TileEntityMobSpawner)) { + result = fixTileEntity(i, j, k, type, result); + } + } else if ((type == Block.SIGN_POST.id) || (type == Block.WALL_SIGN.id)) { + if (!(result instanceof TileEntitySign)) { + result = fixTileEntity(i, j, k, type, result); + } + } + + return result; + } + + private TileEntity fixTileEntity(int x, int y, int z, int type, TileEntity found) { + getServer().getLogger().severe("Block at " + x + "," + y + "," + z + " is " + org.bukkit.Material.getMaterial(type).toString() + " but has " + found + ". " + + "Bukkit will attempt to fix this, but there may be additional damage that we cannot recover."); + + if (Block.byId[type] instanceof BlockContainer) { + TileEntity replacement = ((BlockContainer)Block.byId[type]).a_(); + setTileEntity(x, y, z, replacement); + return replacement; + } else { + getServer().getLogger().severe("Don't know how to fix for this type... Can't do anything! :("); + return found; + } + } + public final int dimension; public EntityTracker tracker; public PlayerManager manager;