Skip to content

Commit

Permalink
add rule updateSuppressionSimulator
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Jul 16, 2023
1 parent abfc819 commit 414c408
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 5 deletions.
23 changes: 18 additions & 5 deletions patches/net/minecraft/block/BlockRailPowered.java.patch
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
--- a/net/minecraft/block/BlockRailPowered.java
+++ b/net/minecraft/block/BlockRailPowered.java
@@ -1,5 +1,8 @@
@@ -1,6 +1,11 @@
package net.minecraft.block;

+import carpet.helpers.UpdateSuppressionSimulator;
+import carpet.logging.microtiming.MicroTimingLoggerManager;
+import carpet.logging.microtiming.enums.EventType;
+import carpet.settings.CarpetSettings;
import net.minecraft.block.state.IBlockState;
+import net.minecraft.init.Blocks;
import net.minecraft.state.BooleanProperty;
import net.minecraft.state.EnumProperty;
@@ -11,8 +14,9 @@
import net.minecraft.state.IProperty;
@@ -11,8 +16,9 @@
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
Expand All @@ -20,7 +23,7 @@
{
public static final EnumProperty<RailShape> SHAPE = BlockStateProperties.RAIL_SHAPE_STRAIGHT;
public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
@@ -25,7 +29,8 @@
@@ -25,7 +31,8 @@

protected boolean findPoweredRailSignal(World worldIn, BlockPos pos, IBlockState state, boolean p_176566_4_, int p_176566_5_)
{
Expand All @@ -30,16 +33,26 @@
{
return false;
}
@@ -177,15 +182,19 @@
@@ -177,15 +184,29 @@
boolean flag = state.get(POWERED);
boolean flag1 = worldIn.isBlockPowered(pos) || this.findPoweredRailSignal(worldIn, pos, state, true, 0) || this.findPoweredRailSignal(worldIn, pos, state, false, 0);

+ logPowered(worldIn, pos, flag1); // RSMM
+
if (flag1 != flag)
{
+ // TISCM updateSuppressionSimulator
+ if (UpdateSuppressionSimulator.isActivated())
+ {
+ if (!flag1 && worldIn.getBlockState(pos.down()).getBlock() == Blocks.EMERALD_ORE)
+ {
+ UpdateSuppressionSimulator.kaboom();
+ }
+ }
+
worldIn.setBlockState(pos, state.with(POWERED, Boolean.valueOf(flag1)), 3);
+ MicroTimingLoggerManager.onEmitBlockUpdate(worldIn, this, pos, EventType.ACTION_START, "updateState"); // TISCM Micro Timing logger
+
worldIn.notifyNeighborsOfStateChange(pos.down(), this);

if (state.get(SHAPE).isAscending())
Expand All @@ -50,7 +63,7 @@
}
}

@@ -333,4 +342,22 @@
@@ -333,4 +354,22 @@
{
builder.add(SHAPE, POWERED);
}
Expand Down
61 changes: 61 additions & 0 deletions src/main/java/carpet/helpers/UpdateSuppressionSimulator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package carpet.helpers;

import com.google.common.collect.ImmutableMap;

import java.util.Map;

public class UpdateSuppressionSimulator
{
private static final Map<String, Runnable> SUPPORTED_ERRORS = ImmutableMap.of(
"StackOverflowError", () -> {
throw new StackOverflowError("TISCM UpdateSuppressionSimulator");
},
"OutOfMemoryError", () -> {
throw new OutOfMemoryError("TISCM UpdateSuppressionSimulator");
},
"ClassCastException", () -> {
throw new ClassCastException("TISCM UpdateSuppressionSimulator");
}
);

private static final Runnable DUMMY = () -> {};
private static Runnable nuke = DUMMY;

public static boolean isActivated()
{
return nuke != DUMMY;
}

public static void kaboom()
{
nuke.run();
}

public static boolean tryAcceptRule(String ruleValue)
{
switch (ruleValue)
{
case "true":
nuke = SUPPORTED_ERRORS.values().iterator().next();
break;
case "false":
nuke = DUMMY;
break;
default:
boolean[] ok = {false};
SUPPORTED_ERRORS.forEach((key, value) -> {
if (key.equalsIgnoreCase(ruleValue))
{
nuke = value;
ok[0] = true;
}
});
if (!ok[0])
{
return false;
}
break;
}
return true;
}
}
22 changes: 22 additions & 0 deletions src/main/java/carpet/settings/CarpetSettings.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package carpet.settings;

import carpet.CarpetServer;
import carpet.helpers.UpdateSuppressionSimulator;
import carpet.logging.microtiming.enums.MicroTimingTarget;
import carpet.logging.microtiming.marker.MicroTimingMarkerManager;
import carpet.utils.Messenger;
Expand Down Expand Up @@ -894,6 +895,27 @@ public String validate(CommandSource source, ParsedRule<String> currentRule, Str
)
public static boolean undeadDontBurnInSunlight = false;

@Rule(
desc = "Activator / Powered rail on an emerald ore simulates a update suppressor",
extra = {
"Right before a powered activator / powered rail on an emerald ore setting its powered state to false, throw the given JVM throwable",
"false: rule disabled; true: rule enable and use StackOverflowError; others: feature enable and use given throwable"
},
category = CREATIVE,
options = {"false", "true", "StackOverflowError", "OutOfMemoryError", "ClassCastException"},
validate = UpdateSuppressionSimulatorValidator.class
)
public static String updateSuppressionSimulator = "false";

public static class UpdateSuppressionSimulatorValidator extends Validator<String>
{
@Override
public String validate(CommandSource source, ParsedRule<String> currentRule, String newValue, String string)
{
return UpdateSuppressionSimulator.tryAcceptRule(newValue) ? newValue : null;
}
}


// /$$$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$ /$$ /$$
//|__ $$__/|_ $$_/ /$$__ $$ /$$__ $$| $$$ /$$$
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/assets/carpet/lang/zh_cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,12 @@ rule:
turtleEggTrampledDisabled:
name: 禁用海龟蛋被践踏
desc: 阻止海龟蛋因实体踩踏而破坏
updateSuppressionSimulator:
name: 更新抑制模拟器
desc: 绿宝石矿石上方的激活/充能铁轨可模拟更新抑制器
extra:
'0': 在绿宝石矿石上已亮起的激活/充能铁轨将要熄灭时,抛出所提供的JVM异常
'1': 'false: 关闭规则; true: 启用规则并使用StackOverflowError; 其他: 启用规则并使用所给异常'
visualizeProjectileLoggerEnabled:
name: 可视化投掷物记录器
desc: 启用可视化投掷物记录器
Expand Down

0 comments on commit 414c408

Please sign in to comment.