Skip to content

Commit 67fefc9

Browse files
authored
1.20.1 v8.0.0 (#4628)
Admin Merge-Commit (Unsquashed)
2 parents 32dc631 + 5318e92 commit 67fefc9

File tree

496 files changed

+7946
-11525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

496 files changed

+7946
-11525
lines changed

dependencies.gradle

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ dependencies {
2222
modCompileOnly(forge.bundles.rei)
2323
modCompileOnly(forge.emi)
2424

25-
// WAILA-likes
26-
modCompileOnly(forge.theoneprobe)
25+
// Jade (WAILA)
2726
modCompileOnly(forge.jade)
2827

2928
// Curios
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
title: "Annotations"
3+
---
4+
5+
# Annotations
6+
The following annotations define the sync/save behaviour for an `ISyncManaged` object.
7+
8+
### `@SaveField`
9+
10+
The `@SaveField` annotation defines a field that should be saved to the server. `nbtKey` is optional, the key will default to the field name.
11+
```java
12+
@SaveField(nbtKey="nbtKeyToSaveTo")
13+
public int mySaveInt = 10;
14+
```
15+
16+
### `@SyncToClient`
17+
18+
The `@SyncToClient` annotation defines a field with a value that should be synced to clients.
19+
20+
!!! warning
21+
Client sync fields **do not** automatically detect changes. When changing a client sync field, call `ISyncManaged.getSyncDataHolder().markClientSyncFieldDirty(FIELD_NAME)`
22+
```java
23+
@SaveField(nbtKey="nbtKeyToSaveTo")
24+
@SyncToClient
25+
public int mySaveAndSyncInt = 10;
26+
27+
@SyncToClient
28+
@RerenderOnChanged
29+
public long mySyncRerenderLong = 10000L;
30+
31+
public void serverTick() {
32+
int newIntValue = getNewIntValue();
33+
long newLongValue = getNewLongValue();
34+
if (mySaveAndSyncInt != newIntValue) {
35+
mySaveAndSyncInt = newIntValue;
36+
getSyncDataHolder().markClientSyncFieldDirty("mySaveAndSyncInt");
37+
}
38+
if (mySyncRerenderLong != newLongValue) {
39+
mySyncRerenderLong = newLongValue;
40+
getSyncDataHolder().markClientSyncFieldDirty("mySyncRerenderLong");
41+
}
42+
}
43+
```
44+
45+
### `@ClientFieldChangeListener` and `@RerenderOnChanged`
46+
47+
The `@ClientFieldChangeListener` annotation defines a method to be called on the client when a client sync field has changed value;
48+
49+
Annotating a `@SyncToClient` field with `@RerenderOnChanged` will cause clients to rerender the block entity when this field changes.
50+
51+
```java
52+
@SyncToClient
53+
@SaveField
54+
@RerenderOnChanged
55+
public boolean isWorkingEnabled = true;
56+
57+
@ClientFieldChangeListener(fieldName="isWorkingEnabled")
58+
public void isWorkingChanged() {
59+
setRenderState(getRenderState().setValue(GTMachineModelProperties.IS_WORKING_ENABLED, isWorkingEnabled));
60+
}
61+
```
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: "Migrating from LDLib SyncData"
3+
---
4+
# Migrating from LDLib SyncData
5+
6+
### Simple example
7+
8+
This simple example covers the majority of use cases when adding sync/save fields to a standard machine, machine trait or cover.
9+
10+
#### With LDLib:
11+
```java
12+
class CustomMachine extends SimpleTieredMachine {
13+
protected static final ManagedFieldHolder MANAGED_FIELD_HOLDER = new ManagedFieldHolder(CustomMachine.class,
14+
SimpleTieredMachine.MANAGED_FIELD_HOLDER);
15+
16+
@Override
17+
public ManagedFieldHolder getFieldHolder() {
18+
return MANAGED_FIELD_HOLDER;
19+
}
20+
21+
@Getter
22+
@Persisted
23+
@DescSynced
24+
@RequireRerender
25+
protected int customIntValue;
26+
27+
@Persisted(key = "customNBTKey")
28+
protected String customStringValue;
29+
30+
public void setCustomIntValue(int newValue) {
31+
this.customIntValue = newValue;
32+
}
33+
}
34+
```
35+
36+
#### New System:
37+
```java
38+
class CustomMachine extends SimpleTieredMachine {
39+
@Getter
40+
@SaveField
41+
@SyncToClient
42+
protected int customIntValue;
43+
44+
@SaveField(nbtKey = "customNBTKey")
45+
protected String customStringValue;
46+
47+
public void setCustomIntValue(int newValue) {
48+
this.customIntValue = newValue;
49+
////// IMPORTANT: markClientSyncFieldDirty must be called to update client synced fields.
50+
getSyncDataHolder().markClientSyncFieldDirty("customIntValue");
51+
}
52+
}
53+
54+
```
55+
56+
### General migration guidelines
57+
58+
- Remove all `ManagedFieldHolder` fields.
59+
- Replace `FieldManagedStorage` fields with `SyncDataHolder` fields.
60+
- Replace `IEnhancedManaged` objects with `ISyncManaged`.
61+
- Replace `IAsyncAutoSyncBlockEntity`, `IAutoPersistBlockEntity`, `IAutoSyncBlockEntity` and `IManagedBlockEntity` by extending `ManagedSyncBlockEntity`.
62+
63+
### Annotations
64+
65+
!!! warning
66+
Client sync fields **do not** automatically detect changes. When changing a client sync field, call `ISyncManaged.syncDataHolder.markClientSyncFieldDirty(FIELD_NAME)`
67+
68+
- `@DescSynced` -> `@SyncToClient`
69+
- `@RequireRerender` -> `@RerenderOnChanged`
70+
- `@Persisted` -> `@SaveField`
71+
- `@UpdateListener` -> `@ClientFieldChangeListener` on listener method.
72+
- `@DropSaved` - Removed, make machines implement `IDropSaveMachine` instead
73+
- `@ReadOnlyManaged` and `@LazyManaged` See usage docs for instructions on complex sync objects
74+
75+
### Other changes
76+
77+
- `saveCustomPersistedData` & `loadCustomPersistedData` methods, and serialization of custom data types - See `ValueTransformer<T>` and `ValueTransformers` classes.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
title: "Usage"
3+
---
4+
5+
## Usage
6+
7+
### Registering classes with the sync system
8+
9+
At the core of the system is the interface `ISyncManaged`, which represents a class that to be synchronised with the client or saved.
10+
All block entities which should be synchronised or saved must extend the abstract class `ManagedSyncBlockEntity`.
11+
12+
!!! warning
13+
Block entities that inherit `ManagedSyncBlockEntity` must call `ManagedSyncBlockEntity::updateTick`***every tick*** within their ticker, or they will not be saved.
14+
15+
```java
16+
class MySyncObject implements ISyncManaged {
17+
// Any class that directly implements ISyncManaged must have the following:
18+
@Getter
19+
protected final SyncDataHolder syncDataHolder = new SyncDataHolder(this);
20+
21+
22+
/**
23+
* Function called when the SyncDataHolder requests a rerender
24+
*/
25+
void scheduleRenderUpdate();
26+
27+
/**
28+
* Function called to notify the server that this object has been updated and must be synced to clients
29+
*/
30+
void markAsChanged();
31+
}
32+
```
33+
34+
### Registering fields to be managed by the system
35+
See [Annotations](Annotations.md)
36+
37+
### Type compatibility
38+
The following field types are supported by default:
39+
- Any class implementing `ISyncManaged`
40+
- Any class implementing `INBTSerializable<Tag>`
41+
- All primitive types
42+
- If `T`, `K` are supported types:
43+
- `T[]`
44+
- `Set<T>`
45+
- `List<T>`,
46+
- `Map<T, K>`
47+
- `String`
48+
- `ItemStack`
49+
- `FluidStack`
50+
- `UUID`
51+
- `BlockPos`
52+
- `CompoundTag`
53+
- `GTRecipe`
54+
- `GTRecipeType`
55+
- `MachineRenderState`
56+
- `Material`
57+
- `Component`
58+
59+
### Adding support for additional types
60+
61+
The `ValueTransformer<T>` abstract class defines how a value of type `T` should be serialized.
62+
63+
To add support for an additional type, call `ValueTransformers.registerTransformer(Class<T> cls, ValueTransformer<T> transformer)` or `ValueTransformers.registerTransformerSupplier(Class<T> cls, Supplier<ValueTransformer<T>> func)`
64+
65+
Additionally, fields can be explicitly directed to use a specific value transformer:
66+
```java
67+
/**
68+
* Example from HullMachine.java. This example shows serialization of an AE2 class which may or may not be loaded at runtime.
69+
*/
70+
71+
@SaveField(nbtKey = "grid_node")
72+
private final Object gridNodeHost;
73+
74+
private static class GridNodeHostTransformer implements ValueTransformer<Object> {
75+
76+
@Override
77+
public Tag serializeNBT(Object value, TransformerContext<Object> context) {
78+
if (GTCEu.Mods.isAE2Loaded() &&
79+
(context.currentValue()) instanceof IGridConnectedBlockEntity connectedBlockEntity) {
80+
var compound = new CompoundTag();
81+
connectedBlockEntity.getMainNode().saveToNBT(compound);
82+
return compound;
83+
}
84+
return new CompoundTag();
85+
}
86+
87+
@Override
88+
public @Nullable Object deserializeNBT(Tag tag, TransformerContext<Object> context) {
89+
if (GTCEu.Mods.isAE2Loaded() &&
90+
context.currentValue() instanceof IGridConnectedBlockEntity connectedBlockEntity &&
91+
tag instanceof CompoundTag c) {
92+
connectedBlockEntity.getMainNode().loadFromNBT(c);
93+
}
94+
return null;
95+
}
96+
}
97+
98+
static {
99+
ClassSyncData.getClassData(HullMachine.class).setCustomTransformerForField("gridNodeHost",
100+
new GridNodeHostTransformer());
101+
}
102+
103+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: "Data Sync/Save system "
3+
---
4+
5+
# Data Sync/Save System
6+
7+
For serialising data to saves and synchronising with clients, a custom data sync system based on Java Annotations is used.
8+
9+
- See [Usage](Usage.md) for a guide on using the system
10+
- See [Annotations](Annotations.md) for a list of annotations provided by the system
11+
- See [Migrating From LDLib SyncData](Migrating-From-LDLib-SyncData.md) for instructions on how to migrate from the LDLib SyncData system, which was used in versions 7.x and lower.
12+

docs/content/Development/SyncData/.pages

Lines changed: 0 additions & 5 deletions
This file was deleted.

docs/content/Development/SyncData/Annotations/.pages

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/content/Development/SyncData/Annotations/DescSynced.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/content/Development/SyncData/Annotations/Persisted.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

docs/content/Development/SyncData/Annotations/RequireRerender.md

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)