From b31604574bab0d1b6e056dc49f965c5ca502ae60 Mon Sep 17 00:00:00 2001 From: Robotia Date: Sat, 23 Apr 2016 02:47:10 -0400 Subject: [PATCH] Woohoo close to 56 --- patches/net/minecraft/world/World.java.patch | 56 ++++++++----- .../cauldron/CauldronHooks.java | 80 +++++++++++-------- .../cauldron/SushchestvoCache.java | 6 +- .../configuration/SushchestvoConfig.java | 1 + 4 files changed, 87 insertions(+), 56 deletions(-) diff --git a/patches/net/minecraft/world/World.java.patch b/patches/net/minecraft/world/World.java.patch index 3a800565..cbeb00bc 100644 --- a/patches/net/minecraft/world/World.java.patch +++ b/patches/net/minecraft/world/World.java.patch @@ -1236,18 +1236,25 @@ if (!canUpdate) { -@@ -2048,9 +2694,18 @@ +@@ -2048,9 +2694,25 @@ MinecraftForge.EVENT_BUS.post(event); canUpdate = event.canUpdate; } - + // Spigot start -+ if (!isForced && !canUpdate && !CauldronHooks.canSushchestvoTick(p_72866_1_,this) && !org.spigotmc.ActivationRange.checkIfActive(p_72866_1_)) // Cauldron - ignore if forge event forced update or entity is in forced chunk ++ byte tickAbility = CauldronHooks.canSushchestvoTick(p_72866_1_,this); ++ if (!isForced && !canUpdate && tickAbility != 0 && !org.spigotmc.ActivationRange.checkIfActive(p_72866_1_)) // Cauldron - ignore if forge event forced update or entity is in forced chunk + { + p_72866_1_.ticksExisted++; + p_72866_1_.inactiveTick(); + return; + } ++ else if(tickAbility == -1) // Thermos force no ticking if it is set to be so ++ { ++ p_72866_1_.ticksExisted++; ++ p_72866_1_.inactiveTick(); ++ return; ++ } + // Spigot end if (canUpdate) { @@ -1256,7 +1263,7 @@ p_72866_1_.lastTickPosX = p_72866_1_.posX; p_72866_1_.lastTickPosY = p_72866_1_.posY; p_72866_1_.lastTickPosZ = p_72866_1_.posZ; -@@ -2134,6 +2789,7 @@ +@@ -2134,6 +2796,7 @@ p_72866_1_.riddenByEntity = null; } } @@ -1264,7 +1271,7 @@ } } -@@ -2570,7 +3226,7 @@ +@@ -2570,7 +3233,7 @@ return; } @@ -1273,7 +1280,7 @@ { if (this.field_147481_N) { -@@ -2612,6 +3268,7 @@ +@@ -2612,6 +3275,7 @@ public void func_147457_a(TileEntity p_147457_1_) { @@ -1281,7 +1288,7 @@ this.field_147483_b.add(p_147457_1_); } -@@ -2718,7 +3375,15 @@ +@@ -2718,7 +3382,15 @@ if (i <= 0) { @@ -1298,7 +1305,7 @@ } } -@@ -2754,7 +3419,15 @@ +@@ -2754,7 +3426,15 @@ if (j <= 0) { @@ -1315,7 +1322,7 @@ } } -@@ -2777,8 +3450,41 @@ +@@ -2777,8 +3457,41 @@ protected void setActivePlayerChunksAndCheckLight() { this.activeChunkSet.clear(); @@ -1358,7 +1365,7 @@ int i; EntityPlayer entityplayer; int j; -@@ -2788,17 +3494,28 @@ +@@ -2788,17 +3501,28 @@ for (i = 0; i < this.playerEntities.size(); ++i) { entityplayer = (EntityPlayer)this.playerEntities.get(i); @@ -1393,7 +1400,7 @@ } this.theProfiler.endSection(); -@@ -2810,7 +3527,7 @@ +@@ -2810,7 +3534,7 @@ this.theProfiler.startSection("playerCheckLight"); @@ -1402,7 +1409,7 @@ { i = this.rand.nextInt(this.playerEntities.size()); entityplayer = (EntityPlayer)this.playerEntities.get(i); -@@ -3034,9 +3751,9 @@ +@@ -3034,9 +3758,9 @@ } } @@ -1414,7 +1421,7 @@ { return false; } -@@ -3166,6 +3883,28 @@ +@@ -3166,6 +3890,28 @@ } } @@ -1443,7 +1450,7 @@ this.theProfiler.endSection(); return true; } -@@ -3188,7 +3927,7 @@ +@@ -3188,7 +3934,7 @@ public List getEntitiesWithinAABBExcludingEntity(Entity p_94576_1_, AxisAlignedBB p_94576_2_, IEntitySelector p_94576_3_) { @@ -1452,7 +1459,7 @@ int i = MathHelper.floor_double((p_94576_2_.minX - MAX_ENTITY_RADIUS) / 16.0D); int j = MathHelper.floor_double((p_94576_2_.maxX + MAX_ENTITY_RADIUS) / 16.0D); int k = MathHelper.floor_double((p_94576_2_.minZ - MAX_ENTITY_RADIUS) / 16.0D); -@@ -3219,7 +3958,7 @@ +@@ -3219,7 +3965,7 @@ int j = MathHelper.floor_double((p_82733_2_.maxX + MAX_ENTITY_RADIUS) / 16.0D); int k = MathHelper.floor_double((p_82733_2_.minZ - MAX_ENTITY_RADIUS) / 16.0D); int l = MathHelper.floor_double((p_82733_2_.maxZ + MAX_ENTITY_RADIUS) / 16.0D); @@ -1461,7 +1468,7 @@ for (int i1 = i; i1 <= j; ++i1) { -@@ -3284,8 +4023,21 @@ +@@ -3284,8 +4030,21 @@ { Entity entity = (Entity)this.loadedEntityList.get(j); @@ -1484,7 +1491,7 @@ ++i; } } -@@ -3298,6 +4050,7 @@ +@@ -3298,6 +4057,7 @@ for (int i = 0; i < p_72868_1_.size(); ++i) { Entity entity = (Entity)p_72868_1_.get(i); @@ -1492,7 +1499,7 @@ if (!MinecraftForge.EVENT_BUS.post(new EntityJoinWorldEvent(entity, this))) { loadedEntityList.add(entity); -@@ -3314,8 +4067,17 @@ +@@ -3314,8 +4074,17 @@ public boolean canPlaceEntityOnSide(Block p_147472_1_, int p_147472_2_, int p_147472_3_, int p_147472_4_, boolean p_147472_5_, int p_147472_6_, Entity p_147472_7_, ItemStack p_147472_8_) { Block block1 = this.getBlock(p_147472_2_, p_147472_3_, p_147472_4_); @@ -1511,7 +1518,7 @@ } public PathEntity getPathEntityToEntity(Entity p_72865_1_, Entity p_72865_2_, float p_72865_3_, boolean p_72865_4_, boolean p_72865_5_, boolean p_72865_6_, boolean p_72865_7_) -@@ -3464,6 +4226,12 @@ +@@ -3464,6 +4233,12 @@ for (int i = 0; i < this.playerEntities.size(); ++i) { EntityPlayer entityplayer1 = (EntityPlayer)this.playerEntities.get(i); @@ -1524,7 +1531,7 @@ double d5 = entityplayer1.getDistanceSq(p_72977_1_, p_72977_3_, p_72977_5_); if ((p_72977_7_ < 0.0D || d5 < p_72977_7_ * p_72977_7_) && (d4 == -1.0D || d5 < d4)) -@@ -3489,7 +4257,12 @@ +@@ -3489,7 +4264,12 @@ for (int i = 0; i < this.playerEntities.size(); ++i) { EntityPlayer entityplayer1 = (EntityPlayer)this.playerEntities.get(i); @@ -1538,7 +1545,7 @@ if (!entityplayer1.capabilities.disableDamage && entityplayer1.isEntityAlive()) { double d5 = entityplayer1.getDistanceSq(p_72846_1_, p_72846_3_, p_72846_5_); -@@ -3660,6 +4433,18 @@ +@@ -3660,6 +4440,18 @@ public void updateAllPlayersSleepingFlag() {} @@ -1557,7 +1564,7 @@ public float getWeightedThunderStrength(float p_72819_1_) { return (this.prevThunderingStrength + (this.thunderingStrength - this.prevThunderingStrength) * p_72819_1_) * this.getRainStrength(p_72819_1_); -@@ -3932,8 +4717,8 @@ +@@ -3932,8 +4724,8 @@ */ public void addTileEntity(TileEntity entity) { @@ -1568,7 +1575,7 @@ { dest.add(entity); } -@@ -4029,4 +4814,127 @@ +@@ -4029,4 +4821,132 @@ } return count; } @@ -1603,6 +1610,11 @@ + return isActiveChunk(x >> 4, z >> 4); + } + ++ public boolean isActiveBlockCoord(int x, int y, int z) ++ { ++ return isActiveChunk(x >> 4, z >> 4); ++ } ++ + public boolean inActiveChunk(Entity entity) + { + return isActiveBlockCoord(MathHelper.floor_double(entity.posX), MathHelper.floor_double(entity.posZ)); diff --git a/src/main/java/net/minecraftforge/cauldron/CauldronHooks.java b/src/main/java/net/minecraftforge/cauldron/CauldronHooks.java index 6e334ed4..f342efc5 100644 --- a/src/main/java/net/minecraftforge/cauldron/CauldronHooks.java +++ b/src/main/java/net/minecraftforge/cauldron/CauldronHooks.java @@ -279,69 +279,68 @@ public int hashCode() } } - public static boolean canSushchestvoTick(Entity entity, World world) + /* + * Thermos + * 0 = false, dependent on others + * 1 = true + * -1 = false, absolute + */ + public static byte canSushchestvoTick(Entity entity, World world) { - if (entity == null || world.sushchestvoConfig == null) return false; + if (entity == null || world.sushchestvoConfig == null) { return 0; } + if (!MinecraftServer.sushchestvoConfig.skipEntityTicks.getValue()) { return 1; } + int cX = net.minecraft.util.MathHelper.floor_double( entity.posX ) >> 4, cZ = net.minecraft.util.MathHelper.floor_double( entity.posZ ) >> 4; int iX = net.minecraft.util.MathHelper.floor_double( entity.posX ), iZ = net.minecraft.util.MathHelper.floor_double( entity.posZ ); - if(world.chunkProvider instanceof ChunkProviderServer) // Thermos - allow the server to tick entities that are in chunks trying to unload - { - ChunkProviderServer cps = ((ChunkProviderServer)world.chunkProvider); - if(cps.chunksToUnload.contains(cX, cZ)) - { - Chunk c = cps.getChunkIfLoaded(cX, cZ); - if(c != null) - { - if(c.lastAccessedTick < 2L) - { - return true; - } - } - } - } SushchestvoCache seCache = sushchestvoCache.get(entity.getClass()); if (seCache == null) { String seConfigPath = entity.getClass().getName().replace(".", "-"); seConfigPath = seConfigPath.replaceAll("[^A-Za-z0-9\\-]", ""); // Fix up odd class names to prevent YAML errors - seCache = new SushchestvoCache(entity.getClass(), world.getWorldInfo().getWorldName().toLowerCase(), seConfigPath, world.sushchestvoConfig.getBoolean(seConfigPath + ".tick-no-players", false), world.sushchestvoConfig.getInt(seConfigPath + ".tick-interval", 1)); + seCache = new SushchestvoCache(entity.getClass(), world.getWorldInfo().getWorldName().toLowerCase(), seConfigPath, world.sushchestvoConfig.getBoolean(seConfigPath + ".tick-no-players", false), world.sushchestvoConfig.getBoolean(seConfigPath + ".never-ever-tick", false), world.sushchestvoConfig.getInt(seConfigPath + ".tick-interval", 1)); sushchestvoCache.put(entity.getClass(), seCache); } // Tick with no players near? if (!seCache.tickNoPlayers && !world.isActiveBlockCoord(iX, iZ)) { - return false; + return 0; + } + else if(seCache.neverEverTick) + { + return -1; } // Skip tick interval if (seCache.tickInterval > 0 && (world.getWorldInfo().getWorldTotalTime() % seCache.tickInterval == 0L)) { - return true; + return 1; } - return false; - } - - public static boolean canTileEntityTick(TileEntity tileEntity, World world) - { - if (tileEntity == null || world.tileentityConfig == null) return false; - if (MinecraftServer.tileEntityConfig.skipTileEntityTicks.getValue()) - { - if(world.chunkProvider instanceof ChunkProviderServer) // Thermos - allow the server to tick tiles that are trying to unload + + if(world.chunkProvider instanceof ChunkProviderServer) // Thermos - allow the server to tick entities that are in chunks trying to unload { ChunkProviderServer cps = ((ChunkProviderServer)world.chunkProvider); - if(cps.chunksToUnload.contains(tileEntity.xCoord >> 4, tileEntity.zCoord >> 4)) + if(cps.chunksToUnload.contains(cX, cZ)) { - Chunk c = cps.getChunkIfLoaded(tileEntity.xCoord >> 4, tileEntity.zCoord >> 4); + Chunk c = cps.getChunkIfLoaded(cX, cZ); if(c != null) { if(c.lastAccessedTick < 2L) { - return true; + return 1; } } } } + + return 0; + } + + public static boolean canTileEntityTick(TileEntity tileEntity, World world) + { + if (tileEntity == null || world.tileentityConfig == null) return false; + if (MinecraftServer.tileEntityConfig.skipTileEntityTicks.getValue()) + { TileEntityCache teCache = tileEntityCache.get(tileEntity.getClass()); if (teCache == null) { @@ -362,6 +361,23 @@ public static boolean canTileEntityTick(TileEntity tileEntity, World world) { return true; } + + if(world.chunkProvider instanceof ChunkProviderServer) // Thermos - allow the server to tick tiles that are trying to unload + { + ChunkProviderServer cps = ((ChunkProviderServer)world.chunkProvider); + if(cps.chunksToUnload.contains(tileEntity.xCoord >> 4, tileEntity.zCoord >> 4)) + { + Chunk c = cps.getChunkIfLoaded(tileEntity.xCoord >> 4, tileEntity.zCoord >> 4); + if(c != null) + { + if(c.lastAccessedTick < 2L) + { + return true; + } + } + } + } + return false; } return true; diff --git a/src/main/java/net/minecraftforge/cauldron/SushchestvoCache.java b/src/main/java/net/minecraftforge/cauldron/SushchestvoCache.java index 120868a8..54452d9a 100644 --- a/src/main/java/net/minecraftforge/cauldron/SushchestvoCache.java +++ b/src/main/java/net/minecraftforge/cauldron/SushchestvoCache.java @@ -6,15 +6,17 @@ public class SushchestvoCache { public Class entityClass; public boolean tickNoPlayers = false; + public boolean neverEverTick = false; public int tickInterval = 1; public String configPath; public String worldName; - public SushchestvoCache(Class entityClass, String worldName, String configPath, boolean tickNoPlayers, int tickInterval) + public SushchestvoCache(Class entityClass, String worldName, String configPath, boolean tickNoPlayers, boolean neverEverTick, int tickInterval) { this.entityClass = entityClass; - this.worldName = worldName; + this.worldName = worldName.intern(); this.tickNoPlayers = tickNoPlayers; + this.neverEverTick = neverEverTick; this.tickInterval = tickInterval; this.configPath = configPath; } diff --git a/src/main/java/net/minecraftforge/cauldron/configuration/SushchestvoConfig.java b/src/main/java/net/minecraftforge/cauldron/configuration/SushchestvoConfig.java index 9a3bea62..c980eb61 100644 --- a/src/main/java/net/minecraftforge/cauldron/configuration/SushchestvoConfig.java +++ b/src/main/java/net/minecraftforge/cauldron/configuration/SushchestvoConfig.java @@ -64,6 +64,7 @@ public void load() for (SushchestvoCache seCache : CauldronHooks.sushchestvoCache.values()) { seCache.tickNoPlayers = config.getBoolean( "world-settings." + seCache.worldName + "." + seCache.configPath + ".tick-no-players", config.getBoolean( "world-settings.default." + seCache.configPath + ".tick-no-players") ); + seCache.neverEverTick = config.getBoolean( "world-settings." + seCache.worldName + "." + seCache.configPath + ".never-ever-tick", config.getBoolean( "world-settings.default." + seCache.configPath + ".never-ever-tick") ); seCache.tickInterval = config.getInt( "world-settings." + seCache.worldName + "." + seCache.configPath + ".tick-interval", config.getInt( "world-settings.default." + seCache.configPath + ".tick-interval") ); } this.saveWorldConfigs();