Skip to content

Commit

Permalink
Added rule repeaterHalfDelay: Halve the delay of redstone repeaters u…
Browse files Browse the repository at this point in the history
…pon a redstone ore
  • Loading branch information
Fallen-Breath committed Nov 25, 2020
1 parent 865bd7a commit 1dd76c1
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
- [POI更新开关](#POI更新开关-poiUpdates)
- [TNT引信时长](#TNT引信时长-tntFuseDuration)
- [实体速度丢失](#实体速度丢失-entityMomentumLoss)
- [中继器延迟折半](#中继器延迟折半-repeaterHalfDelay)

## [监视器](#监视器列表)

Expand Down Expand Up @@ -453,6 +454,18 @@
- 分类: `TIS`, `EXPERIMENTAL`


## 中继器延迟折半 (repeaterHalfDelay)

当红石中继器位于红石矿上方时,红石中继器的延迟将减半

延迟将会由 2, 4, 6, 8 游戏刻变为 1, 2,3 ,4 游戏刻

- 类型: `boolean`
- 默认值: `true`
- 参考选项: `false`, `true`
- 分类: `TIS`, `CREATIVE`


-----------

# 监视器列表
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/assets/carpettisaddition/lang/zh_cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "被移除",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/carpet-tis-addition.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1dd76c1

Please sign in to comment.