Files
fabric-carpet/src/main/java/carpet/mixins/ServerPlayerEntity_updateSuppressionCrashFixMixin.java
T
Fx Morin 0714098347 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
2021-10-20 23:08:23 -03:00

56 lines
1.9 KiB
Java

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() + " ]"
)};
});
}
}
}