Skip to content

Commit

Permalink
Merge resource reload bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
FoundationGames committed Jun 13, 2024
2 parents 0a39cf7 + 8b95cdf commit be5dd1f
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ loader_version=0.15.11

fabric_version=0.99.4+1.20.6

mod_version = 0.10+1.20.6
mod_version = 0.10.1+1.20.6
maven_group = foundationgames
archives_base_name = enhancedblockentities

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public void render(BlockEntityRenderer<BlockEntity> renderer, BlockEntity blockE
};

public BlockEntityRendererOverride() {
EBEEvents.RELOAD_MODELS.register((loader, manager, profiler) -> this.onModelsReload());
EBEEvents.RESOURCE_RELOAD.register(this::onModelsReload);
}

public abstract void render(BlockEntityRenderer<BlockEntity> renderer, BlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@
import net.minecraft.util.profiler.Profiler;

public enum EBEEvents {;
public static final Event<Reload> RELOAD_MODELS = EventFactory.createArrayBacked(Reload.class, (callbacks) -> (loader, manager, profiler) -> {
for (Reload event : callbacks) {
event.onReload(loader, manager, profiler);
public static final Event<Runnable> RESOURCE_RELOAD = EventFactory.createArrayBacked(Runnable.class, (callbacks) -> () -> {
for (var event : callbacks) {
event.run();
}
});

public interface Reload {
void onReload(ModelLoader loader, ResourceManager manager, Profiler profiler);
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
package foundationgames.enhancedblockentities.mixin;

import foundationgames.enhancedblockentities.event.EBEEvents;
import foundationgames.enhancedblockentities.util.duck.BakedModelManagerAccess;
import net.minecraft.client.render.model.BakedModel;
import net.minecraft.client.render.model.BakedModelManager;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceReloader;
import net.minecraft.util.Identifier;
import net.minecraft.util.profiler.Profiler;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;

@Mixin(BakedModelManager.class)
public class BakedModelManagerMixin implements BakedModelManagerAccess {
Expand All @@ -26,15 +17,4 @@ public class BakedModelManagerMixin implements BakedModelManagerAccess {
public BakedModel enhanced_bes$getModel(Identifier id) {
return this.models.get(id);
}

// Should invoke the EBE event after the model manager's block model cache is filled during a resource reload
@Inject(method = "reload", at = @At("TAIL"))
public void enhanced_bes$invokeReloadEvent(ResourceReloader.Synchronizer synchronizer, ResourceManager manager,
Profiler prepareProfiler, Profiler applyProfiler, Executor prepareExecutor,
Executor applyExecutor, CallbackInfoReturnable<CompletableFuture<Void>> cir) {
cir.getReturnValue().thenAccept(obj -> {
var result = (BakedModelManager.BakingResult)(Object)obj;
EBEEvents.RELOAD_MODELS.invoker().onReload(result.modelLoader(), manager, applyProfiler);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package foundationgames.enhancedblockentities.mixin;

import foundationgames.enhancedblockentities.event.EBEEvents;
import net.minecraft.client.MinecraftClient;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.concurrent.CompletableFuture;

@Mixin(MinecraftClient.class)
public class MinecraftClientMixin {
@Inject(method = "reloadResources()Ljava/util/concurrent/CompletableFuture;",
at = @At("RETURN"))
private void enhanced_bes$fireReloadEvent(CallbackInfoReturnable<CompletableFuture<Void>> cir) {
cir.getReturnValue().thenAccept(v -> EBEEvents.RESOURCE_RELOAD.invoker().run());
}
}
1 change: 1 addition & 0 deletions src/main/resources/enhancedblockentities.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"DecoratedPotBlockEntityMixin",
"EnderChestBlockEntityMixin",
"LifecycledResourceManagerImplMixin",
"MinecraftClientMixin",
"ShulkerBoxBlockEntityMixin",
"SignBlockEntityRenderAccessor",
"SignEditScreenMixin",
Expand Down

0 comments on commit be5dd1f

Please sign in to comment.