经验感知红石 XpAwareRedstone
改造 Tinkers’ 的红石发射器,使其按持有者工具的等级调整红石信号强度。
- 实现:
iguanaman.iguanatweakstconstruct.leveling.modifiers.ModXpAwareRedstone - 继承:
tconstruct.smeltery.blocks.RedstoneReceiver extends tconstruct.library.crafting.BlockModifierPowered - 注册:
tconstruct.smeltery.TinkerWorld.redstoneReceiver
方块实体升级
IguanaToolLeveling 在 init 阶段做客户端与服务端分离的注册:
if (event.getSide() == Side.CLIENT) {
// 客户端:把默认 TinkerWorld.redstoneReceiver 的 TE 换成 ModXpAwareRedstone
TileEntityRegistry.instance.registerTileEntity(
TinkerWorld.redstoneReceiver, ModXpAwareRedstone.class, "Redstone Receiver");
// 渲染器换成 9 个面的方块
BlockRenderRegistry.registerBlockRenderer(TinkerWorld.redsideReceiver, new RedstoneRend());
}
源码注释解释了为何用条件分支而非 TileEntity.replaceTileEntity(那会留下一个坏掉的 TileEntity):
// we use TileEntityRegistry directly here, because TileEntity.replaceTileEntity breaks TinkerSmeltery's
// instanceof check in BlockRedstoneReceiver.getWeakPowerLevel(), and it also leaves a broken TileEntity
// (TileEntity instead of TileEntityTinkerRedstone) in the world when the block is removed.
ModXpAwareRedstone 自身在静态初始化块中再 registerTileEntity(ModXpAwareRedstone.class, ModXpAwareRedstone.class, "Redstone Receiver") —— 即两个名字分别注册到两个方块上。
TileEntityRedstone 侧的客户端 RedstoneRend(leveling/handlers/RedstoneRend.java)重写模型为 9 面立方体贴图(redstoneCube_* 系列)。
信号强度算法
ModXpAwareRedstone.getRedstoneLevel(World world, int x, int y, int z, int side, TileEntity tile, int strength):
e = ((TileEntityTinkerRedstone) tile).effectiveSide;- 逐层叠加
if (side == e) { result += strength; return true; }; - 判断
world.isSideSolid(...)后继续累加strength; - 向上取整:
return (int) Math.ceil(((float) result) / 15f * 15f)。
真正的分级逻辑在父类 BlockModifierPowered 与 RedstoneReceiver 中,强度由 maxBoost / fuelCap 等字段与持有者手中的 ToolCore 等级共同决定。
前置条件
红石发射器要工作,玩家必须手持一件带等级数据的 Tinkers’ 工具(hasLevel(tags))。若手持物品没有 InfiTool 等级数据,强度回落到基础值。
与随机奖励的关联
红石相关奖励(REDSTONE 权重在工具 45 / 弓 100)见 随机奖励修饰符。本修饰符没有独立工作台配方,红石发射器本体是 Tinkers’ 的物品,本 mod 只替换其方块实体。