1
0
Fork 0

增加对entity tick的拦截与判定

kcx-1614
聪聪 2017-06-28 08:26:41 +08:00
parent 467c637ca6
commit 05b874f281
8 changed files with 419 additions and 93 deletions

View File

@ -35,7 +35,7 @@
import org.apache.commons.lang3.Validate;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@@ -80,18 +86,54 @@
@@ -80,18 +86,55 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.WorldEvent;
@ -66,6 +66,7 @@
+import net.minecraft.world.WorldProvider;
+import net.minecraftforge.cauldron.CauldronUtils;
+import net.minecraftforge.cauldron.configuration.CauldronConfig;
+import net.minecraftforge.cauldron.configuration.EntityConfig;
+import net.minecraftforge.cauldron.configuration.TileEntityConfig;
+import net.minecraftforge.common.util.EnumHelper;
+
@ -93,7 +94,7 @@
private final ServerStatusResponse field_147147_p = new ServerStatusResponse();
private final Random field_147146_q = new Random();
@SideOnly(Side.SERVER)
@@ -135,8 +177,40 @@
@@ -135,8 +178,41 @@
private long field_147142_T = 0L;
private final GameProfileRepository field_152365_W;
private final PlayerProfileCache field_152366_X;
@ -118,6 +119,7 @@
+ public static CauldronConfig cauldronConfig;
+ public static KCauldronConfig kcauldronConfig;
+ public static TileEntityConfig tileEntityConfig;
+ public static EntityConfig entityConfig;
+ public static YamlConfiguration configuration;
+ public static YamlConfiguration commandsConfiguration;
+ public static File configFile;
@ -134,7 +136,7 @@
public MinecraftServer(File p_i45281_1_, Proxy p_i45281_2_)
{
this.field_152366_X = new PlayerProfileCache(this, field_152367_a);
@@ -149,10 +223,70 @@
@@ -149,10 +225,72 @@
this.field_152364_T = new YggdrasilAuthenticationService(p_i45281_2_, UUID.randomUUID().toString());
this.field_147143_S = this.field_152364_T.createMinecraftSessionService();
this.field_152365_W = this.field_152364_T.createProfileRepository();
@ -142,6 +144,7 @@
+ kcauldronConfig = new KCauldronConfig();
+ cauldronConfig = new CauldronConfig("cauldron.yml", "cauldron");
+ tileEntityConfig = new TileEntityConfig("tileentities.yml", "cauldron_te");
+ entityConfig = new EntityConfig("entities.yml", "cauldron_e");
}
+ // Cauldron end
@ -162,6 +165,7 @@
+ kcauldronConfig = new KCauldronConfig();
+ cauldronConfig = new CauldronConfig("cauldron.yml", "cauldron");
+ tileEntityConfig = new TileEntityConfig("tileentities.yml", "cauldron_te");
+ entityConfig = new EntityConfig("entities.yml", "cauldron_e");
+ // Cauldron end
+ // CraftBukkit start
+ this.options = options;
@ -206,7 +210,7 @@
protected void convertMapIfNeeded(String p_71237_1_)
{
if (this.getActiveAnvilConverter().isOldMapFormat(p_71237_1_))
@@ -172,6 +306,7 @@
@@ -172,6 +310,7 @@
MinecraftServer.logger.info("Converting... " + p_73718_1_ + "%");
}
}
@ -214,7 +218,7 @@
@SideOnly(Side.CLIENT)
public void resetProgressAndMessage(String p_73721_1_) {}
@SideOnly(Side.CLIENT)
@@ -195,10 +330,17 @@
@@ -195,10 +334,17 @@
protected void loadAllWorlds(String p_71247_1_, String p_71247_2_, long p_71247_3_, WorldType p_71247_5_, String p_71247_6_)
{
@ -234,7 +238,7 @@
WorldSettings worldsettings;
if (worldinfo == null)
@@ -215,11 +357,79 @@
@@ -215,11 +361,79 @@
{
worldsettings.enableBonusChest();
}
@ -317,7 +321,7 @@
world.addWorldAccess(new WorldManager(this, world));
if (!this.isSinglePlayer())
@@ -227,12 +437,14 @@
@@ -227,12 +441,14 @@
world.getWorldInfo().setGameType(this.getGameType());
}
@ -335,7 +339,7 @@
}
protected void initialWorldChunkLoad()
@@ -244,9 +456,12 @@
@@ -244,9 +460,12 @@
int i = 0;
this.setUserMessage("menu.generatingTerrain");
byte b0 = 0;
@ -348,7 +352,7 @@
long j = getSystemTimeMillis();
for (int k = -192; k <= 192 && this.isServerRunning(); k += 16)
@@ -265,7 +480,8 @@
@@ -265,7 +484,8 @@
worldserver.theChunkProviderServer.loadChunk(chunkcoordinates.posX + k >> 4, chunkcoordinates.posZ + l >> 4);
}
}
@ -358,7 +362,7 @@
this.clearCurrentTask();
}
@@ -292,19 +508,17 @@
@@ -292,19 +512,17 @@
{
this.currentTask = null;
this.percentDone = 0;
@ -383,7 +387,7 @@
if (worldserver != null)
{
@@ -313,25 +527,41 @@
@@ -313,25 +531,41 @@
logger.info("Saving chunks for level \'" + worldserver.getWorldInfo().getWorldName() + "\'/" + worldserver.provider.getDimensionName());
}
@ -430,7 +434,7 @@
if (this.func_147137_ag() != null)
{
this.func_147137_ag().terminateEndpoints();
@@ -347,7 +577,14 @@
@@ -347,7 +581,14 @@
if (this.worldServers != null)
{
logger.info("Saving worlds");
@ -446,7 +450,7 @@
for (int i = 0; i < this.worldServers.length; ++i)
{
@@ -380,6 +617,13 @@
@@ -380,6 +621,13 @@
this.serverRunning = false;
}
@ -460,7 +464,7 @@
public void run()
{
try
@@ -392,45 +636,41 @@
@@ -392,45 +640,41 @@
this.field_147147_p.func_151315_a(new ChatComponentText(this.motd));
this.field_147147_p.func_151321_a(new ServerStatusResponse.MinecraftProtocolVersionIdentifier("1.7.10", 5));
this.func_147138_a(this.field_147147_p);
@ -527,7 +531,7 @@
FMLCommonHandler.instance().handleServerStopping();
FMLCommonHandler.instance().expectServerStopped(); // has to come before finalTick to avoid race conditions
}
@@ -448,6 +688,14 @@
@@ -448,6 +692,14 @@
catch (Throwable throwable1)
{
logger.error("Encountered an unexpected exception", throwable1);
@ -542,7 +546,7 @@
CrashReport crashreport = null;
if (throwable1 instanceof ReportedException)
@@ -477,6 +725,7 @@
@@ -477,6 +729,7 @@
{
try
{
@ -550,7 +554,7 @@
this.stopServer();
this.serverStopped = true;
}
@@ -486,6 +735,16 @@
@@ -486,6 +739,16 @@
}
finally
{
@ -567,7 +571,7 @@
FMLCommonHandler.instance().handleServerStopped();
this.serverStopped = true;
this.systemExitNow();
@@ -532,8 +791,11 @@
@@ -532,8 +795,11 @@
public void tick()
{
@ -579,7 +583,7 @@
++this.tickCounter;
if (this.startProfiling)
@@ -562,12 +824,21 @@
@@ -562,12 +828,21 @@
this.field_147147_p.func_151318_b().func_151330_a(agameprofile);
}
@ -603,7 +607,7 @@
}
this.theProfiler.startSection("tallying");
@@ -575,25 +846,57 @@
@@ -575,25 +850,57 @@
this.theProfiler.endSection();
this.theProfiler.startSection("snooper");
@ -663,7 +667,7 @@
int i;
Integer[] ids = DimensionManager.getIDs(this.tickCounter % 200 == 0);
@@ -602,19 +905,21 @@
@@ -602,19 +909,21 @@
int id = ids[x];
long j = System.nanoTime();
@ -688,7 +692,7 @@
this.theProfiler.startSection("tick");
FMLCommonHandler.instance().onPreWorldTick(worldserver);
@@ -622,22 +927,46 @@
@@ -622,22 +931,46 @@
try
{
@ -737,7 +741,7 @@
worldserver.addWorldInfoToCrashReport(crashreport);
throw new ReportedException(crashreport);
}
@@ -645,10 +974,12 @@
@@ -645,10 +978,12 @@
FMLCommonHandler.instance().onPostWorldTick(worldserver);
this.theProfiler.endSection();
this.theProfiler.startSection("tracker");
@ -751,7 +755,7 @@
worldTickTimes.get(id)[this.tickCounter % 100] = System.nanoTime() - j;
}
@@ -656,15 +987,21 @@
@@ -656,15 +991,21 @@
this.theProfiler.endStartSection("dim_unloading");
DimensionManager.unloadWorlds(worldTickTimes);
this.theProfiler.endStartSection("connection");
@ -773,7 +777,7 @@
this.theProfiler.endSection();
}
@@ -699,6 +1036,13 @@
@@ -699,6 +1040,13 @@
public WorldServer worldServerForDimension(int p_71218_1_)
{
@ -787,7 +791,7 @@
WorldServer ret = DimensionManager.getWorld(p_71218_1_);
if (ret == null)
{
@@ -784,13 +1128,14 @@
@@ -784,13 +1132,14 @@
public List getPossibleCompletions(ICommandSender p_71248_1_, String p_71248_2_)
{
@ -806,7 +810,7 @@
if (list != null)
{
@@ -798,40 +1143,25 @@
@@ -798,40 +1147,25 @@
while (iterator.hasNext())
{
@ -855,7 +859,7 @@
}
public static MinecraftServer getServer()
@@ -1034,7 +1364,7 @@
@@ -1034,7 +1368,7 @@
public boolean isServerInOnlineMode()
{
@ -864,7 +868,7 @@
}
public void setOnlineMode(boolean p_71229_1_)
@@ -1124,7 +1454,7 @@
@@ -1124,7 +1458,7 @@
public NetworkSystem func_147137_ag()
{
@ -873,7 +877,7 @@
}
@SideOnly(Side.CLIENT)
@@ -1259,8 +1589,11 @@
@@ -1259,8 +1593,11 @@
{
Bootstrap.func_151354_b();
@ -885,7 +889,7 @@
boolean flag = true;
String s = null;
String s1 = ".";
@@ -1356,16 +1689,34 @@
@@ -1356,16 +1693,34 @@
{
dedicatedserver.setGuiEnabled();
}
@ -926,7 +930,7 @@
}
catch (Exception exception)
{
@@ -1400,15 +1751,70 @@
@@ -1400,15 +1755,70 @@
@SideOnly(Side.SERVER)
public String getPlugins()
{
@ -1002,7 +1006,7 @@
}
@SideOnly(Side.SERVER)
@@ -1455,9 +1861,213 @@
@@ -1455,9 +1865,213 @@
return this.serverStopped;
}

View File

@ -140,7 +140,7 @@
this.field_154332_n = new ServerEula(new File("eula.txt"));
if (!this.field_154332_n.func_154346_a())
@@ -172,6 +231,17 @@
@@ -172,6 +231,18 @@
this.setServerPort(this.settings.getIntProperty("server-port", 25565));
}
@ -153,12 +153,13 @@
+ kcauldronConfig.registerCommands();
+ cauldronConfig.registerCommands();
+ tileEntityConfig.registerCommands();
+ entityConfig.registerCommands();
+ // Cauldron end
+
field_155771_h.info("Generating keypair");
this.setKeyPair(CryptManager.createNewKeyPair());
field_155771_h.info("Starting Minecraft server on " + (this.getServerHostname().length() == 0 ? "*" : this.getServerHostname()) + ":" + this.getServerPort());
@@ -180,7 +250,7 @@
@@ -180,7 +251,7 @@
{
this.func_147137_ag().addLanEndpoint(inetaddress, this.getServerPort());
}
@ -167,7 +168,7 @@
{
field_155771_h.warn("**** FAILED TO BIND TO PORT!");
field_155771_h.warn("The exception was: {}", new Object[] {ioexception.toString()});
@@ -196,10 +266,17 @@
@@ -196,10 +267,17 @@
field_155771_h.warn("To change this, set \"online-mode\" to \"true\" in the server.properties file.");
}
@ -187,7 +188,7 @@
if (!PreYggdrasilConverter.func_152714_a(this.settings))
{
@@ -208,7 +285,8 @@
@@ -208,7 +286,8 @@
else
{
FMLCommonHandler.instance().onServerStarted();
@ -197,7 +198,7 @@
long j = System.nanoTime();
if (this.getFolderName() == null)
@@ -274,11 +352,30 @@
@@ -274,11 +353,30 @@
this.theRConThreadMain.startThread();
}
@ -228,7 +229,7 @@
public boolean canStructuresSpawn()
{
return this.canSpawnStructures;
@@ -364,11 +461,19 @@
@@ -364,11 +462,19 @@
public void executePendingCommands()
{

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;
}

View File

@ -46,6 +46,7 @@ public class CauldronHooks
public static int tickingDimension = 0;
public static ChunkCoordIntPair tickingChunk = null;
public static Map<Class<? extends TileEntity>, TileEntityCache> tileEntityCache = new HashMap<Class<? extends TileEntity>, TileEntityCache>();
public static Map<Class<? extends Entity>, EntityCache> entityCache = new HashMap<Class<? extends Entity>, EntityCache>();
private static TObjectLongHashMap<CollisionWarning> recentWarnings = new TObjectLongHashMap<CollisionWarning>();
@ -305,6 +306,26 @@ public class CauldronHooks
}
return true;
}
public static boolean canEntityTick(Entity pEntity,World world){
if(pEntity==null||world.tileentityConfig==null) return false;
if(MinecraftServer.entityConfig.skipEntityTicks.getValue()){
EntityCache eCache=entityCache.get(pEntity.getClass());
if(eCache==null){
String teConfigPath=pEntity.getClass().getName().replace(".","-");
teConfigPath=teConfigPath.replaceAll("[^A-Za-z0-9\\-]",""); // Fix up odd class names to prevent YAML errors
eCache=new EntityCache(pEntity.getClass(),world.getWorldInfo().getWorldName().toLowerCase(),teConfigPath,world.entityConfig.getInt(teConfigPath+".tick-interval",1));
entityCache.put(pEntity.getClass(),eCache);
}
// Skip tick interval
if(eCache.tickInterval>0&&(world.getWorldInfo().getWorldTotalTime()%eCache.tickInterval==0L)){
return true;
}
return false;
}
return true;
}
public static boolean canUpdate(TileEntity tileEntity)
{

View File

@ -0,0 +1,18 @@
package net.minecraftforge.cauldron;
import net.minecraft.entity.Entity;
public class EntityCache{
public Class<? extends Entity> tileEntityClass;
public int tickInterval=1;
public String configPath;
public String worldName;
public EntityCache(Class<? extends Entity> entityClass,String worldName,String configPath,int tickInterval){
this.tileEntityClass=entityClass;
this.worldName=worldName;
this.tickInterval=tickInterval;
this.configPath=configPath;
}
}

View File

@ -0,0 +1,173 @@
package net.minecraftforge.cauldron.command;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.server.MinecraftServer;
import net.minecraftforge.cauldron.configuration.BoolSetting;
import net.minecraftforge.cauldron.configuration.IntSetting;
import net.minecraftforge.cauldron.configuration.Setting;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang.math.NumberUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.util.StringUtil;
import com.google.common.collect.ImmutableList;
public class EntityCommand extends Command{
private static final List<String> COMMANDS=ImmutableList.of("get","set","save","reload");
public EntityCommand(){
super("cauldron_e");
this.description="Toggle certain TileEntity options";
this.usageMessage="/cauldron_e ["+StringUtils.join(COMMANDS,'|')+"] <option> [value]";
this.setPermission("cauldron.command.cauldron_e");
}
@Override
public boolean execute(CommandSender sender,String commandLabel,String[] args){
if(!testPermission(sender)){
return true;
}
if((args.length==1)&&"save".equalsIgnoreCase(args[0])){
MinecraftServer.getServer();
MinecraftServer.entityConfig.save();
sender.sendMessage(ChatColor.GREEN+"Config file saved");
return true;
}
if((args.length==1)&&"reload".equalsIgnoreCase(args[0])){
MinecraftServer.getServer();
MinecraftServer.entityConfig.load();
sender.sendMessage(ChatColor.GREEN+"Config file reloaded");
return true;
}
if(args.length<2){
sender.sendMessage(ChatColor.RED+"Usage: "+usageMessage);
return false;
}
if("get".equalsIgnoreCase(args[0])){
return getToggle(sender,args);
}else if("set".equalsIgnoreCase(args[0])){
return setToggle(sender,args);
}else{
sender.sendMessage(ChatColor.RED+"Usage: "+usageMessage);
}
return false;
}
private boolean getToggle(CommandSender sender,String[] args){
try{
MinecraftServer.getServer();
Setting toggle=MinecraftServer.entityConfig.getSettings().get(args[1]);
MinecraftServer.getServer();
// check config directly
if(toggle==null&&MinecraftServer.entityConfig.isSet(args[1])){
MinecraftServer.getServer();
if(MinecraftServer.entityConfig.isBoolean(args[1])){
MinecraftServer.getServer();
MinecraftServer.getServer();
toggle=new BoolSetting(MinecraftServer.entityConfig,args[1],MinecraftServer.entityConfig.getBoolean(args[1],false),"");
}else{
MinecraftServer.getServer();
if(MinecraftServer.entityConfig.isInt(args[1])){
MinecraftServer.getServer();
MinecraftServer.getServer();
toggle=new IntSetting(MinecraftServer.entityConfig,args[1],MinecraftServer.entityConfig.getInt(args[1],1),"");
}
}
if(toggle!=null){
MinecraftServer.getServer();
MinecraftServer.entityConfig.getSettings().put(toggle.path,toggle);
MinecraftServer.getServer();
MinecraftServer.entityConfig.load();
}
}
if(toggle==null){
sender.sendMessage(ChatColor.RED+"Could not find option: "+args[1]);
return false;
}
Object value=toggle.getValue();
String option=(Boolean.TRUE.equals(value)?ChatColor.GREEN:ChatColor.RED)+" "+value;
sender.sendMessage(ChatColor.GOLD+args[1]+" "+option);
}catch(Exception ex){
sender.sendMessage(ChatColor.RED+"Usage: "+usageMessage);
ex.printStackTrace();
}
return true;
}
private boolean intervalSet(CommandSender sender,String[] args){
try{
int setting=NumberUtils.toInt(args[2],1);
MinecraftServer.getServer();
MinecraftServer.entityConfig.set(args[1],setting);
}catch(Exception ex){
sender.sendMessage(ChatColor.RED+"Usage: "+usageMessage);
return false;
}
return true;
}
private boolean setToggle(CommandSender sender,String[] args){
try{
MinecraftServer.getServer();
Setting toggle=MinecraftServer.entityConfig.getSettings().get(args[1]);
MinecraftServer.getServer();
// check config directly
if(toggle==null&&MinecraftServer.entityConfig.isSet(args[1])){
MinecraftServer.getServer();
MinecraftServer.getServer();
toggle=new BoolSetting(MinecraftServer.entityConfig,args[1],MinecraftServer.entityConfig.getBoolean(args[1],false),"");
MinecraftServer.getServer();
MinecraftServer.entityConfig.getSettings().put(toggle.path,toggle);
MinecraftServer.getServer();
MinecraftServer.entityConfig.load();
}
if(toggle==null){
sender.sendMessage(ChatColor.RED+"Could not find option: "+args[1]);
return false;
}
if(args.length==2){
sender.sendMessage(ChatColor.RED+"Usage: "+args[0]+" "+args[1]+" [value]");
return false;
}
toggle.setValue(args[2]);
Object value=toggle.getValue();
String option=(Boolean.TRUE.equals(value)?ChatColor.GREEN:ChatColor.RED)+" "+value;
sender.sendMessage(ChatColor.GOLD+args[1]+" "+option);
MinecraftServer.getServer();
MinecraftServer.entityConfig.save();
}catch(Exception ex){
sender.sendMessage(ChatColor.RED+"Usage: "+usageMessage);
ex.printStackTrace();
}
return true;
}
@Override
public List<String> tabComplete(CommandSender sender,String alias,String[] args){
Validate.notNull(sender,"Sender cannot be null");
Validate.notNull(args,"Arguments cannot be null");
Validate.notNull(alias,"Alias cannot be null");
if(args.length==1){
return StringUtil.copyPartialMatches(args[0],COMMANDS,new ArrayList<String>(COMMANDS.size()));
}
if(((args.length==2)&&"get".equalsIgnoreCase(args[0]))||"set".equalsIgnoreCase(args[0])){
MinecraftServer.getServer();
MinecraftServer.getServer();
return StringUtil.copyPartialMatches(args[1],MinecraftServer.entityConfig.getSettings().keySet(),new ArrayList<String>(MinecraftServer.tileEntityConfig.getSettings().size()));
}
return ImmutableList.of();
}
}

View File

@ -0,0 +1,77 @@
package net.minecraftforge.cauldron.configuration;
import org.bukkit.configuration.file.YamlConfiguration;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.WorldServer;
import net.minecraftforge.cauldron.CauldronHooks;
import net.minecraftforge.cauldron.EntityCache;
import net.minecraftforge.cauldron.command.EntityCommand;
public class EntityConfig extends ConfigBase{
private final String HEADER="Made By Imcc,to skip entity tick";
/*
* ========================================================================
*/
public final BoolSetting skipEntityTicks=new BoolSetting(this,"settings.skip-entity-ticks",true,
"If enabled, turns on entity tick skip feature");
/*
* ========================================================================
*/
public EntityConfig(String fileName,String commandName){
super(fileName,commandName);
init();
}
public void addCommands(){
commands.put(this.commandName,new EntityCommand());
}
public void init(){
settings.put(skipEntityTicks.path,skipEntityTicks);
load();
}
public void load(){
try{
config=YamlConfiguration.loadConfiguration(configFile);
String header=HEADER+"\n";
for(Setting toggle : settings.values()){
if(!toggle.description.equals(""))
header+="Setting: "+toggle.path+" Default: "+toggle.def+" # "+toggle.description+"\n";
config.addDefault(toggle.path,toggle.def);
settings.get(toggle.path).setValue(config.getString(toggle.path));
}
config.options().header(header);
config.options().copyDefaults(true);
version=getInt("config-version",1);
set("config-version",1);
for(EntityCache tCache : CauldronHooks.entityCache.values()){
tCache.tickInterval=config.getInt("world-settings."+tCache.worldName+"."+tCache.configPath+".tick-interval",config.getInt("world-settings.default."+tCache.configPath+".tick-interval"));
}
this.saveWorldConfigs();
this.save();
}catch(Exception ex){
MinecraftServer.getServer().logSevere("Could not load "+this.configFile);
ex.printStackTrace();
}
}
@Override
public void saveWorldConfigs(){
for(int i=0;i<MinecraftServer.getServer().worlds.size();++i){
WorldServer worldserver=MinecraftServer.getServer().worlds.get(i);
if(worldserver!=null&&worldserver.entityConfig!=null){
worldserver.entityConfig.save();
}
}
}
}

View File

@ -0,0 +1,8 @@
package net.minecraftforge.cauldron.configuration;
public class EntityWorldConfig extends WorldConfig{
public EntityWorldConfig(String worldName,ConfigBase configFile){
super(worldName,configFile);
}
}