Skip to content

Commit

Permalink
Rework caching and update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiDragon committed Sep 30, 2023
1 parent ad90849 commit 67c4167
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 58 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ repositories {
maven { url "https://maven.blamejared.com" }
maven { url "https://maven.isxander.dev/releases" }
maven { url "https://maven.terraformersmc.com" }
maven { url "https://jitpack.io" }
maven { url 'https://maven.quiltmc.org/repository/release/' }
maven { url 'https://maven.cafeteria.dev/releases/' }
maven { url "https://jitpack.io" }
}

// Has to run before dependencies so that we get access to proper dependency configurations
Expand Down Expand Up @@ -103,7 +104,6 @@ java {
withSourcesJar()
}


publishing {
publications.create("mavenJava", MavenPublication) {
from components.java
Expand Down
7 changes: 7 additions & 0 deletions changelog/2.0.6+1.20.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
* Rework network caching
* Fix issues with items being deleted
* Probably improve performance in cases with rapidly changing networks
* Properly handle drawers in unloaded chunks
* Update dependencies
* Now compatible with latest YACL
* Probably fixed some bugs somewhere
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ minecraft_version=1.20.1
yarn_mappings=1.20.1+build.10
loader_version=0.14.21

mod_version=2.0.5
mod_version=2.0.6
maven_group=io.github.mattidragon
archives_base_name=ExtendedDrawers

fabric_version=0.86.1+1.20.1
graphlib_version=1.1.1+1.20
fabric_version=0.89.0+1.20.1
graphlib_version=1.4.0+1.20
patchouli_version=1.20.1-81-FABRIC
mixinextras_version=0.2.0-beta.9
yacl_version=3.1.0+1.20
mixinextras_version=0.2.0-rc.5
yacl_version=3.2.1+1.20
modmenu_version=7.2.1
configtoolkit_version=1.0.0
noindium_version=1.1.0+1.20
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.*;
import dev.isxander.yacl3.gui.ImageRenderer;
import dev.isxander.yacl3.gui.image.ImageRenderer;
import dev.isxander.yacl3.gui.image.ImageRendererManager;
import io.github.mattidragon.extendeddrawers.ExtendedDrawers;
import io.github.mattidragon.extendeddrawers.client.renderer.AbstractDrawerBlockEntityRenderer;
import io.github.mattidragon.extendeddrawers.config.ConfigData;
Expand Down Expand Up @@ -31,13 +32,12 @@
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;

import static io.github.mattidragon.extendeddrawers.ExtendedDrawers.id;
import static io.github.mattidragon.extendeddrawers.config.ConfigData.DEFAULT;

public class ConfigScreenFactory {
public static final Function<Float, Text> FLOAT_FORMATTER;
public static final ValueFormatter<Float> FLOAT_FORMATTER;

static {
var format = NumberFormat.getNumberInstance(Locale.ROOT);
Expand Down Expand Up @@ -134,13 +134,13 @@ private static ConfigCategory createMiscCategory(MutableMiscCategory instance) {
.option(Option.<CreativeBreakingBehaviour>createBuilder()
.name(Text.translatable("config.extended_drawers.misc.frontBreakingBehaviour"))
.binding(DEFAULT.misc().frontBreakingBehaviour(), instance::frontBreakingBehaviour, instance::frontBreakingBehaviour)
.controller(option -> EnumControllerBuilder.create(option).enumClass(CreativeBreakingBehaviour.class).valueFormatter(CreativeBreakingBehaviour::getDisplayName))
.controller(option -> EnumControllerBuilder.create(option).enumClass(CreativeBreakingBehaviour.class).formatValue(CreativeBreakingBehaviour::getDisplayName))
.description(value -> creativeBreakingBehaviourDescription(Text.translatable("config.extended_drawers.misc.frontBreakingBehaviour.description"), value))
.build())
.option(Option.<CreativeBreakingBehaviour>createBuilder()
.name(Text.translatable("config.extended_drawers.misc.sideBreakingBehaviour"))
.binding(DEFAULT.misc().sideBreakingBehaviour(), instance::sideBreakingBehaviour, instance::sideBreakingBehaviour)
.controller(option -> EnumControllerBuilder.create(option).enumClass(CreativeBreakingBehaviour.class).valueFormatter(CreativeBreakingBehaviour::getDisplayName))
.controller(option -> EnumControllerBuilder.create(option).enumClass(CreativeBreakingBehaviour.class).formatValue(CreativeBreakingBehaviour::getDisplayName))
.description(value -> creativeBreakingBehaviourDescription(Text.translatable("config.extended_drawers.misc.sideBreakingBehaviour.description"), value))
.build())
.option(Option.<Boolean>createBuilder()
Expand Down Expand Up @@ -204,25 +204,25 @@ private static OptionGroup createIconGroup(MutableClientCategory.MutableIconGrou
.name(Text.translatable("config.extended_drawers.client.lockedIcon"))
.binding(DEFAULT.client().icons().lockedIcon(), icons::lockedIcon, icons::lockedIcon)
.customController(IdentifierController::new)
.description(id -> OptionDescription.createBuilder().customImage(ImageRenderer.getOrMakeSync(id, () -> Optional.of(new IconRenderer(id)))).text(Text.translatable("config.extended_drawers.client.lockedIcon.description")).build())
.description(id -> OptionDescription.createBuilder().customImage(ImageRendererManager.registerImage(id, () -> () -> new IconRenderer(id)).thenApply(Optional::of)).text(Text.translatable("config.extended_drawers.client.lockedIcon.description")).build())
.build())
.option(Option.<Identifier>createBuilder()
.name(Text.translatable("config.extended_drawers.client.voidingIcon"))
.binding(DEFAULT.client().icons().voidingIcon(), icons::voidingIcon, icons::voidingIcon)
.customController(IdentifierController::new)
.description(id -> OptionDescription.createBuilder().customImage(ImageRenderer.getOrMakeSync(id, () -> Optional.of(new IconRenderer(id)))).text(Text.translatable("config.extended_drawers.client.voidingIcon.description")).build())
.description(id -> OptionDescription.createBuilder().customImage(ImageRendererManager.registerImage(id, () -> () -> new IconRenderer(id)).thenApply(Optional::of)).text(Text.translatable("config.extended_drawers.client.voidingIcon.description")).build())
.build())
.option(Option.<Identifier>createBuilder()
.name(Text.translatable("config.extended_drawers.client.hiddenIcon"))
.binding(DEFAULT.client().icons().hiddenIcon(), icons::hiddenIcon, icons::hiddenIcon)
.customController(IdentifierController::new)
.description(id -> OptionDescription.createBuilder().customImage(ImageRenderer.getOrMakeSync(id, () -> Optional.of(new IconRenderer(id)))).text(Text.translatable("config.extended_drawers.client.hiddenIcon.description")).build())
.description(id -> OptionDescription.createBuilder().customImage(ImageRendererManager.registerImage(id, () -> () -> new IconRenderer(id)).thenApply(Optional::of)).text(Text.translatable("config.extended_drawers.client.hiddenIcon.description")).build())
.build())
.option(Option.<Identifier>createBuilder()
.name(Text.translatable("config.extended_drawers.client.dupingIcon"))
.binding(DEFAULT.client().icons().dupingIcon(), icons::dupingIcon, icons::dupingIcon)
.customController(IdentifierController::new)
.description(id -> OptionDescription.createBuilder().customImage(ImageRenderer.getOrMakeSync(id, () -> Optional.of(new IconRenderer(id)))).text(Text.translatable("config.extended_drawers.client.dupingIcon.description")).build())
.description(id -> OptionDescription.createBuilder().customImage(ImageRendererManager.registerImage(id, () -> () -> new IconRenderer(id)).thenApply(Optional::of)).text(Text.translatable("config.extended_drawers.client.dupingIcon.description")).build())
.build())
.build();
}
Expand All @@ -233,31 +233,31 @@ private static OptionGroup createLayoutGroup(MutableClientCategory.MutableLayout
var smallItemScale = Option.<Float>createBuilder()
.name(Text.translatable("config.extended_drawers.client.smallItemScale"))
.binding(DEFAULT.client().layout().smallItemScale(), instance::smallItemScale, instance::smallItemScale)
.controller(option -> FloatSliderControllerBuilder.create(option).range(0f, 2f).step(0.05f).valueFormatter(FLOAT_FORMATTER))
.controller(option -> FloatSliderControllerBuilder.create(option).range(0f, 2f).step(0.05f).formatValue(FLOAT_FORMATTER))
.description(OptionDescription.createBuilder().customImage(CompletableFuture.completedFuture(Optional.of(layoutRenderer))).text(Text.translatable("config.extended_drawers.client.smallItemScale.description")).build())
.build();
var largeItemScale = Option.<Float>createBuilder()
.name(Text.translatable("config.extended_drawers.client.largeItemScale"))
.binding(DEFAULT.client().layout().largeItemScale(), instance::largeItemScale, instance::largeItemScale)
.controller(option -> FloatSliderControllerBuilder.create(option).range(0f, 2f).step(0.05f).valueFormatter(FLOAT_FORMATTER))
.controller(option -> FloatSliderControllerBuilder.create(option).range(0f, 2f).step(0.05f).formatValue(FLOAT_FORMATTER))
.description(OptionDescription.createBuilder().customImage(CompletableFuture.completedFuture(Optional.of(layoutRenderer))).text(Text.translatable("config.extended_drawers.client.largeItemScale.description")).build())
.build();
var smallTextScale = Option.<Float>createBuilder()
.name(Text.translatable("config.extended_drawers.client.smallTextScale"))
.binding(DEFAULT.client().layout().smallTextScale(), instance::smallTextScale, instance::smallTextScale)
.controller(option -> FloatSliderControllerBuilder.create(option).range(0f, 2f).step(0.05f).valueFormatter(FLOAT_FORMATTER))
.controller(option -> FloatSliderControllerBuilder.create(option).range(0f, 2f).step(0.05f).formatValue(FLOAT_FORMATTER))
.description(OptionDescription.createBuilder().customImage(CompletableFuture.completedFuture(Optional.of(layoutRenderer))).text(Text.translatable("config.extended_drawers.client.smallTextScale.description")).build())
.build();
var largeTextScale = Option.<Float>createBuilder()
.name(Text.translatable("config.extended_drawers.client.largeTextScale"))
.binding(DEFAULT.client().layout().largeTextScale(), instance::largeTextScale, instance::largeTextScale)
.controller(option -> FloatSliderControllerBuilder.create(option).range(0f, 2f).step(0.05f).valueFormatter(FLOAT_FORMATTER))
.controller(option -> FloatSliderControllerBuilder.create(option).range(0f, 2f).step(0.05f).formatValue(FLOAT_FORMATTER))
.description(OptionDescription.createBuilder().customImage(CompletableFuture.completedFuture(Optional.of(layoutRenderer))).text(Text.translatable("config.extended_drawers.client.largeTextScale.description")).build())
.build();
var textOffset = Option.<Float>createBuilder()
.name(Text.translatable("config.extended_drawers.client.textOffset"))
.binding(DEFAULT.client().layout().textOffset(), instance::textOffset, instance::textOffset)
.controller(option -> FloatSliderControllerBuilder.create(option).range(0f, 1f).step(0.05f).valueFormatter(FLOAT_FORMATTER))
.controller(option -> FloatSliderControllerBuilder.create(option).range(0f, 1f).step(0.05f).formatValue(FLOAT_FORMATTER))
.description(OptionDescription.createBuilder().customImage(CompletableFuture.completedFuture(Optional.of(layoutRenderer))).text(Text.translatable("config.extended_drawers.client.textOffset.description")).build())
.build();

Expand Down Expand Up @@ -297,7 +297,7 @@ public void init(Option<Float> smallItemScale, Option<Float> largeItemScale, Opt
}

@Override
public int render(DrawContext context, int x, int y, int renderWidth) {
public int render(DrawContext context, int x, int y, int renderWidth, float tickDelta) {
if (!initialized) return 0;

var atlas = MinecraftClient.getInstance().getSpriteAtlas(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE);
Expand Down Expand Up @@ -373,7 +373,7 @@ public void close() {

private record IconRenderer(Identifier id) implements ImageRenderer {
@Override
public int render(DrawContext graphics, int x, int y, int renderWidth) {
public int render(DrawContext graphics, int x, int y, int renderWidth, float tickDelta) {
var blockAtlas = MinecraftClient.getInstance().getSpriteAtlas(PlayerScreenHandler.BLOCK_ATLAS_TEXTURE);
var sprite = blockAtlas.apply(id);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.mattidragon.extendeddrawers.block.entity;

import io.github.mattidragon.extendeddrawers.network.NetworkRegistry;
import io.github.mattidragon.extendeddrawers.network.UpdateHandler;
import io.github.mattidragon.extendeddrawers.storage.DrawerStorage;
import net.minecraft.block.Block;
Expand All @@ -21,8 +22,9 @@ public StorageDrawerBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockStat
}

public void onSlotChanged(boolean sortingChanged) {
markDirty();
if (world instanceof ServerWorld serverWorld) {
// Using this instead of markDirty to handle cases where drawer is in unloaded chunks (why doesn't minecraft save in unloaded chunks?)
world.getWorldChunk(pos).setNeedsSaving(true);
UpdateHandler.scheduleUpdate(serverWorld, pos, sortingChanged ? UpdateHandler.ChangeType.CONTENT : UpdateHandler.ChangeType.COUNT);
var state = getCachedState();
world.updateListeners(pos, state, state, Block.NOTIFY_LISTENERS);
Expand All @@ -35,4 +37,26 @@ public void onSlotChanged(boolean sortingChanged) {

@Override
public abstract void writeNbt(NbtCompound nbt);

@Override
public void markRemoved() {
super.markRemoved();
if (world instanceof ServerWorld serverWorld) {
NetworkRegistry.UNIVERSE.getServerGraphWorld(serverWorld)
.getAllGraphsAt(pos)
.map(graph -> graph.getGraphEntity(NetworkRegistry.STORAGE_CACHE_TYPE))
.forEach(cache -> cache.onNodeUnloaded(pos));
}
}

@Override
public void cancelRemoval() {
super.cancelRemoval();
if (world instanceof ServerWorld serverWorld) {
NetworkRegistry.UNIVERSE.getServerGraphWorld(serverWorld)
.getAllGraphsAt(pos)
.map(graph -> graph.getGraphEntity(NetworkRegistry.STORAGE_CACHE_TYPE))
.forEach(cache -> cache.onNodeReloaded(pos));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public class NetworkRegistry {
public static final GraphUniverse UNIVERSE = GraphUniverse.builder()
.saveMode(SaveMode.INCREMENTAL)
.build(id("drawers"));
public static final GraphEntityType<NetworkStorageCache> STORAGE_CACHE_TYPE = GraphEntityType.of(id("storage_cache"), NetworkStorageCache::new);
public static final GraphEntityType<NetworkStorageCache> STORAGE_CACHE_TYPE = GraphEntityType.of(id("storage_cache"),
NetworkStorageCache::new,
nbt -> new NetworkStorageCache(),
NetworkStorageCache::split);
public static final GraphEntityType<UpdateHandler> UPDATE_HANDLER_TYPE = GraphEntityType.of(id("update_handler"), UpdateHandler::new);

public static void register() {
Expand Down
Loading

0 comments on commit 67c4167

Please sign in to comment.