Skip to content

Commit

Permalink
Add noise suppression support for rule yeetUpdateSuppressionCrash (#…
Browse files Browse the repository at this point in the history
…165)

* Add noise suppression support for rule `yeetUpdateSuppressionCrash`

<3 JKM & Metacinnabar

* make it actually work

has not been tested in game yet

---------

Co-authored-by: Fallen_Breath <[email protected]>
  • Loading branch information
VelizarBG and Fallen-Breath authored Aug 11, 2024
1 parent 015d09c commit ca19e40
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public static UpdateSuppressionException createWrapper(Throwable cause, World wo
{
return new OutOfMemorySuppression(cause, world, pos);
}
if (cause instanceof IllegalArgumentException)
{
return new IllegalArgumentSuppression(cause, world, pos);
}
return null;
}

Expand All @@ -51,6 +55,7 @@ public static void noop()
StackOverflowSuppression.class.getClass();
ClassCastSuppression.class.getClass();
OutOfMemorySuppression.class.getClass();
IllegalArgumentSuppression.class.getClass();
}

public static class StackOverflowSuppression extends StackOverflowError implements UpdateSuppressionException
Expand Down Expand Up @@ -118,4 +123,26 @@ public UpdateSuppressionContext getSuppressionContext()
return this.context;
}
}

