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
4 changes: 2 additions & 2 deletions src/main/java/com/modularmc/synceddata/SyncedData.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
public class SyncedData {

public static final String MOD_ID = "synced";
public static final String MOD_NAME = "SyncedData";
public static final String MOD_NAME = "SyncedData Lib";
public static final Logger LOGGER = LogManager.getLogger(MOD_NAME);
public static final Codec<Identifier> GTCEU_ID = Codec.STRING.comapFlatMap(
public static final Codec<Identifier> SyncedData_ID = Codec.STRING.comapFlatMap(
str -> Identifier.read(appendIdString(str)),
s -> s.getNamespace().equals(MOD_ID) ? s.getPath() : s.toString());
public static final Path SYNCED_FOLDER = getGameDir().resolve("synced");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.modularmc.synceddata.api.blockentity;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

public record BlockEntityCreationInfo(BlockEntityType<?> type, BlockPos pos, BlockState state) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.modularmc.synceddata.api.sync_system;

public interface ISyncManaged {

SyncDataHolder getSyncDataHolder();

/**
* Function called when a synced field requests a rerender
*/
void scheduleRenderUpdate();

/**
* Function called to notify the server that this object has been updated and must be synced to clients
*/
void markAsChanged();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.modularmc.synceddata.api.sync_system;

import com.modularmc.synceddata.api.blockentity.BlockEntityCreationInfo;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

import lombok.Getter;
import lombok.Setter;

import java.util.Objects;

public abstract class ManagedSyncBlockEntity extends BlockEntity implements ISyncManaged {

@Getter
protected final SyncDataHolder syncDataHolder = new SyncDataHolder(this);
@Getter
@Setter
private boolean isDirty;

public ManagedSyncBlockEntity(BlockEntityCreationInfo info) {
super(info.type(), info.pos(), info.state());
}

public ManagedSyncBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState blockState) {
super(type, pos, blockState);
}

@Override
public final void markAsChanged() {
isDirty = true;
}

public final void updateTick() {
setChanged();
if (isDirty) {
Objects.requireNonNull(getLevel()).sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(),
Block.UPDATE_CLIENTS);
isDirty = false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.modularmc.synceddata.api.sync_system;

import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import it.unimi.dsi.fastutil.objects.ObjectSet;

public class SyncDataHolder {

private final ISyncManaged holder;

private final ObjectSet<String> dirtySyncFields = new ObjectOpenHashSet<>();
private boolean resyncAll = false;

public SyncDataHolder(ISyncManaged o) {
holder = o;
}
}
5 changes: 0 additions & 5 deletions src/main/resources/assets/synceddata/lang/en_us.json

This file was deleted.

Loading