From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 1 Mar 2016 23:52:34 -0600
Subject: [PATCH] Prevent tile entity and entity crashes


diff --git a/src/main/java/net/minecraft/server/TileEntity.java b/src/main/java/net/minecraft/server/TileEntity.java
index f1d0e2faffb3ef27f5a41d06d0ff7d787f1098f5..da96a91c6b4cc03ad2e4539053bd30e7dc62dfe8 100644
--- a/src/main/java/net/minecraft/server/TileEntity.java
+++ b/src/main/java/net/minecraft/server/TileEntity.java
@@ -194,7 +194,12 @@ public abstract class TileEntity implements KeyedObject { // Paper
             return IRegistry.BLOCK_ENTITY_TYPE.getKey(this.getTileType()) + " // " + this.getClass().getCanonicalName();
         });
         if (this.world != null) {
-            CrashReportSystemDetails.a(crashreportsystemdetails, this.position, this.getBlock());
+            // Paper start - Prevent TileEntity and Entity crashes
+            IBlockData block = this.getBlock();
+            if (block != null) {
+                CrashReportSystemDetails.a(crashreportsystemdetails, this.position, block);
+            }
+            // Paper end
             CrashReportSystemDetails.a(crashreportsystemdetails, this.position, this.world.getType(this.position));
         }
     }
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 3f2ca3874f743c635fd6a7f6c18d554425a0c056..fb26ec91ecdeaa94a6247c064b7c6191a43927eb 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -685,11 +685,13 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
 
                         gameprofilerfiller.exit();
                     } catch (Throwable throwable) {
-                        CrashReport crashreport = CrashReport.a(throwable, "Ticking block entity");
-                        CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Block entity being ticked");
-
-                        tileentity.a(crashreportsystemdetails);
-                        throw new ReportedException(crashreport);
+                        // Paper start - Prevent tile entity and entity crashes
+                        System.err.println("TileEntity threw exception at " + tileentity.world.getWorld().getName() + ":" + tileentity.position.getX() + "," + tileentity.position.getY() + "," + tileentity.position.getZ());
+                        throwable.printStackTrace();
+                        tilesThisCycle--;
+                        this.tileEntityListTick.remove(tileTickPosition--);
+                        continue;
+                        // Paper end
                     }
                     // Spigot start
                     finally {
@@ -755,11 +757,12 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
         try {
             consumer.accept(entity);
         } catch (Throwable throwable) {
-            CrashReport crashreport = CrashReport.a(throwable, "Ticking entity");
-            CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Entity being ticked");
-
-            entity.appendEntityCrashDetails(crashreportsystemdetails);
-            throw new ReportedException(crashreport);
+            // Paper start - Prevent tile entity and entity crashes
+            System.err.println("Entity threw exception at " + entity.world.getWorld().getName() + ":" + entity.locX() + "," + entity.locY() + "," + entity.locZ());
+            throwable.printStackTrace();
+            entity.dead = true;
+            return;
+            // Paper end
         }
     }
 