public static class IllegalArgumentSuppression extends IllegalArgumentException implements UpdateSuppressionException
{
private final UpdateSuppressionContext context;

public IllegalArgumentSuppression(Throwable cause, World world, BlockPos pos)
{
this.context = new UpdateSuppressionContext(cause, world, pos);
}

@Override
public synchronized Throwable getCause()
{
return this.context.getCause();
}

@Override
public UpdateSuppressionContext getSuppressionContext()
{
return this.context;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of the Carpet TIS Addition project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* Carpet TIS Addition is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Carpet TIS Addition is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Carpet TIS Addition. If not, see <https://www.gnu.org/licenses/>.
*/

package carpettisaddition.mixins.rule.yeetUpdateSuppressionCrash.mark;

import carpettisaddition.utils.compat.DummyClass;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(DummyClass.class)
public abstract class CalibratedSculkSensorBlockEntityCallBackMixin
{
// impl in mc1.20.1 subproject
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of the Carpet TIS Addition project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* Carpet TIS Addition is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Carpet TIS Addition is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Carpet TIS Addition. If not, see <https://www.gnu.org/licenses/>.
*/

package carpettisaddition.mixins.rule.yeetUpdateSuppressionCrash.mark;

import carpettisaddition.utils.compat.DummyClass;
import org.spongepowered.asm.mixin.Mixin;

@Mixin(DummyClass.class)
public abstract class SculkSensorBlockEntityVibrationCallbackMixin
{
// impl in mc1.18.2 subproject
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public abstract class WorldMixin
target = "Lnet/minecraft/util/crash/CrashReport;create(Ljava/lang/Throwable;Ljava/lang/String;)Lnet/minecraft/util/crash/CrashReport;"
)
)
private Throwable yeetUpdateSuppressionCrash_wrapSuppressionExceptions(
private Throwable yeetUpdateSuppressionCrash_wrapSoundSuppression(
Throwable throwable,
@Local(ordinal = 1, argsOnly = true) BlockPos neighborPos,
@Local LocalRef<Throwable> ref
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/carpet-tis-addition.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,10 @@
"rule.xpTrackingDistance.ExperienceOrbEntityMixin",
"rule.yeetOutOfOrderChatKick.MessageVerifierImplMixin",
"rule.yeetOutOfOrderChatKick.ServerPlayNetworkHandlerMixin",
"rule.yeetUpdateSuppressionCrash.mark.CalibratedSculkSensorBlockEntityCallBackMixin",
"rule.yeetUpdateSuppressionCrash.mark.ChainRestrictedNeighborUpdaterSixWayEntryMixin",
"rule.yeetUpdateSuppressionCrash.mark.NeighborUpdaterMixin",
"rule.yeetUpdateSuppressionCrash.mark.SculkSensorBlockEntityVibrationCallbackMixin",
"rule.yeetUpdateSuppressionCrash.mark.WorldMixin",
"rule.yeetUpdateSuppressionCrash.yeet.MinecraftServerMixin",
"rule.yeetUpdateSuppressionCrash.yeet.ReentrantThreadExecutorMixin",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* This file is part of the Carpet TIS Addition project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* Carpet TIS Addition is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Carpet TIS Addition is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Carpet TIS Addition. If not, see <https://www.gnu.org/licenses/>.
*/

package carpettisaddition.mixins.rule.yeetUpdateSuppressionCrash.mark;

import carpettisaddition.CarpetTISAdditionSettings;
import carpettisaddition.helpers.rule.yeetUpdateSuppressionCrash.UpdateSuppressionYeeter;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.SculkSensorBlockEntity;
import net.minecraft.util.math.BlockPos;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

//#if MC >= 11900
//$$ import net.minecraft.server.world.ServerWorld;
//#else
import net.minecraft.world.World;
//#endif

@Mixin(
//#if MC >= 12000
//$$ SculkSensorBlockEntity.VibrationCallback.class
//#else
SculkSensorBlockEntity.class
//#endif
)
public abstract class SculkSensorBlockEntityVibrationCallbackMixin
{
@WrapOperation(
method = {"accepts", "accept"},
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/SculkSensorBlock;isInactive(Lnet/minecraft/block/BlockState;)Z"
)
)
private boolean yeetUpdateSuppressionCrash_wrapSoundSuppression(
BlockState instance, Operation<Boolean> original,
//#if MC >= 12000
//$$ @Local(argsOnly = true) ServerWorld world,
//$$ @Local(argsOnly = true) BlockPos pos
//#elseif MC >= 11900
//$$ @Local(argsOnly = true) ServerWorld world
//#else
@Local(argsOnly = true) World world
//#endif
) throws Throwable
{
if (CarpetTISAdditionSettings.yeetUpdateSuppressionCrash)
{
try
{
return original.call(instance);
}
catch (Throwable throwable)
{
//#if MC < 12000
BlockPos pos = ((SculkSensorBlockEntity)(Object)this).getPos();
//#endif
throw UpdateSuppressionYeeter.tryReplaceWithWrapper(throwable, world, pos);
}
}
else
{
// vanilla
return original.call(instance);
}
}
}
5 changes: 5 additions & 0 deletions versions/1.20.1/carpet-tis-addition.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ accessible class net/minecraft/village/raid/Raid$Status
accessible class net/minecraft/server/command/FillCommand$Mode
accessible class net/minecraft/world/SpawnDensityCapper$DensityCap
accessible class net/minecraft/world/block/ChainRestrictedNeighborUpdater$Entry

# XXX: If without and use `targets = "xxxx"` instead, mixin will complain about "Mixin target xxxx is public and should be specified in value",
# even if they are actually protected classes
accessible class net/minecraft/block/entity/CalibratedSculkSensorBlockEntity$Callback
accessible class net/minecraft/block/entity/SculkSensorBlockEntity$VibrationCallback
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* This file is part of the Carpet TIS Addition project, licensed under the
* GNU Lesser General Public License v3.0
*
* Copyright (C) 2024 Fallen_Breath and contributors
*
* Carpet TIS Addition is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Carpet TIS Addition is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Carpet TIS Addition. If not, see <https://www.gnu.org/licenses/>.
*/

package carpettisaddition.mixins.rule.yeetUpdateSuppressionCrash.mark;

import carpettisaddition.CarpetTISAdditionSettings;
import carpettisaddition.helpers.rule.yeetUpdateSuppressionCrash.UpdateSuppressionYeeter;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.CalibratedSculkSensorBlockEntity;
import net.minecraft.state.property.Property;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

@Mixin(CalibratedSculkSensorBlockEntity.Callback.class)
public abstract class CalibratedSculkSensorBlockEntityCallBackMixin
{
@WrapOperation(
method = "getCalibrationFrequency",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/block/BlockState;get(Lnet/minecraft/state/property/Property;)Ljava/lang/Comparable;"
)
)
private <T extends Comparable<T>> T yeetUpdateSuppressionCrash_wrapSoundSuppression(
BlockState instance, Property<T> property, Operation<T> original,
@Local(argsOnly = true) World world,
@Local(argsOnly = true) BlockPos pos
) throws Throwable
{
if (CarpetTISAdditionSettings.yeetUpdateSuppressionCrash)
{
try
{
return original.call(instance, property);
}
catch (Throwable throwable)
{
throw UpdateSuppressionYeeter.tryReplaceWithWrapper(throwable, world, pos);
}
}
else
{
// vanilla
return original.call(instance, property);
}
}
}
5 changes: 5 additions & 0 deletions versions/1.20.2/carpet-tis-addition.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ accessible class net/minecraft/village/raid/Raid$Status
accessible class net/minecraft/server/command/FillCommand$Mode
accessible class net/minecraft/world/SpawnDensityCapper$DensityCap
accessible class net/minecraft/world/block/ChainRestrictedNeighborUpdater$Entry

# XXX: If without and use `targets = "xxxx"` instead, mixin will complain about "Mixin target xxxx is public and should be specified in value",
# even if they are actually protected classes
accessible class net/minecraft/block/entity/CalibratedSculkSensorBlockEntity$Callback
accessible class net/minecraft/block/entity/SculkSensorBlockEntity$VibrationCallback
5 changes: 5 additions & 0 deletions versions/1.20.4/carpet-tis-addition.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ accessible class net/minecraft/village/raid/Raid$Status
accessible class net/minecraft/server/command/FillCommand$Mode
accessible class net/minecraft/world/SpawnDensityCapper$DensityCap
accessible class net/minecraft/world/block/ChainRestrictedNeighborUpdater$Entry

# XXX: If without and use `targets = "xxxx"` instead, mixin will complain about "Mixin target xxxx is public and should be specified in value",
# even if they are actually protected classes
accessible class net/minecraft/block/entity/CalibratedSculkSensorBlockEntity$Callback
accessible class net/minecraft/block/entity/SculkSensorBlockEntity$VibrationCallback
5 changes: 5 additions & 0 deletions versions/1.20.6/carpet-tis-addition.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ accessible class net/minecraft/village/raid/Raid$Status
accessible class net/minecraft/server/command/FillCommand$Mode
accessible class net/minecraft/world/SpawnDensityCapper$DensityCap
accessible class net/minecraft/world/block/ChainRestrictedNeighborUpdater$Entry

# XXX: If without and use `targets = "xxxx"` instead, mixin will complain about "Mixin target xxxx is public and should be specified in value",
# even if they are actually protected classes
accessible class net/minecraft/block/entity/CalibratedSculkSensorBlockEntity$Callback
accessible class net/minecraft/block/entity/SculkSensorBlockEntity$VibrationCallback
5 changes: 5 additions & 0 deletions versions/1.21/carpet-tis-addition.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ accessible class net/minecraft/village/raid/Raid$Status
accessible class net/minecraft/server/command/FillCommand$Mode
accessible class net/minecraft/world/SpawnDensityCapper$DensityCap
accessible class net/minecraft/world/block/ChainRestrictedNeighborUpdater$Entry

# XXX: If without and use `targets = "xxxx"` instead, mixin will complain about "Mixin target xxxx is public and should be specified in value",
# even if they are actually protected classes
accessible class net/minecraft/block/entity/CalibratedSculkSensorBlockEntity$Callback
accessible class net/minecraft/block/entity/SculkSensorBlockEntity$VibrationCallback

0 comments on commit ca19e40

Please sign in to comment.