Skip to content

Commit

Permalink
add support for anvilCanRepairUseIronBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
Eyre-S committed Jun 22, 2024
1 parent f294e2b commit ea2da07
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ There may still under WIP status.
- [x] anvilUseItemCost
- [x] anvilRenameCost -- only implements the on/off (1/0) yet
- [x] anvilTooExpensiveLimit
- [x] anvilCanRepairedUseIronBlock
- [x] anvilCanRepairUseIronBlock
- [x] tickFreezeWhenNoPlayers
- [ ] tickFreezeWhenNoPlayersUseDeepFreeze
- [ ] petsPreventOwnerDamage
Expand Down
21 changes: 17 additions & 4 deletions docs/rules.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,13 @@
> 分类 : `nukos` | `生存` | `铁砧` \
> 自版本 : `0.2.0` \
> values : <u>`true`</u> | `false` \
> 需要匹配客户端 : *部分*(仅在 *仅重命名* 情况下需要) \
> WIP : 部分(待修复在无消费情况下无法取出问题的问题)
> 需要匹配客户端 : *部分*(仅在消费为 0 的情况下需要)
控制铁砧是否对于重命名收取费用。

默认为 `true`,即为原版行为:重命名花费 `1` 级经验。设置为 `false` 将会让重命名完全免费。

由于在原版客户端上,在消费为 0 时无法取出物品,这会导致没有安装本 mod 的原版客户端无法对物品进行*仅重命名*的操作:表现为重命名后的物品可以显示在输出槽位但是无法取出。<sup>TODO:此 mod 在客户端对此问题的修复</sup>
由于在原版客户端上,在消费为 0 时无法取出物品,这会导致没有安装本 mod 的原版客户端无法对物品进行*仅重命名*的操作:表现为重命名后的物品可以显示在输出槽位但是无法取出。

