Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,56 @@ title: "Migrating from LDLib SyncData"
---
# Migrating from LDLib SyncData

### Simple example

This simple example covers the majority of use cases when adding sync/save fields to a standard machine, machine trait or cover.

#### With LDLib:
```java
class CustomMachine extends SimpleTieredMachine {
protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(CustomMachine.class,
SimpleTieredMachine.MANAGED_FIELD_HOLDER);

@Override
public ManagedFieldHolder getFieldHolder() {
return MANAGED_FIELD_HOLDER;
}

@Getter
@Persisted
@DescSynced
@RequireRerender
protected int customIntValue;

@Persisted(key = "customNBTKey")
protected String customStringValue;

public void setCustomIntValue(int newValue) {
this.customIntValue = newValue;
}
}
```

#### New System:
```java
class CustomMachine extends SimpleTieredMachine {
@Getter
@SaveField
@SyncToClient
protected int customIntValue;

@SaveField(nbtKey = "customNBTKey")
protected String customStringValue;

public void setCustomIntValue(int newValue) {
this.customIntValue = newValue;
////// IMPORTANT: markClientSyncFieldDirty must be called to update client synced fields.
getSyncDataHolder().markClientSyncFieldDirty("customIntValue");
}
}

```

### General migration guidelines

- Remove all `ManagedFieldHolder` fields.
Expand Down
69 changes: 69 additions & 0 deletions docs/content/Modpacks/Changes/v8.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ title: "Version 8.0.0"

# Updating from `7.4.0` to `8.0.0`

## New Data Save/Sync System

A new system for saving and syncing object fields has been added. See [this page](../../Development/Data-Sync-System/Migrating-From-LDLib-SyncData.md) for migration instructions.

## Machine Refactor

Many aspects of the machine classes have been refactored and changed in order to streamline the machine system and remove legacy and unnecessary abstraction.
Expand Down Expand Up @@ -39,6 +43,7 @@ public MetaMachine(IMachineBlockEntity holder);
public MetaMachine(BlockEntityCreationInfo info);
```
A number of methods have been renamed across a number of different interfaces and classes to ensure consistency with default BlockEntity methods:

- `BlockPos getPipePos()` -> `BlockPos getBlockPos()`
- `Level getPipeLevel()` -> `Level getLevel()`
- `BlockPos getPos()` -> `BlockPos getBlockPos()`
Expand Down Expand Up @@ -69,3 +74,67 @@ The constructors for a large number of machines have changed in order to simply
#### `WorkableMultiblockMachine`, `WorkableElectricMultiblockMachine` and `SteamWorkableMachine`
- Removed `createRecipeLogic` method
- Constructor now has an optional `Supplier<RecipeLogic>` argument, defaults to the standard `RecipeLogic` class

## Machine Trait Refactor

A new system for attaching traits and custom behaviour to machines has been added, and many machine interfaces and traits now use this new system.

### New System Example

Example of the new `AutoOutputTrait`

```java
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 = new NotifiableFluidTank(this, 1, capacity, IO.BOTH);

// Registers an auto output trait that provides fluid output behaviour for the given fluid tank.
this.autoOutput = AutoOutputTrait.ofFluids(this, 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);

}
}
```

### Removed interfaces

A large number of machine feature interfaces have been removed, and have had their functionality merged into the standard MetaMachine class, or now use the new machine trait system:

- `ITurbineMachine` Use the `LargeTurbineMachine` class directly.
- `IRotorHolderMachine` Use the `RotorHolderMachine` class directly.
- `IMultiController` Use the `MultiblockControllerMachine` class directly.
- `IMufflerMachine` Use the `MufflerMachine` class directly.
- `IMachineLife` Override the `MetaMachine::onMachinePlaced` and `MetaMachine::onMachineDestroyed`.
- `IMachineModifyDrops` Override `MetaMachine::modifyDrops`.
- `IInteractedMachine` Override `MetaMachine::onUse` and `MetaMachine::onLeftClick`.
- `ICleanroomReceiver` & `ICleanroomProvider` - Use `CleanroomReceiverTrait` and `CleanroomProviderTrait`.
- `IAutoOutputBoth`, `IAutoOutputFluid`, `IAutoOutputItem` - Use `AutoOutputTrait`.
- `IExplosionMachine` - Use `EnvironmentalExplosionTrait`, `GTUtil::doExplosion`, and `GTUtil::setOnFire`
- `IEnvironmentalHazardCleaner` Use `EnvironmentalHazardCleanerTrait`
- `ILocalizedHazardEmitter` - Use `LocalizedHazardEmitterTrait`
- `IExhaustVentMachine` - Use `ExhaustVentMachineTrait`
- `IHPCAComponentHatch` - Use `HPCAComponentTrait`
- `IHPCAComputationProvider` - Use `HPCAComputationProviderTrait`
- `IHPCACoolantProvider` - Use `HPCACoolantProviderTrait`