跳转至

从 7.4.0 更新到 8.0.0

新的数据保存/同步系统

新增了用于保存和同步对象字段的系统。迁移说明参见此页面。

GTPM 1.21.1 的配方、能量、存档和整合包入口见当前迁移指南。

机器重构第 1 部分:MetaMachine 与 MetaMachineBlockEntity 合并

为了简化机器系统并移除旧的、不必要的抽象,机器类的许多方面已被重构和修改。

  • MetaMachineBlockEntity(MMBE) 类已被移除,MetaMachine(MM) 现在是 BlockEntity。
  • MMBE 的大多数方法和属性已移动到 MM。
  • IMachineBlockEntity 接口已被移除。请直接使用 MetaMachineBlock。
  • 许多所有 block entities 通用的方法已移动到 IGregtechBlockEntity 接口。
  • 机器实例创建函数的签名从 (IMachineBlockEntity) -> MetaMachine 改为 (BlockEntityCreationInfo) -> MetaMachine。

对 MMBE 的引用通常可以替换为对 MM 的引用:

/////// OLD
if (level.getBlockEntity(getPos()) instanceof MetaMachineBlockEntity mmbe) {
    MetaMachine machine = mmbe.getMetaMachine();
    ...
}

////// NEW
if (level.getBlockEntity(getPos()) instanceof MetaMachine machine) {
    ...
}

机器构造函数中的 IMachineBlockEntity holder 参数已替换为 BlockEntityCreationInfo info:

////// OLD
public MetaMachine(IMachineBlockEntity holder);
////// NEW
public MetaMachine(BlockEntityCreationInfo info);
为确保与默认 BlockEntity 方法保持一致,多个接口和类中的一些方法已重命名:

  • BlockPos getPipePos() -> BlockPos getBlockPos()
  • Level getPipeLevel() -> Level getLevel()
  • BlockPos getPos() -> BlockPos getBlockPos()
  • BlockState getState() -> BlockState getBlockState()
  • boolean isInvalid() -> boolean isRemoved()
  • void markAsDirty() -> void markAsChanged()

合并进 MetaMachine 的接口与行为

部分接口已被移除,其方法现在直接属于 MetaMachine 类。

  • IMachineLife - 使用 MetaMachine::onMachinePlaced 和 MetaMachine::onMachineDestroyed。
  • IMachineModifyDrops - 使用 MetaMachine::modifyDrops。
  • IInteractedMachine - 使用 MetaMachine::onUse 和 MetaMachine::onLeftClick。

机器交互重构

处理机器交互的方法已经改变,现在都接收单个 ExtendedUseOnContext 参数。 机器交互已拆分为两个方法:MetaMachine::onUse 和 MetaMachine::onUseWithItem。

机器重构第 2 部分:新的机器 Trait 系统

新增了将 traits 与自定义行为附加到机器上的系统,许多机器接口和 traits 现在都使用这个新系统。

机器构造函数与 trait 初始化变更

为了简化机器实例创建,大量机器的构造函数已发生变化。此外,用于创建 trait 的方法也已移除,现在成为机器构造函数的一部分。

所有机器

  • 将第一个构造函数参数 IMachineBlockEntity holder 替换为 BlockEntityCreationInfo info

TieredEnergyMachine

  • 移除了 createEnergyContainer 方法
  • 构造函数现在有一个可选的 Supplier<NotifiableEnergyContainer> 参数

WorkableTieredMachine

  • 移除了 createRecipeLogic、createImportItemHandler、createExportItemHandler、createImportFluidHandler、createExportFluidHandler 方法
  • 新增了一个构造函数:
    • BlockEntityCreationInfo info
    • int tier
    • Supplier<RecipeLogic> recipeLogicSupplier Recipe logic supplier,默认使用标准 RecipeLogic 类。
    • int importSlots 物品输入槽数量,默认值为机器默认 recipe type 的槽位数量。
    • int exportSlots 同上,但用于物品输出槽。
    • int fluidImportSlots 同上,但用于流体输入槽。
    • int fluidExportSlots 同上,但用于流体输出槽。
    • Int2IntFunction tankScalingFunction 流体槽容量缩放函数。

WorkableMultiblockMachine、WorkableElectricMultiblockMachine 与 SteamWorkableMachine

  • 移除了 createRecipeLogic 方法
  • 构造函数现在有一个可选的 Supplier<RecipeLogic> 参数,默认使用标准 RecipeLogic 类

新系统示例

重要迁移说明:

Traits 必须通过对要附加的 trait 调用 attachTrait(MachineTrait trait),直接附加到机器上。 过去,所有机器 traits 都以机器作为第一个参数来构造。

/////// OLD
this.itemHandler = new NotifiableItemStackHandler(this, 0, IO.BOTH);

////// NEW
this.itemHandler = attachTrait(new NotifiableItemStackHandler(0, IO.BOTH))
迁移时,请从 machine trait 构造函数中移除 this 参数,并改为附加 trait。

新的 AutoOutputTrait 示例:

public class CustomDrumMachine extends MetaMachine {

  protected final NotifiableFluidTank tank;
  public final AutoOutputTrait autoOutput;

