Ported rule updateSuppressionCrashFix from Carpet-Extra + More (#1133)
* Posted rule `updateSuppressionCrashFix` from Carpet-Extra Also added catch for update suppression in neighbour update during ServerPlayerEntity tick. Added Logger `updateSuppressedCrashes` so not everyone sees the crash messages Added Coords to crash message so we now know where it originates from * Make it easier to read * that `s` has been there for a long time * Made `updateSuppressionCrashFix` compatible with carpet-extra
This commit is contained in:
1 parent
506457d878
commit
0714098347
7 files changed
+169
-4
No files matched your search
@@ -0,0 +1,55 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.CarpetSettings;
|
||||
import carpet.helpers.ThrowableSuppression;
|
||||
import carpet.logging.LoggerRegistry;
|
||||
import carpet.utils.Messenger;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.BaseText;
|
||||
import net.minecraft.util.crash.CrashException;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
@Mixin(ServerPlayerEntity.class)
|
||||
public class ServerPlayerEntity_updateSuppressionCrashFixMixin {
|
||||
|
||||
@Redirect(
|
||||
method = "playerTick()V",
|
||||
at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/entity/player/PlayerEntity;tick()V"
|
||||
),
|
||||
require = 0
|
||||
)
|
||||
private void fixUpdateSuppressionCrashPlayerTick(PlayerEntity playerEntity){
|
||||
if (!CarpetSettings.updateSuppressionCrashFix) {
|
||||
playerEntity.tick();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
playerEntity.tick();
|
||||
} catch (CrashException e) {
|
||||
if (!(e.getCause() instanceof ThrowableSuppression throwableSuppression)) throw e;
|
||||
logUpdateSuppressionPlayer(throwableSuppression.pos);
|
||||
} catch (ThrowableSuppression e) {
|
||||
logUpdateSuppressionPlayer(e.pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void logUpdateSuppressionPlayer(BlockPos pos) {
|
||||
if(LoggerRegistry.__updateSuppressedCrashes) {
|
||||
LoggerRegistry.getLogger("updateSuppressedCrashes").log(() -> {
|
||||
return new BaseText[]{Messenger.c(
|
||||
"w Server crash prevented in: ",
|
||||
"m player tick ",
|
||||
"w - at: ",
|
||||
"g [ " + pos.toShortString() + " ]"
|
||||
)};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user