这个设置不影响*仅重命名*时最高 `39` 的消费限制;也与后面的 [anvilCustomNameSerializer](#anvilcustomnameserializer) 设置无关。

Expand Down Expand Up @@ -99,7 +98,7 @@

原版的默认值是 `40`,你可以在此设置为任何的非负整数以允许更高消费的附魔合成等等,也可以设置为更小的数以对铁砧进行更多的限制。当一个铁砧合成的最终经验等级消费超过设置的值之后,输出栏的物品将会被清空(即无法合成),同时将会把最终消费设置为 `Integer.MAX` 以确保客户端将会正确显示 *过于昂贵*

如果此值设置为大于 `40` ,在最终消费大于 `40` 但小于设置的最大允许值的情况下,服务端将会正确回报一个大于 `40` 的最终消费和输出物品。但是在没有被修改的原版客户端里,由于 Mojang 在客户端**硬编码**了大于 `40` 后就显示 *过于昂贵* 并不允许取出输出物品的逻辑,所以如果客户端没有安装此 mod(或者一些别的修复此问题的 mod)的话,大于 `40` 消费的物品仍然是无法取出的。<sup>TODO:此 mod 在客户端对此问题的修复</sup>
如果此值设置为大于 `40` ,在最终消费大于 `40` 但小于设置的最大允许值的情况下,服务端将会正确回报一个大于 `40` 的最终消费和输出物品。但是在没有被修改的原版客户端里,由于 Mojang 在客户端**硬编码**了大于 `40` 后就显示 *过于昂贵* 并不允许取出输出物品的逻辑,所以如果客户端没有安装此 mod(或者一些别的修复此问题的 mod)的话,大于 `40` 消费的物品仍然是无法取出的。

### anvilCustomNameSerializer

Expand Down Expand Up @@ -127,3 +126,17 @@
铁砧将名称设置到输出物品上的行为是一个服务端行为,所以可以正常的在原版客户端上使用此规则为物品设置富文本名称。

由于铁砧在铁砧的重命名输入框中显示物品名称是一个客户端行为,而且原版并没有处理物品的*自定义名称*为富文本的情况,这会导致一个带有富文本的物品放在铁砧的主要输入口后,其富文本会在客户端被抹去。这会导致在**原版客户端**下对一个拥有富文本的物品使用铁砧后其富文本会**消失**(这个过程是**被认为是一次重命名**的)。有两种方法可以解决这个问题:在铁砧里的输入框里手动设置一个和物品的富文本名称相同的富文本名称;或者在客户端安装此 mod。

### anvilCanRepairUseIronBlock

> 本地化名称 : anvilCanRepairUseIronBlock |铁块修复铁砧 \
> 分类 : `nukos` | `生存` | `铁砧` \
> 自版本 : `0.5.0` \
> values : <u>`false`</u> | `true` \
> 需要匹配客户端 : 不需要
可以通过使用*铁块*右键一个有破损的铁砧来修复这个铁砧。

每个*铁块*(每次右键)将能够修复一级这个铁砧的损坏程度(从*破损的铁砧**开裂的铁砧*,或从*开裂的铁砧**铁砧*),这个*铁块*将被消耗,同时玩家的*铁块**使用统计数据*将会增加 1。右键一个没有破损的铁砧没有效果。

这个动作将会产生 *PP 更新*,不会产生 *NC 更新*
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ loader_version=0.15.11
fabric_version=0.92.2+1.20.1

# Mod Properties
mod_version=0.4.2
mod_version=0.5.0
maven_group=cc.sukazyo
archives_base_name=carpet_nukos_addition

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public static AnvilAlgorithm getCurrentAnvilAlgorithm () {
)
public static String anvilCustomNameSerializer = "vanilla";

@Rule(categories = {NukosCategoryKeys.NUKOS, RuleCategory.SURVIVAL, NukosCategoryKeys.ANVIL})
public static boolean anvilCanRepairUseIronBlock = false;

@Rule(categories = {NukosCategoryKeys.NUKOS, RuleCategory.OPTIMIZATION, RuleCategory.EXPERIMENTAL, NukosCategoryKeys.TICK})
public static Boolean tickFreezeWhenNoPlayers = false;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cc.sukazyo.nukos.carpet.anvils.extend;

import net.minecraft.block.AnvilBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;

public class AnvilBlockExt {

public static boolean isBroken (BlockState currentState) {
return (currentState.isOf(Blocks.DAMAGED_ANVIL) || currentState.isOf(Blocks.CHIPPED_ANVIL));
}

public static BlockState getRepairedState (BlockState currentState) {
if (currentState.isOf(Blocks.DAMAGED_ANVIL))
return Blocks.CHIPPED_ANVIL.getDefaultState().with(AnvilBlock.FACING, currentState.get(AnvilBlock.FACING));
if (currentState.isOf(Blocks.CHIPPED_ANVIL))
return Blocks.ANVIL.getDefaultState().with(AnvilBlock.FACING, currentState.get(AnvilBlock.FACING));
return currentState;
}

}
48 changes: 48 additions & 0 deletions src/main/java/cc/sukazyo/nukos/carpet/mixin/MixinAnvilBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cc.sukazyo.nukos.carpet.mixin;

import cc.sukazyo.nukos.carpet.CarpetNukosSettings;
import cc.sukazyo.nukos.carpet.ModCarpetNukos;
import cc.sukazyo.nukos.carpet.anvils.extend.AnvilBlockExt;
import net.minecraft.block.AnvilBlock;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FallingBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.stat.Stats;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(AnvilBlock.class)
public abstract class MixinAnvilBlock extends FallingBlock {
public MixinAnvilBlock (Settings settings) { super(settings); }

@Inject(method = "onUse", at = @At("HEAD"), cancellable = true)
public void inject_onUse (
BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit,
CallbackInfoReturnable<ActionResult> cir
) {
if (!CarpetNukosSettings.anvilCanRepairUseIronBlock) return;
if (world.isClient) return;
ItemStack item = player.getStackInHand(hand);
if (AnvilBlockExt.isBroken(state) && item.isOf(Blocks.IRON_BLOCK.asItem())) {
ModCarpetNukos.LOGGER.info("fixed anvil!!!");
world.setBlockState(pos, AnvilBlockExt.getRepairedState(state), 2);
world.playSound(null, pos, SoundEvents.BLOCK_ANVIL_USE, SoundCategory.BLOCKS, 1f, 1f);
if (!player.getAbilities().creativeMode)
item.decrement(1);
player.increaseStat(Stats.USED.getOrCreateStat(Blocks.IRON_BLOCK.asItem()), 1);
cir.setReturnValue(ActionResult.CONSUME);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"carpet.rule.anvilAlgorithm.desc": "Customize the algorithm that calculates the result and costs for a anvil. Independents with item's anvil-use-cost rollup algorithm.",

"carpet.rule.anvilCustomNameSerializer.name": "anvilCustomNameSerializer",
"carpet.rule.anvilCustomNameSerializer.desc": "Customize the serializer used for anvil renaming items. May available only on this mod installed on client. Only affects when using mod anvil algorithms."
"carpet.rule.anvilCustomNameSerializer.desc": "Customize the serializer used for anvil renaming items. May available only on this mod installed on client. Only affects when using mod anvil algorithms.",

"carpet.rule.anvilCanRepairUseIronBlock.name": "anvilCanRepairUseIronBlock",
"carpet.rule.anvilCanRepairUseIronBlock.desc": "Can repair a breaking anvil by right-clicking it with an iron block iron hand."

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"carpet.rule.anvilAlgorithm.desc": "自定义铁砧的输出物品和物品/经验消耗算法。与物品累加惩罚算法独立。",

"carpet.rule.anvilCustomNameSerializer.name": "铁砧重命名物品的文字序列化器",
"carpet.rule.anvilCustomNameSerializer.desc": "自定义铁砧重命名名称序列化器以支持更丰富的物品名称格式。可能仅在此 mod 在客户端安装后有效。仅在使用本 mod 的铁砧算法时生效。"
"carpet.rule.anvilCustomNameSerializer.desc": "自定义铁砧重命名名称序列化器以支持更丰富的物品名称格式。可能仅在此 mod 在客户端安装后有效。仅在使用本 mod 的铁砧算法时生效。",

"carpet.rule.anvilCanRepairUseIronBlock.name": "铁块修复铁砧",
"carpet.rule.anvilCanRepairUseIronBlock.desc": "可以使用铁块右键一个破损的铁砧来修复它。"

}
1 change: 1 addition & 0 deletions src/main/resources/carpet_nukos_addition.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"package": "cc.sukazyo.nukos.carpet.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"MixinAnvilBlock",
"MixinAnvilScreenHandler"
],
"injectors": {
Expand Down

0 comments on commit ea2da07

Please sign in to comment.