PaperSpigot-Parent/Spigot-Server-Patches/0050-Force-load-chunks-for-specific-entities-that-fly-thr.patch
Zach Brown 233814297b Remove the spigot TileEntity/Entity capping feature
It appears to cause visual glitching issues with certain TNT entities
fired from cannons. TileEntity tick capping has already been removed
for some time, Entity tick capping removal is new to this patch.
2015-05-30 01:39:20 -05:00

173 lines
8.8 KiB
Diff

From a7954c623d317f72957411ec5d1338fa76a94d7f Mon Sep 17 00:00:00 2001
From: Zach Brown <zach.brown@destroystokyo.com>
Date: Thu, 28 May 2015 22:01:25 -0500
Subject: [PATCH] Force load chunks for specific entities that fly through
diff --git a/src/main/java/net/minecraft/server/EntityEnderPearl.java b/src/main/java/net/minecraft/server/EntityEnderPearl.java
index f4b5032..a7190fa 100644
--- a/src/main/java/net/minecraft/server/EntityEnderPearl.java
+++ b/src/main/java/net/minecraft/server/EntityEnderPearl.java
@@ -86,8 +86,20 @@ public class EntityEnderPearl extends EntityProjectile {
}
public void t_() {
- EntityLiving entityliving = this.getShooter();
+ // PaperSpigot start - Force load chunks for specific entities that fly through
+ if (world.paperSpigotConfig.loadUnloadedEnderPearls) {
+ ChunkProviderServer chunkProvider = (ChunkProviderServer) world.chunkProvider;
+ boolean before = chunkProvider.forceChunkLoad;
+ chunkProvider.forceChunkLoad = true;
+ for (int cx = (int) locX >> 4; cx <= (int) (locX + motX) >> 4; ++cx) {
+ for (int cz = (int) locZ >> 4; cz <= (int) (locZ + motZ) >> 4; ++cz) {
+ world.getChunkAt(cx, cz);
+ }
+ }
+ chunkProvider.forceChunkLoad = before;
+ }
+ EntityLiving entityliving = this.getShooter();
if (entityliving != null && entityliving instanceof EntityHuman && !entityliving.isAlive()) {
this.die();
} else {
diff --git a/src/main/java/net/minecraft/server/EntityFallingBlock.java b/src/main/java/net/minecraft/server/EntityFallingBlock.java
index 44219cd..a0452ac 100644
--- a/src/main/java/net/minecraft/server/EntityFallingBlock.java
+++ b/src/main/java/net/minecraft/server/EntityFallingBlock.java
@@ -60,6 +60,21 @@ public class EntityFallingBlock extends Entity {
if (block.getMaterial() == Material.AIR) {
this.die();
} else {
+ // PaperSpigot start - Force load chunks for specific entities that fly through
+ if (world.paperSpigotConfig.loadUnloadedFallingBlocks) {
+ ChunkProviderServer chunkProvider = (ChunkProviderServer) world.chunkProvider;
+ boolean before = chunkProvider.forceChunkLoad;
+ chunkProvider.forceChunkLoad = true;
+
+ for (int cx = (int) locX >> 4; cx <= (int) (locX + motX) >> 4; ++cx) {
+ for (int cz = (int) locZ >> 4; cz <= (int) (locZ + motZ) >> 4; ++cz) {
+ world.getChunkAt(cx, cz);
+ }
+ }
+
+ chunkProvider.forceChunkLoad = before;
+ }
+ // PaperSpigot end
this.lastX = this.locX;
this.lastY = this.locY;
this.lastZ = this.locZ;
diff --git a/src/main/java/net/minecraft/server/EntityTNTPrimed.java b/src/main/java/net/minecraft/server/EntityTNTPrimed.java
index dd1ad68..c272060 100644
--- a/src/main/java/net/minecraft/server/EntityTNTPrimed.java
+++ b/src/main/java/net/minecraft/server/EntityTNTPrimed.java
@@ -56,6 +56,21 @@ public class EntityTNTPrimed extends Entity {
public void t_() {
if (world.spigotConfig.currentPrimedTnt++ > world.spigotConfig.maxTntTicksPerTick) { return; } // Spigot
+ // PaperSpigot start - Force load chunks for specific entities that fly through
+ if (world.paperSpigotConfig.loadUnloadedTNTEntities) {
+ ChunkProviderServer chunkProvider = (ChunkProviderServer) world.chunkProvider;
+ boolean before = chunkProvider.forceChunkLoad;
+ chunkProvider.forceChunkLoad = true;
+
+ for (int cx = (int) locX >> 4; cx <= (int) (locX + motX) >> 4; ++cx) {
+ for (int cz = (int) locZ >> 4; cz <= (int) (locZ + motZ) >> 4; ++cz) {
+ world.getChunkAt(cx, cz);
+ }
+ }
+
+ chunkProvider.forceChunkLoad = before;
+ }
+ // PaperSpigot end
this.lastX = this.locX;
this.lastY = this.locY;
this.lastZ = this.locZ;
@@ -116,7 +131,18 @@ public class EntityTNTPrimed extends Entity {
locY += this.length / 2.0F;
}
- this.world.createExplosion(this, this.locX, locY, this.locZ, event.getRadius(), event.getFire(), true);
+ // PaperSpigot start - Force load chunks for specific entities that fly through
+ if (world.paperSpigotConfig.loadUnloadedTNTEntities) {
+ ChunkProviderServer chunkProvider = (ChunkProviderServer) world.chunkProvider;
+ boolean before = chunkProvider.forceChunkLoad;
+ chunkProvider.forceChunkLoad = true;
+
+ this.world.createExplosion(this, this.locX, locY, this.locZ, event.getRadius(), event.getFire(), true);
+
+ chunkProvider.forceChunkLoad = before;
+ } else {
+ this.world.createExplosion(this, this.locX, locY, this.locZ, event.getRadius(), event.getFire(), true);
+ }
// PaperSpigot end
}
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index 86913f4..385d742 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -1641,6 +1641,17 @@ public abstract class World implements IBlockAccess {
if (this.isChunkLoaded(k, i1, true)) {
entity.ad = true;
this.getChunkAt(k, i1).a(entity);
+ // PaperSpigot start - Force load chunks for specific entities that fly through
+ } else if ((entity instanceof EntityEnderPearl && entity.world.paperSpigotConfig.loadUnloadedEnderPearls) ||
+ (entity instanceof EntityTNTPrimed && entity.world.paperSpigotConfig.loadUnloadedTNTEntities) ||
+ (entity instanceof EntityFallingBlock && entity.world.paperSpigotConfig.loadUnloadedFallingBlocks)) {
+ ChunkProviderServer chunkProvider = (ChunkProviderServer) this.chunkProvider;
+ boolean before = chunkProvider.forceChunkLoad;
+ chunkProvider.forceChunkLoad = true;
+ entity.ad = true;
+ this.getChunkAt(k, i1).a(entity);
+ chunkProvider.forceChunkLoad = before;
+ // PaperSpigot end
} else {
entity.ad = false;
}
diff --git a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
index 6a690ee..557561c 100644
--- a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
+++ b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
@@ -254,4 +254,14 @@ public class PaperSpigotWorldConfig
{
disableEndCredits = getBoolean( "game-mechanics.disable-end-credits", false );
}
+
+ public boolean loadUnloadedEnderPearls;
+ public boolean loadUnloadedTNTEntities;
+ public boolean loadUnloadedFallingBlocks;
+ private void loadUnloaded()
+ {
+ loadUnloadedEnderPearls = getBoolean( "load-chunks.enderpearls", false );
+ loadUnloadedTNTEntities = getBoolean( "load-chunks.tnt-entities", false );
+ loadUnloadedFallingBlocks = getBoolean( "load-chunks.falling-blocks", false );
+ }
}
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
index 7ca1b24..dcab40c 100644
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -13,6 +13,7 @@ import net.minecraft.server.EntityComplexPart;
import net.minecraft.server.EntityCreature;
import net.minecraft.server.EntityEnderCrystal;
import net.minecraft.server.EntityEnderDragon;
+import net.minecraft.server.EntityEnderPearl; // PaperSpigot
import net.minecraft.server.EntityFallingBlock;
import net.minecraft.server.EntityFireball;
import net.minecraft.server.EntityFireworks;
@@ -247,7 +248,10 @@ public class ActivationRange
{
SpigotTimings.checkIfActiveTimer.startTiming();
// Never safe to skip fireworks or entities not yet added to chunk
- if ( !entity.isAddedToChunk() || entity instanceof EntityFireworks ) {
+ // PaperSpigot - Changes for loading chunks for entities that fly through them
+ if ( !entity.isAddedToChunk() || entity instanceof EntityFireworks || entity instanceof EntityFallingBlock ||
+ ( entity instanceof EntityEnderPearl && entity.world.paperSpigotConfig.loadUnloadedEnderPearls ) ||
+ ( entity instanceof EntityTNTPrimed && entity.world.paperSpigotConfig.loadUnloadedTNTEntities ) ) {
SpigotTimings.checkIfActiveTimer.stopTiming();
return true;
}
--
2.4.1.windows.1