Dungeons Gear

Dungeons Gear

6M Downloads

[1.16.4] Dungeons Gear Mod lagging out Servers

Speiger opened this issue ยท 7 comments

commented

Hey. ChunkPregenerator dev here.

I got a bugreport about a lagsource in Chunk Pregenerator where the game would freeze and get killed by the Server Watch Dog because a Tick took longer then 60 seconds.

After Investigating i found this nice line in the Log that was provided:
at com.infamous.dungeons_gear.loot.GlobalLootModifier$CommonLootAdditions.doApply(GlobalLootModifier.java:72) ~[dungeons_gear:3.0.6] {re:classloading}

Full Log:
crash-2021-01-13_13.54.15-server.txt

After looking into your code i found the reason why that is happening.
There is 2 issues with this code:

  1. You always Check for the TileEntity First, which you should change to Entity Check first and if that fails then it should check for the TileEntity.
  2. You load a TileEntity without Checking if it is loaded. Please add a check if the chunk is actually loaded in.

I do not know if that is only a 1.16.4 bug but this is a serious issue that needs to be solved.

Thanks for reading. Speiger.

commented

I've had this happen a few times in a couple of my worlds utilizing DG, although I don't have the logs to prove it was this in particular, it would happen in certain parts of my map, and I do remember seeing this line in the logs at the time. Thanks for sharing, Speiger. ;2)

commented

Pinned for attention to this issue, I am currently not actively developing but I will try to get someone to fix this ASAP

commented

Also, duplicate of #23

commented

@Speiger can you look at the most recent change made to my loot modifier in master and see if that is enough to fix the lag issue?

commented

That works but technically breaks your mod. Because entities do not have to be loaded to generate loot.
This would have been my fix as i have written it to you.

@Nonnull
@Override
public List<ItemStack> doApply(List<ItemStack> generatedLoot, LootContext context) {
	// return early if the user has disabled this feature
	if(!DungeonsGearConfig.ENABLE_DUNGEONS_GEAR_LOOT.get()){
		return generatedLoot;
	}
	Entity contextEntity = context.get(LootParameters.KILLER_ENTITY); 
	if(contextEntity instanceof ContainerMinecartEntity){
		ContainerMinecartEntity containerMinecartEntity = (ContainerMinecartEntity)contextEntity;
		ResourceLocation lootTable = getLootTable(containerMinecartEntity);
		if (lootTable != null) {
			String lootTablePath = lootTable.toString();
			DungeonsGearConfig.COMMON_LOOT_TABLES.get().forEach((path) ->{
				if(lootTablePath.contains(path) && !DungeonsGearConfig.COMMON_LOOT_TABLES_BLACKLIST.get().contains(lootTablePath)){
					generatedLoot.addAll(ChestLootHelper.generateLootFromValues(DungeonsGearConfig.UNIQUE_ITEM_COMMON_LOOT.get(), DungeonsGearConfig.ARTIFACT_COMMON_LOOT.get()));
				}
			});
		}
	}
	else 
	{
		Vector3d vector3d = context.get(LootParameters.field_237457_g_);
		if(vector3d != null){
			BlockPos pos = new BlockPos(vector3d);
			// fix chunk lag issue
			if(!context.getWorld().isBlockLoaded(pos)){
				return generatedLoot;
			}
			TileEntity contextTileEntity = context.getWorld().getTileEntity(pos);
			if(contextTileEntity instanceof LockableLootTileEntity){
				LockableLootTileEntity lockableLootTileEntity = (LockableLootTileEntity)contextTileEntity;
				ResourceLocation lootTable = getLootTable(lockableLootTileEntity);
				if (lootTable != null) {
					String lootTablePath = lootTable.toString();
					DungeonsGearConfig.COMMON_LOOT_TABLES.get().forEach((path) ->{
						if(lootTablePath.contains(path) && !DungeonsGearConfig.COMMON_LOOT_TABLES_BLACKLIST.get().contains(lootTablePath)){
							generatedLoot.addAll(ChestLootHelper.generateLootFromValues(DungeonsGearConfig.UNIQUE_ITEM_COMMON_LOOT.get(), DungeonsGearConfig.ARTIFACT_COMMON_LOOT.get()));
						}
					});
				}
			}
		}
	}
	return generatedLoot;
}
commented

Technically the block exists check would only be nessesary for Dungeons and other blocks that use chests instead of minecarts but having a prevention system in for other mods to prevent bad mods causing issue is always a good idea anyways.
As dumb as it sounds: Always assume other mods want to break your mod xD May not be true but you wonder how often i get mod specific crashes where the dev was asleep at the driving wheel xD (I wonder who gets the reference)

commented

Implemented your fix in development, will be fixed in next release