Paper/Spigot-Server-Patches/0049-Force-load-chunks-for-specific-entities-that-fly-thr.patch

174 lines
9.0 KiB
Diff
Raw Normal View History

From 20ef67da6f0df0601f190b8809d6a7a7176201c2 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
2015-06-04 10:42:09 +02:00
index 1daba4e..db33c98 100644
--- a/src/main/java/net/minecraft/server/EntityTNTPrimed.java
+++ b/src/main/java/net/minecraft/server/EntityTNTPrimed.java
2015-06-04 10:42:09 +02:00
@@ -50,6 +50,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;
2015-06-04 10:42:09 +02:00
@@ -97,7 +112,19 @@ public class EntityTNTPrimed extends Entity {
server.getPluginManager().callEvent(event);
2015-06-04 10:42:09 +02:00
if (!event.isCancelled()) {
- this.world.createExplosion(this, this.locX, this.locY + (double) (this.length / 2.0F), 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;
+
2015-06-04 10:42:09 +02:00
+ this.world.createExplosion(this, this.locX, this.locY + (double) (this.length / 2.0F), this.locZ, event.getRadius(), event.getFire(), true);
+
+ chunkProvider.forceChunkLoad = before;
+ } else {
2015-06-04 10:42:09 +02:00
+ this.world.createExplosion(this, this.locX, this.locY + (double) (this.length / 2.0F), this.locZ, event.getRadius(), event.getFire(), true);
+ }
2015-06-04 10:42:09 +02:00
+ // PaperSpigot end
}
// CraftBukkit end
2015-06-04 10:42:09 +02:00
}
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 e14e961..f51962e 100644
--- a/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
+++ b/src/main/java/org/github/paperspigot/PaperSpigotWorldConfig.java
@@ -265,4 +265,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;
}
--
2015-06-04 10:42:09 +02:00
1.9.5.msysgit.1