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 @@ -44,7 +44,7 @@ public ServerPastelNetwork(ServerLevel world, UUID uuid, int color) {
}

public ServerPastelNetwork(ServerLevel world, PastelNodeBlockEntity initialNode) {
this(world, initialNode.getNodeId(), initialNode.getPastelNetworkColor(), new TickLooper(10));
this(world, UUID.randomUUID(), initialNode.getPastelNetworkColor(), new TickLooper(10));
addNode(initialNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public CompoundTag save(CompoundTag nbt, HolderLookup.Provider registryLookup) {
var wrapper = new CompoundTag();
wrapper.put("network", opt.get());
wrapper.put("scheduler", transgender(network.getTransmissions()));
wrapper.put("graph", network.graphToNbt());
// Trans missions?... do... do they really?
networkList.add(wrapper);
}
Expand All @@ -75,10 +76,12 @@ public static ServerPastelNetworkManager fromNbt(CompoundTag nbt) {
var comp = (CompoundTag) element;
var netNbt = comp.get("network");
var schedulerNbt = comp.getCompound("scheduler");
var graphNbt = comp.getCompound("graph");

Optional<ServerPastelNetwork> network = CodecHelper.fromNbt(ServerPastelNetwork.CODEC, netNbt);
if (network.isPresent()) {
network.get().getTransmissions().putAll(transDecode(schedulerNbt, network.get()));
network.get().setGraph(ServerPastelNetwork.graphFromNbt(graphNbt));
manager.networks.add(network.get());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ public ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level

world.playLocalSound(pos, SpectrumSoundEvents.MEDIUM_CRYSTAL_RING, SoundSource.BLOCKS, 0.25F, 0.9F + world.getRandom().nextFloat() * 0.2F, true);
return ItemInteractionResult.sidedSuccess(world.isClientSide());
} else if (tryColorUsingStackInHand(stack, world, pos, player, hand)) {
return ItemInteractionResult.sidedSuccess(world.isClientSide());
} else if (this.pastelNodeType.usesFilters()) {
if (!world.isClientSide) {
player.openMenu(blockEntity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public class PastelNodeBlockEntity extends BlockEntity implements FilterConfigur

protected BlockApiCache<Storage<ItemVariant>, Direction> connectedStorageCache = null;
protected Direction cachedDirection = null;

protected Boolean isInitialized = false;

private final List<ItemVariant> filterItems;
float rotationTarget, crystalRotation, lastRotationTarget, heightTarget, crystalHeight, lastHeightTarget, alphaTarget, ringAlpha, lastAlphaTarget;
Expand Down Expand Up @@ -101,6 +103,11 @@ public PastelNodeBlockEntity(BlockPos blockPos, BlockState blockState) {
}

public static void tick(@NotNull Level world, BlockPos pos, BlockState state, PastelNodeBlockEntity node) {
if (!node.isInitialized && !world.isClientSide()) { // kinda onLoad()?
node.getServerNetwork().ifPresent(network -> network.initializeNode(node));
node.isInitialized = true;
}

if (node.lamp && state.getValue(BlockStateProperties.LIT) != node.canTransfer()) {
world.setBlockAndUpdate(pos, state.setValue(BlockStateProperties.LIT, node.cachedUnpowered));
}
Expand Down Expand Up @@ -333,6 +340,7 @@ protected void loadAdditional(CompoundTag nbt, HolderLookup.Provider registryLoo
this.creationStamp = nbt.contains("creationStamp") ? nbt.getLong("creationStamp") : 0;
this.lastTransferTick = nbt.contains("LastTransferTick", Tag.TAG_LONG) ? nbt.getLong("LastTransferTick") : 0;
this.itemCountUnderway = nbt.contains("ItemCountUnderway", Tag.TAG_LONG) ? nbt.getLong("ItemCountUnderway") : 0;
this.color = nbt.contains("ColorId", Tag.TAG_INT) ? Optional.of(DyeColor.byId(nbt.getInt("ColorId"))) : Optional.empty();
this.outerRing = nbt.contains("OuterRing") ? Optional.ofNullable(SpectrumRegistries.PASTEL_UPGRADE.get(ResourceLocation.tryParse(nbt.getString("OuterRing")))) : Optional.empty();
this.innerRing = nbt.contains("InnerRing") ? Optional.ofNullable(SpectrumRegistries.PASTEL_UPGRADE.get(ResourceLocation.tryParse(nbt.getString("InnerRing")))) : Optional.empty();
this.redstoneRing = nbt.contains("RedstoneRing") ? Optional.ofNullable(SpectrumRegistries.PASTEL_UPGRADE.get(ResourceLocation.tryParse(nbt.getString("RedstoneRing")))) : Optional.empty();
Expand All @@ -351,6 +359,9 @@ protected void saveAdditional(CompoundTag nbt, HolderLookup.Provider registryLoo
if (this.networkUUID.isPresent()) {
nbt.putUUID("NetworkUUID", this.networkUUID.get());
}
if (this.color.isPresent()) {
nbt.putInt("ColorId", this.color.get().getId());
}
nbt.putUUID("NodeID", this.nodeId);
nbt.putBoolean("Triggered", this.triggered);
nbt.putBoolean("Waiting", this.waiting);
Expand Down Expand Up @@ -546,6 +557,7 @@ public boolean setColor(Optional<DyeColor> color, @Nullable Entity user) {
public void connectToNearbyNodes(@Nullable Entity user) {
// remove from existing network, if it had one and join new networks
Pastel.getServerInstance().removeNode(this, NodeRemovalReason.DISCONNECT);
this.setNetworkUUID(null);

// scan for all connectable nearby nodes
Map<Optional<ServerPastelNetwork>, List<PastelNodeBlockEntity>> connectableNodes = new Object2ObjectArrayMap<>();
Expand Down Expand Up @@ -584,7 +596,12 @@ public void connectToNearbyNodes(@Nullable Entity user) {

network = Pastel.getServerInstance().createNetwork((ServerLevel) level, this);
for (PastelNodeBlockEntity entry : connectableNodes.get(Optional.empty())) {
network.addEdge(this, entry);
try {
network.addEdge(this, entry); // Sometimes throws 'IllegalStateException("Attempted to add an edge to a foreign network")' (why? idk. better safe than sorry)
} catch (Exception e) {
SpectrumCommon.logWarning("PastelNodeBlockEntity can't connectToNearbyNodes: " + e.getMessage());
e.printStackTrace();
}
}
} else if (foundNetworkCount == 1) {
// there is exactly one other network
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private boolean tryColorBlock(UseOnContext context) {
context.getLevel().playSound(null, context.getClickedPos(), SpectrumSoundEvents.USE_FAIL, SoundSource.BLOCKS, 1.0F, 1.0F);
}
}
return false;
return true;
}

return cursedColor(context);
Expand Down