feat: 村民生成堆栈显示
This commit is contained in:
1 parent
a3e3fb361f
commit
43a6b49e9e
6 files changed
+47
-3
No files matched your search
@@ -53,4 +53,7 @@ public class SLSCarpetSettings {
|
||||
|
||||
@Rule(categories = {CARPET_ID, RuleCategory.OPTIMIZATION})
|
||||
public static boolean optimizedOnDragonRespawn = false;
|
||||
|
||||
@Rule(categories = {CARPET_ID, RuleCategory.FEATURE})
|
||||
public static boolean printStackTraceOnVillagerSpawn = false;
|
||||
}
|
||||
+39
@@ -1,17 +1,24 @@
|
||||
package com.github.zly2006.carpetslsaddition.mixin.entity;
|
||||
|
||||
import com.github.zly2006.carpetslsaddition.SLSCarpetSettings;
|
||||
import com.github.zly2006.carpetslsaddition.ServerMain;
|
||||
import net.minecraft.entity.EntityData;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.SpawnReason;
|
||||
import net.minecraft.entity.passive.MerchantEntity;
|
||||
import net.minecraft.entity.passive.VillagerEntity;
|
||||
import net.minecraft.village.VillagerData;
|
||||
import net.minecraft.village.VillagerProfession;
|
||||
import net.minecraft.world.LocalDifficulty;
|
||||
import net.minecraft.world.ServerWorldAccess;
|
||||
import net.minecraft.world.World;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
@Mixin(VillagerEntity.class)
|
||||
public abstract class MixinVillagerEntity extends MerchantEntity {
|
||||
@@ -19,11 +26,43 @@ public abstract class MixinVillagerEntity extends MerchantEntity {
|
||||
|
||||
@Shadow protected abstract void decayGossip();
|
||||
|
||||
@Unique
|
||||
int tickCount = 0;
|
||||
|
||||
public MixinVillagerEntity(EntityType<? extends MerchantEntity> entityType, World world) {
|
||||
super(entityType, world);
|
||||
}
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "initialize")
|
||||
private void injectInitialize(ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, EntityData entityData, CallbackInfoReturnable<EntityData> cir) {
|
||||
if (SLSCarpetSettings.printStackTraceOnVillagerSpawn) {
|
||||
var logBuilder = new StringBuilder("\n=== Villager Spawn Report ===\n");
|
||||
logBuilder.append("// Generated by Carpet SLS Addition\n");
|
||||
try {
|
||||
logBuilder.append("- Spawn Reason: ").append(spawnReason.toString()).append("\n");
|
||||
logBuilder.append("- World: ").append(this.getWorld().getRegistryKey().getValue().toString()).append("\n");
|
||||
logBuilder.append("- Position: ").append("(x=%.2f, y=%.2f, z=%.2f)".formatted(this.getX(), this.getY(), this.getZ())).append("\n");
|
||||
logBuilder.append("- Stack Trance: ");
|
||||
|
||||
var exception = new Exception();
|
||||
for (var element : exception.getStackTrace()) {
|
||||
logBuilder.append("\n ").append(element.toString());
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
logBuilder.append("// Sorry but we fail to generate the villager spawn report.\n");
|
||||
logBuilder.append("- Error Stack Trance: ");
|
||||
|
||||
for (var element : e.getStackTrace()) {
|
||||
logBuilder.append("\n ").append(element.toString());
|
||||
}
|
||||
}
|
||||
|
||||
logBuilder.append("\n ================================");
|
||||
ServerMain.LOGGER.warn(logBuilder.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(at = @At("HEAD"), method = "tick", cancellable = true)
|
||||
private void onTick(CallbackInfo ci) {
|
||||
if (SLSCarpetSettings.skipTicksForJoblessVillager != 0) {
|
||||
|
||||
Reference in new issue
Block a user