3
0

增加对entity tick的拦截与判定

This commit is contained in:
2017-06-28 08:26:41 +08:00
parent 467c637ca6
commit 05b874f281
8 changed files with 419 additions and 93 deletions

View File

@ -36,7 +36,7 @@
import cpw.mods.fml.common.FMLLog;
import com.google.common.collect.ImmutableSetMultimap;
@@ -70,6 +73,55 @@
@@ -70,6 +73,56 @@
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
import net.minecraft.entity.EnumCreatureType;
@ -81,6 +81,7 @@
+import net.minecraftforge.cauldron.CauldronHooks;
+import net.minecraftforge.cauldron.configuration.CauldronConfig;
+import net.minecraftforge.cauldron.configuration.CauldronWorldConfig;
+import net.minecraftforge.cauldron.configuration.EntityWorldConfig;
+import net.minecraftforge.cauldron.configuration.TileEntityConfig;
+import net.minecraftforge.cauldron.configuration.TileEntityWorldConfig;
+import net.minecraftforge.common.DimensionManager;
@ -92,7 +93,7 @@
public abstract class World implements IBlockAccess
{
/**
@@ -83,15 +135,14 @@
@@ -83,15 +136,14 @@
public boolean scheduledUpdatesAreImmediate;
public List loadedEntityList = new ArrayList();
@ -110,7 +111,7 @@
protected final int DIST_HASH_MAGIC = 1013904223;
public float prevRainingStrength;
public float rainingStrength;
@@ -100,30 +151,93 @@
@@ -100,30 +152,94 @@
public int lastLightningBolt;
public EnumDifficulty difficultySetting;
public Random rand = new Random();
@ -156,6 +157,7 @@
+ public int tilesTicked;
+ public CauldronWorldConfig cauldronConfig;
+ public TileEntityWorldConfig tileentityConfig;
+ public EntityWorldConfig entityConfig; // imcc
+ // preload world crash report classes to fix NCDFE masking StackOverflow/memory error, see #721
+ private static boolean preloadedCrashClasses = false;
+ {
@ -211,7 +213,7 @@
public BiomeGenBase getBiomeGenForCoords(final int p_72807_1_, final int p_72807_2_)
{
@@ -166,6 +280,27 @@
@@ -166,6 +282,27 @@
return this.provider.worldChunkMgr;
}
@ -239,7 +241,7 @@
@SideOnly(Side.CLIENT)
public World(ISaveHandler p_i45368_1_, String p_i45368_2_, WorldProvider p_i45368_3_, WorldSettings p_i45368_4_, Profiler p_i45368_5_)
{
@@ -179,6 +314,12 @@
@@ -179,6 +316,12 @@
this.worldInfo = new WorldInfo(p_i45368_4_, p_i45368_2_);
this.provider = p_i45368_3_;
perWorldStorage = new MapStorage((ISaveHandler)null);
@ -252,7 +254,7 @@
}
// Broken up so that the WorldClient gets the chance to set the mapstorage object before the dimension initializes
@@ -207,8 +348,175 @@
@@ -207,8 +350,177 @@
this.calculateInitialWeather();
}
@ -263,8 +265,9 @@
+ this.spigotConfig = new org.spigotmc.SpigotWorldConfig(p_i45369_2_); // Spigot
+ initLimiter(); // Spigot
+ // Cauldron start
+ this.cauldronConfig = new CauldronWorldConfig(p_i45369_2_, MinecraftServer.getServer().cauldronConfig);
+ this.tileentityConfig = new TileEntityWorldConfig(p_i45369_2_, MinecraftServer.getServer().tileEntityConfig);
+ this.cauldronConfig = new CauldronWorldConfig(p_i45369_2_, MinecraftServer.cauldronConfig);
+ this.tileentityConfig = new TileEntityWorldConfig(p_i45369_2_, MinecraftServer.tileEntityConfig);
+ this.entityConfig = new EntityWorldConfig(p_i45369_2_, MinecraftServer.entityConfig);
+ // Cauldron end
+ this.worldInfo = p_i45369_1_.loadWorldInfo(); // Spigot
+ this.generator = gen;
@ -409,6 +412,7 @@
+ initLimiter(); // Spigot
+ this.cauldronConfig = new CauldronWorldConfig(p_i45369_2_, MinecraftServer.getServer().cauldronConfig);
+ this.tileentityConfig = new TileEntityWorldConfig(p_i45369_2_, MinecraftServer.getServer().tileEntityConfig);
+ this.entityConfig = new EntityWorldConfig(p_i45369_2_, MinecraftServer.getServer().entityConfig);
+ this.world = DimensionManager.getWorld(0).getWorld();
+ this.timings = DimensionManager.getWorld(0).timings;
+ this.activeChunkSet_CB = new gnu.trove.map.hash.TLongShortHashMap(spigotConfig.chunksPerTick * 5, 0.7f, Long.MIN_VALUE, Short.MIN_VALUE);
@ -428,7 +432,7 @@
this.ambientTickCountdown = this.rand.nextInt(12000);
this.spawnHostileMobs = true;
this.spawnPeacefulMobs = true;
@@ -216,7 +524,6 @@
@@ -216,7 +528,6 @@
this.lightUpdateBlockList = new int[32768];
this.saveHandler = p_i45369_1_;
this.theProfiler = p_i45369_5_;
@ -436,7 +440,7 @@
this.worldInfo = p_i45369_1_.loadWorldInfo();
if (p_i45369_4_ != null)
@@ -235,13 +542,26 @@
@@ -235,13 +546,26 @@
if (this.worldInfo == null)
{
this.worldInfo = new WorldInfo(p_i45369_3_, p_i45369_2_);
@ -463,7 +467,7 @@
this.chunkProvider = this.createChunkProvider();
if (this instanceof WorldServer)
@@ -294,6 +614,7 @@
@@ -294,6 +618,7 @@
this.calculateInitialSkylight();
this.calculateInitialWeather();
}
@ -471,7 +475,7 @@
private static MapStorage s_mapStorage;
private static ISaveHandler s_savehandler;
@@ -336,6 +657,18 @@
@@ -336,6 +661,18 @@
public Block getBlock(int p_147439_1_, int p_147439_2_, int p_147439_3_)
{
@ -490,7 +494,7 @@
if (p_147439_1_ >= -30000000 && p_147439_3_ >= -30000000 && p_147439_1_ < 30000000 && p_147439_3_ < 30000000 && p_147439_2_ >= 0 && p_147439_2_ < 256)
{
Chunk chunk = null;
@@ -404,7 +737,7 @@
@@ -404,7 +741,7 @@
}
}
@ -499,7 +503,7 @@
{
return this.chunkProvider.chunkExists(p_72916_1_, p_72916_2_);
}
@@ -421,6 +754,27 @@
@@ -421,6 +758,27 @@
public boolean setBlock(int p_147465_1_, int p_147465_2_, int p_147465_3_, Block p_147465_4_, int p_147465_5_, int p_147465_6_)
{
@ -527,7 +531,7 @@
if (p_147465_1_ >= -30000000 && p_147465_3_ >= -30000000 && p_147465_1_ < 30000000 && p_147465_3_ < 30000000)
{
if (p_147465_2_ < 0)
@@ -450,7 +804,9 @@
@@ -450,7 +808,9 @@
boolean flag = chunk.func_150807_a(p_147465_1_ & 15, p_147465_2_, p_147465_3_ & 15, p_147465_4_, p_147465_5_);
@ -538,7 +542,7 @@
{
this.capturedBlockSnapshots.remove(blockSnapshot);
blockSnapshot = null;
@@ -460,6 +816,7 @@
@@ -460,6 +820,7 @@
this.func_147451_t(p_147465_1_, p_147465_2_, p_147465_3_);
this.theProfiler.endSection();
@ -546,7 +550,7 @@
if (flag && blockSnapshot == null) // Don't notify clients or update physics while capturing blockstates
{
// Modularize client and physic updates
@@ -496,6 +853,19 @@
@@ -496,6 +857,19 @@
public int getBlockMetadata(int p_72805_1_, int p_72805_2_, int p_72805_3_)
{
@ -566,7 +570,7 @@
if (p_72805_1_ >= -30000000 && p_72805_3_ >= -30000000 && p_72805_1_ < 30000000 && p_72805_3_ < 30000000)
{
if (p_72805_2_ < 0)
@@ -511,7 +881,7 @@
@@ -511,7 +885,7 @@
Chunk chunk = this.getChunkFromChunkCoords(p_72805_1_ >> 4, p_72805_3_ >> 4);
p_72805_1_ &= 15;
p_72805_3_ &= 15;
@ -575,7 +579,7 @@
}
}
else
@@ -610,6 +980,12 @@
@@ -610,6 +984,12 @@
public void notifyBlockChange(int p_147444_1_, int p_147444_2_, int p_147444_3_, Block p_147444_4_)
{
@ -588,7 +592,7 @@
this.notifyBlocksOfNeighborChange(p_147444_1_, p_147444_2_, p_147444_3_, p_147444_4_);
}
@@ -694,6 +1070,21 @@
@@ -694,6 +1074,21 @@
try
{
@ -610,7 +614,7 @@
block.onNeighborBlockChange(this, p_147460_1_, p_147460_2_, p_147460_3_, p_147460_4_);
}
catch (Throwable throwable1)
@@ -1307,8 +1698,22 @@
@@ -1307,8 +1702,22 @@
public boolean spawnEntityInWorld(Entity p_72838_1_)
{
@ -626,7 +630,7 @@
+ if(!this.isRemote){
+ if(p_72838_1_ instanceof net.minecraft.entity.item.EntityItem&&this.restoringBlockSnapshots)
+ return false;
+ if(this.captureBlockSnapshots){
+ if(this.captureBlockSnapshots&&!(p_72838_1_ instanceof EntityPlayerMP)){
+ this.capturedEntityItemSnapshots.add(new net.minecraftforge.common.util.EntitySnapshot(this,p_72838_1_,spawnReason));
+ return true;
+ }
@ -634,7 +638,7 @@
int i = MathHelper.floor_double(p_72838_1_.posX / 16.0D);
int j = MathHelper.floor_double(p_72838_1_.posZ / 16.0D);
@@ -1319,23 +1724,99 @@
@@ -1319,23 +1728,99 @@
flag = true;
}
@ -736,7 +740,7 @@
return true;
}
}
@@ -1346,6 +1827,8 @@
@@ -1346,6 +1831,8 @@
{
((IWorldAccess)this.worldAccesses.get(i)).onEntityCreate(p_72923_1_);
}
@ -745,7 +749,7 @@
}
public void onEntityRemoved(Entity p_72847_1_)
@@ -1354,6 +1837,8 @@
@@ -1354,6 +1841,8 @@
{
((IWorldAccess)this.worldAccesses.get(i)).onEntityDestroy(p_72847_1_);
}
@ -754,7 +758,7 @@
}
public void removeEntity(Entity p_72900_1_)
@@ -1397,6 +1882,19 @@
@@ -1397,6 +1886,19 @@
}
this.loadedEntityList.remove(p_72973_1_);
@ -774,7 +778,7 @@
this.onEntityRemoved(p_72973_1_);
}
@@ -1408,40 +1906,58 @@
@@ -1408,40 +1910,58 @@
public List getCollidingBoundingBoxes(Entity p_72945_1_, AxisAlignedBB p_72945_2_)
{
this.collidingBoundingBoxes.clear();
@ -847,7 +851,7 @@
for (int j2 = 0; j2 < list.size(); ++j2)
{
@@ -1797,11 +2313,22 @@
@@ -1797,11 +2317,22 @@
Entity entity;
CrashReport crashreport;
CrashReportCategory crashreportcategory;
@ -870,7 +874,23 @@
try
{
++entity.ticksExisted;
@@ -1862,10 +2389,14 @@
@@ -1812,14 +2343,7 @@
crashreport = CrashReport.makeCrashReport(throwable2, "Ticking entity");
crashreportcategory = crashreport.makeCategory("Entity being ticked");
- if (entity == null)
- {
- crashreportcategory.addCrashSection("Entity", "~~NULL~~");
- }
- else
- {
- entity.addEntityCrashInfo(crashreportcategory);
- }
+ entity.addEntityCrashInfo(crashreportcategory);
if (ForgeModContainer.removeErroringEntities)
{
@@ -1862,10 +2386,14 @@
this.unloadedEntityList.clear();
this.theProfiler.endStartSection("regular");
@ -888,7 +908,7 @@
if (entity.ridingEntity != null)
{
@@ -1884,7 +2415,9 @@
@@ -1884,7 +2412,9 @@
{
try
{
@ -898,7 +918,7 @@
}
catch (Throwable throwable1)
{
@@ -1916,30 +2449,85 @@
@@ -1916,30 +2446,84 @@
{
this.getChunkFromChunkCoords(j, l).removeEntity(entity);
}
@ -958,7 +978,6 @@
+ // Spigot start
+ if (tileentity == null)
{
+ getServer().getLogger().severe("Cauldron has detected a null entity and has removed it, preventing a crash");
+ tilesThisCycle--;
+ this.loadedTileEntityList.remove(tileTickPosition--);
+ continue;
@ -991,7 +1010,7 @@
crashreport = CrashReport.makeCrashReport(throwable, "Ticking block entity");
crashreportcategory = crashreport.makeCategory("Block entity being ticked");
tileentity.func_145828_a(crashreportcategory);
@@ -1955,23 +2543,13 @@
@@ -1955,23 +2539,13 @@
}
}
}
@ -1020,7 +1039,7 @@
if (!this.field_147483_b.isEmpty())
{
for (Object tile : field_147483_b)
@@ -1981,6 +2559,7 @@
@@ -1981,6 +2555,7 @@
this.loadedTileEntityList.removeAll(this.field_147483_b);
this.field_147483_b.clear();
}
@ -1028,7 +1047,7 @@
this.field_147481_N = false;
@@ -2016,17 +2595,23 @@
@@ -2016,17 +2591,23 @@
this.addedTileEntityList.clear();
}
@ -1055,11 +1074,16 @@
}
public void updateEntity(Entity p_72870_1_)
@@ -2036,21 +2621,36 @@
@@ -2036,21 +2617,41 @@
public void updateEntityWithOptionalForce(Entity p_72866_1_, boolean p_72866_2_)
{
+ if (p_72866_1_.isDead) return;
+ if(!CauldronHooks.canEntityTick(p_72866_1_,this)){
+ p_72866_1_.ticksExisted++;
+ p_72866_1_.inactiveTick();
+ return;
+ }
int i = MathHelper.floor_double(p_72866_1_.posX);
int j = MathHelper.floor_double(p_72866_1_.posZ);
boolean isForced = getPersistentChunks().containsKey(new ChunkCoordIntPair(i >> 4, j >> 4));
@ -1094,7 +1118,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 +2734,7 @@
@@ -2134,6 +2735,7 @@
p_72866_1_.riddenByEntity = null;
}
}
@ -1102,7 +1126,7 @@
}
}
@@ -2570,7 +3171,7 @@
@@ -2570,7 +3172,7 @@
return;
}
@ -1111,7 +1135,7 @@
{
if (this.field_147481_N)
{
@@ -2612,6 +3213,9 @@
@@ -2612,6 +3214,9 @@
public void func_147457_a(TileEntity p_147457_1_)
{
@ -1121,7 +1145,7 @@
this.field_147483_b.add(p_147457_1_);
}
@@ -2718,7 +3322,15 @@
@@ -2718,7 +3323,15 @@
if (i <= 0)
{
@ -1138,7 +1162,7 @@
}
}
@@ -2754,7 +3366,15 @@
@@ -2754,7 +3367,15 @@
if (j <= 0)
{
@ -1155,7 +1179,7 @@
}
}
@@ -2777,8 +3397,41 @@
@@ -2777,8 +3398,41 @@
protected void setActivePlayerChunksAndCheckLight()
{
this.activeChunkSet.clear();
@ -1198,7 +1222,7 @@
int i;
EntityPlayer entityplayer;
int j;
@@ -2788,17 +3441,28 @@
@@ -2788,17 +3442,28 @@
for (i = 0; i < this.playerEntities.size(); ++i)
{
entityplayer = (EntityPlayer)this.playerEntities.get(i);
@ -1233,7 +1257,7 @@
}
this.theProfiler.endSection();
@@ -2810,7 +3474,7 @@
@@ -2810,7 +3475,7 @@
this.theProfiler.startSection("playerCheckLight");
@ -1242,7 +1266,7 @@
{
i = this.rand.nextInt(this.playerEntities.size());
entityplayer = (EntityPlayer)this.playerEntities.get(i);
@@ -3034,9 +3698,9 @@
@@ -3034,9 +3699,9 @@
}
}
@ -1254,7 +1278,7 @@
{
return false;
}
@@ -3166,6 +3830,16 @@
@@ -3166,6 +3831,16 @@
}
}
@ -1271,7 +1295,7 @@
this.theProfiler.endSection();
return true;
}
@@ -3284,8 +3958,21 @@
@@ -3284,8 +3959,21 @@
{
Entity entity = (Entity)this.loadedEntityList.get(j);
@ -1294,7 +1318,7 @@
++i;
}
}
@@ -3298,6 +3985,7 @@
@@ -3298,6 +3986,7 @@
for (int i = 0; i < p_72868_1_.size(); ++i)
{
Entity entity = (Entity)p_72868_1_.get(i);
@ -1302,7 +1326,7 @@
if (!MinecraftForge.EVENT_BUS.post(new EntityJoinWorldEvent(entity, this)))
{
loadedEntityList.add(entity);
@@ -3314,8 +4002,17 @@
@@ -3314,8 +4003,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_);
@ -1321,7 +1345,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 +4161,12 @@
@@ -3464,6 +4162,12 @@
for (int i = 0; i < this.playerEntities.size(); ++i)
{
EntityPlayer entityplayer1 = (EntityPlayer)this.playerEntities.get(i);
@ -1334,7 +1358,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 +4192,12 @@
@@ -3489,7 +4193,12 @@
for (int i = 0; i < this.playerEntities.size(); ++i)
{
EntityPlayer entityplayer1 = (EntityPlayer)this.playerEntities.get(i);
@ -1348,7 +1372,7 @@
if (!entityplayer1.capabilities.disableDamage && entityplayer1.isEntityAlive())
{
double d5 = entityplayer1.getDistanceSq(p_72846_1_, p_72846_3_, p_72846_5_);
@@ -3660,6 +4368,18 @@
@@ -3660,6 +4369,18 @@
public void updateAllPlayersSleepingFlag() {}
@ -1367,7 +1391,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 +4652,8 @@
@@ -3932,8 +4653,8 @@
*/
public void addTileEntity(TileEntity entity)
{
@ -1378,7 +1402,7 @@
{
dest.add(entity);
}
@@ -4029,4 +4749,122 @@
@@ -4029,4 +4750,122 @@
}
return count;
}