diff --git a/README.md b/README.md index 0ad57a155..461c20bb4 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,7 @@ Use with carpet mod in the same Minecraft version. Use newer carpet mod versions - [poiUpdates](#poiUpdates) - [tntFuseDuration](#tntFuseDuration) - [entityMomentumLoss](#entityMomentumLoss) +- [repeaterHalfDelay](#repeaterHalfDelay) ## [Loggers](#logger-list) @@ -451,6 +452,18 @@ Set it to `false` to disable entity axis momentum cancellation if it's above 10m - Categories: `TIS`, `EXPERIMENTAL` +## repeaterHalfDelay + +Halve the delay of redstone repeaters upon a redstone ore + +The delay will change from 2, 4, 6 or 8 game tick instead of 1, 2, 3 or 4 game tick + +- Type: `boolean` +- Default value: `true` +- Suggested options: `false`, `true` +- Categories: `TIS`, `CREATIVE` + + ----------- # Logger List diff --git a/README_CN.md b/README_CN.md index 4c6f24c9e..d7528cc56 100644 --- a/README_CN.md +++ b/README_CN.md @@ -45,6 +45,7 @@ - [POI更新开关](#POI更新开关-poiUpdates) - [TNT引信时长](#TNT引信时长-tntFuseDuration) - [实体速度丢失](#实体速度丢失-entityMomentumLoss) +- [中继器延迟折半](#中继器延迟折半-repeaterHalfDelay) ## [监视器](#监视器列表) @@ -453,6 +454,18 @@ - 分类: `TIS`, `EXPERIMENTAL` +## 中继器延迟折半 (repeaterHalfDelay) + +当红石中继器位于红石矿上方时,红石中继器的延迟将减半 + +延迟将会由 2, 4, 6, 8 游戏刻变为 1, 2,3 ,4 游戏刻 + +- 类型: `boolean` +- 默认值: `true` +- 参考选项: `false`, `true` +- 分类: `TIS`, `CREATIVE` + + ----------- # 监视器列表 diff --git a/src/main/java/carpettisaddition/CarpetTISAdditionSettings.java b/src/main/java/carpettisaddition/CarpetTISAdditionSettings.java index 57a307f67..7fe586e2f 100644 --- a/src/main/java/carpettisaddition/CarpetTISAdditionSettings.java +++ b/src/main/java/carpettisaddition/CarpetTISAdditionSettings.java @@ -374,6 +374,15 @@ public String description() ) public static boolean entityMomentumLoss = true; + @Rule( + desc = "Halve the delay of redstone repeaters upon a redstone ore", + extra = { + "The delay will change from 2, 4, 6 or 8 game tick instead of 1, 2, 3 or 4 game tick" + }, + category = {TIS, CREATIVE} + ) + public static boolean repeaterHalfDelay = false; + /* * Declare rules above this * General validators down below diff --git a/src/main/java/carpettisaddition/mixins/rule/repeaterHalfDelay/AbstractRedstoneGateBlockMixin.java b/src/main/java/carpettisaddition/mixins/rule/repeaterHalfDelay/AbstractRedstoneGateBlockMixin.java new file mode 100644 index 000000000..3b41cffa8 --- /dev/null +++ b/src/main/java/carpettisaddition/mixins/rule/repeaterHalfDelay/AbstractRedstoneGateBlockMixin.java @@ -0,0 +1,59 @@ +package carpettisaddition.mixins.rule.repeaterHalfDelay; + +import carpettisaddition.CarpetTISAdditionSettings; +import net.minecraft.block.AbstractRedstoneGateBlock; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.block.RepeaterBlock; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +import java.util.Random; + +@Mixin(AbstractRedstoneGateBlock.class) +public abstract class AbstractRedstoneGateBlockMixin +{ + @Shadow protected abstract int getUpdateDelayInternal(BlockState state); + + @Redirect( + method = "scheduledTick", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/block/AbstractRedstoneGateBlock;getUpdateDelayInternal(Lnet/minecraft/block/BlockState;)I" + ) + ) + private int modifyRepeaterDelay(AbstractRedstoneGateBlock abstractRedstoneGateBlock, BlockState state1, BlockState state2, ServerWorld world, BlockPos pos, Random random) + { + return this.getModifiedDelay(abstractRedstoneGateBlock, world, pos, state1); + } + + @Redirect( + method = "updatePowered", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/block/AbstractRedstoneGateBlock;getUpdateDelayInternal(Lnet/minecraft/block/BlockState;)I" + ) + ) + private int modifyRepeaterDelay(AbstractRedstoneGateBlock abstractRedstoneGateBlock, BlockState state1, World world, BlockPos pos, BlockState state2) + { + return this.getModifiedDelay(abstractRedstoneGateBlock, world, pos, state1); + } + + private int getModifiedDelay(AbstractRedstoneGateBlock abstractRedstoneGateBlock, World world, BlockPos pos, BlockState state) + { + int delay = this.getUpdateDelayInternal(state); + if (CarpetTISAdditionSettings.repeaterHalfDelay) + { + if (abstractRedstoneGateBlock instanceof RepeaterBlock && world.getBlockState(pos.down()).getBlock() == Blocks.REDSTONE_ORE) + { + delay /= 2; + } + } + return delay; + } +} diff --git a/src/main/resources/assets/carpettisaddition/lang/zh_cn.json b/src/main/resources/assets/carpettisaddition/lang/zh_cn.json index 5dcb08e07..db970fad4 100644 --- a/src/main/resources/assets/carpettisaddition/lang/zh_cn.json +++ b/src/main/resources/assets/carpettisaddition/lang/zh_cn.json @@ -131,6 +131,10 @@ "rule.entityMomentumLoss.name": "实体速度丢失", "rule.entityMomentumLoss.desc": "将其设为 false 以关闭从磁盘载入时实体超过10m/gt部分的沿轴速度的丢失", + "rule.repeaterHalfDelay.name": "中继器延迟折半", + "rule.repeaterHalfDelay.desc": "当红石中继器位于红石矿上方时,红石中继器的延迟将减半", + "rule.repeaterHalfDelay.extra.0": "延迟将会由2,4,6,8游戏刻变为1,2,3,4游戏刻", + "logger.ticket.added": "被添加", "logger.ticket.removed": "被移除", diff --git a/src/main/resources/carpet-tis-addition.mixins.json b/src/main/resources/carpet-tis-addition.mixins.json index 86d03d312..71ee23da6 100644 --- a/src/main/resources/carpet-tis-addition.mixins.json +++ b/src/main/resources/carpet-tis-addition.mixins.json @@ -75,6 +75,7 @@ "rule.renewableDragonEgg.DragonEggBlockMixin", "rule.renewableDragonHead.EnderDragonEntityMixin", "rule.renewableElytra.PhantomEntityMixin", + "rule.repeaterHalfDelay.AbstractRedstoneGateBlockMixin", "rule.sandDupingFix.FallingBlockEntityMixin", "rule.structureBlockLimit.StructureBlockBlockEntityMixin", "rule.structureBlockLimit.UpdateStructureBlockC2SPacketMixin",