Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

Commit

Permalink
Woohoo close to 56
Browse files Browse the repository at this point in the history
  • Loading branch information
robotia committed Apr 23, 2016
1 parent 3838737 commit b316045
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 56 deletions.
56 changes: 34 additions & 22 deletions patches/net/minecraft/world/World.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -1256,15 +1263,15 @@
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;
}
}
+ p_72866_1_.tickTimer.stopTiming(); // Spigot
}
}

@@ -2570,7 +3226,7 @@
@@ -2570,7 +3233,7 @@
return;
}

Expand All @@ -1273,15 +1280,15 @@
{
if (this.field_147481_N)
{
@@ -2612,6 +3268,7 @@
@@ -2612,6 +3275,7 @@

public void func_147457_a(TileEntity p_147457_1_)
{
+ if(p_147457_1_ != null)
this.field_147483_b.add(p_147457_1_);
}

@@ -2718,7 +3375,15 @@
@@ -2718,7 +3382,15 @@

if (i <= 0)
{
Expand All @@ -1298,7 +1305,7 @@
}
}

@@ -2754,7 +3419,15 @@
@@ -2754,7 +3426,15 @@

if (j <= 0)
{
Expand All @@ -1315,7 +1322,7 @@
}
}

@@ -2777,8 +3450,41 @@
@@ -2777,8 +3457,41 @@
protected void setActivePlayerChunksAndCheckLight()
{
this.activeChunkSet.clear();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1393,7 +1400,7 @@
}

this.theProfiler.endSection();
@@ -2810,7 +3527,7 @@
@@ -2810,7 +3534,7 @@

this.theProfiler.startSection("playerCheckLight");

Expand All @@ -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 @@
}
}

Expand All @@ -1414,7 +1421,7 @@
{
return false;
}
@@ -3166,6 +3883,28 @@
@@ -3166,6 +3890,28 @@
}
}

Expand Down Expand Up @@ -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_)
{
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -1484,15 +1491,15 @@
++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);
+ if (!entity.entityAllowedToSpawn()) continue;
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_);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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() {}

Expand All @@ -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)
{
Expand All @@ -1568,7 +1575,7 @@
{
dest.add(entity);
}
@@ -4029,4 +4814,127 @@
@@ -4029,4 +4821,132 @@
}
return count;
}
Expand Down Expand Up @@ -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));
Expand Down
80 changes: 48 additions & 32 deletions src/main/java/net/minecraftforge/cauldron/CauldronHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ public class SushchestvoCache {

public Class<? extends Entity> entityClass;
public boolean tickNoPlayers = false;
public boolean neverEverTick = false;
public int tickInterval = 1;
public String configPath;
public String worldName;

public SushchestvoCache(Class<? extends Entity> entityClass, String worldName, String configPath, boolean tickNoPlayers, int tickInterval)
public SushchestvoCache(Class<? extends Entity> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b316045

Please sign in to comment.