  public DrumMachine(BlockEntityCreationInfo info, int capacity) {
    super(info);

    // Traits must be attached in the constructor.

    this.tank = attachTrait(new NotifiableFluidTank(1, capacity, IO.BOTH));

    // Registers an auto output trait that provides fluid output behaviour for the given fluid tank.
    this.autoOutput = attachTrait(AutoOutputTrait.ofFluids(tank));

    autoOutput.setFluidOutputDirection(Direction.DOWN);
    autoOutput.setFluidOutputDirectionValidator(d -> d == Direction.DOWN);
  }

  // Any code can query traits from a machine
  public static void queryTraits(MetaMachine machine) {

      // Returns a trait with the given type, or null.
      AutoOutputTrait autoOutputTrait = machine.getTraitHolder().getTrait(AutoOutputTrait.TYPE);

      Optional<RecipeLogic> recipeLogicOptional = machine.getTraitHolder().getTrait(RecipeLogic.TYPE);

      // Gets all traits with the specified type.
      List<NotifiableItemStackHandler> allItemStackHandlers = machine.getTraitHolder().getTraits(NotifiableItemStackHandler.TYPE);

  }
}

已移除接口

大量机器功能接口已被移除,其功能已合并进标准 MetaMachine 类,或改为使用新的机器 trait 系统:

  • ITurbineMachine 直接使用 LargeTurbineMachine 类。
  • IRotorHolderMachine 直接使用 RotorHolderMachine 类。
  • IMultiController 直接使用 MultiblockControllerMachine 类。
  • IMufflerMachine 直接使用 MufflerMachine 类。
  • ICleanroomReceiver 与 ICleanroomProvider - 使用 CleanroomReceiverTrait 和 CleanroomProviderTrait。
  • IAutoOutputBoth、IAutoOutputFluid、IAutoOutputItem - 使用 AutoOutputTrait。
  • IExplosionMachine - 使用 EnvironmentalExplosionTrait、GTUtil::doExplosion 和 GTUtil::setOnFire
  • IEnvironmentalHazardCleaner 使用 EnvironmentalHazardCleanerTrait
  • ILocalizedHazardEmitter - 使用 LocalizedHazardEmitterTrait
  • IExhaustVentMachine - 使用 ExhaustVentMachineTrait
  • IHPCAComponentHatch - 使用 HPCAComponentTrait
  • IHPCAComputationProvider - 使用 HPCAComputationProviderTrait
  • IHPCACoolantProvider - 使用 HPCACoolantProviderTrait
  • IFluidRendererMulti - 使用 MultiblockFluidRendererTrait

连接纹理重新实现

GregTech Post Modern 直接读取 .png.mcmeta 中的 gtpm 元数据段。材质包、附属模组和整合包可以按以下顺序转换旧版 LDLib 纹理元数据。

  1. 匹配:"ldlib":([\s\{]*)"connection"(:\s".*?")(?:,\s.*)? 替换为:"gtpm":$1"connection_texture"$2
  2. 匹配:\s*\},\s*"shimmer":\s*\{(\s*"bloom":.*) 替换为:,$1
  3. 匹配:(\{\s*)"shimmer":(\s*\{\s*"bloom":.*) 替换为:$1"gtpm":$2

其他变更

  • BlastingRecipeBuilder、CampfireRecipeBuilder、SmeltingRecipeBuilder 和 SmokingRecipeBuilder 已合并进 SimpleCookingRecipeBuilder
    • 示例用法:SimpleCookingRecipeBuilder.campfireCooking("cooking_chicken").input(new ItemStack(Items.CHICKEN)).output(new ItemStacks(Items.COOKED_CHICKEN)).cookingTime(100).experience(100).save(provider);
  • GTFluidImpl 已合并进 GTFluid,请使用 GTFluid.Flowing 和 GTFluid.Source 替代 GTFluidImpl.Flowing 和 GTFluidImpl.Source。
  • Item behaviors 已移动到 common/item/behavior,部分 items 已从 api/item 移动到 common/item。
  • compat.minimap.surfaceRockProspectRange 和 compat.minimap.oreBlockProspectRange 配置的最小值从 -1 改为 0。设为 0 时,该行为仍然禁用。
  • 所有 materials 现在都存储在单一 registry 中,而不是每个 addon 一个 registry。将 GTCEuAPI.materialManager 的引用替换为 GTRegistries.MATERIALS。
  • ChargerMachine 已合并进 BatteryBufferMachine。
  • 用以下参数调用电池缓冲器构造函数,可获得与 charger machine 相同的行为:(info, tier, inventorySize, BatteryBufferMachine.AMPS_PER_BATTERY_CHARGER, 0)
  • Jade provider 代码已重构。用于特定机器类型的 jade providers 请使用 MachineInfoProvider 类,用于特定机器 trait 的 providers 请使用 MachineTraitProvider。
  • GTUtil.getMoltenFluid(Material) 已移动到 Material.getHotFluid()。
  • ICopyable::copyConfig 现在会直接修改传入的 CompoundTag,而不是返回一个新的。