-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Rewrite facade rendering for improved compatibility
- Loading branch information
Showing
9 changed files
with
149 additions
and
90 deletions.
There are no files selected for viewing
121 changes: 74 additions & 47 deletions
121
enderio-conduits/src/main/java/com/enderio/conduits/client/ConduitFacadeRendering.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 12 additions & 12 deletions
24
...onduits/src/main/java/com/enderio/conduits/client/model/conduit/facades/FacadeHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
package com.enderio.conduits.client.model.conduit.facades; | ||
|
||
import com.enderio.conduits.common.conduit.block.ConduitBundleBlockEntity; | ||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.core.SectionPos; | ||
|
||
// TODO: In future, support hiding specific conduit types too. | ||
public class FacadeHelper { | ||
|
||
private static boolean FACADES_VISIBLE = true; | ||
|
||
public static void setFacadesVisible(boolean visible) { | ||
if (visible != FACADES_VISIBLE) { | ||
RenderSystem.recordRenderCall(() -> { | ||
ConduitBundleBlockEntity.CHUNK_FACADES.keySet().forEach((section) -> { | ||
Minecraft.getInstance().levelRenderer.setSectionDirty(SectionPos.x(section), SectionPos.y(section), | ||
SectionPos.z(section)); | ||
}); | ||
}); | ||
} | ||
|
||
FACADES_VISIBLE = visible; | ||
} | ||
|
||
public static boolean areFacadesVisible() { | ||
return FACADES_VISIBLE; | ||
} | ||
|
||
public static void rebuildChunkMeshes() { | ||
var minecraft = Minecraft.getInstance(); | ||
|
||
if (minecraft.levelRenderer.viewArea == null) { | ||
return; | ||
} | ||
|
||
for (var section : minecraft.levelRenderer.viewArea.sections) { | ||
section.setDirty(false); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
enderio-conduits/src/main/java/com/enderio/conduits/mixin/BlockRenderDispatcherMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.enderio.conduits.mixin; | ||
|
||
import com.enderio.conduits.common.conduit.block.ConduitBundleBlockEntity; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import net.minecraft.client.renderer.block.BlockModelShaper; | ||
import net.minecraft.client.renderer.block.BlockRenderDispatcher; | ||
import net.minecraft.client.resources.model.BakedModel; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.world.level.BlockAndTintGetter; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
|
||
/** | ||
* This fixes the block breaking overlay when a facade is attached to use the model of the facade. Without this, it will use the model of the conduit, and be invisible in most cases. | ||
*/ | ||
@Mixin(BlockRenderDispatcher.class) | ||
public class BlockRenderDispatcherMixin { | ||
@WrapOperation(method = "renderBreakingTexture(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/BlockAndTintGetter;Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;Lnet/neoforged/neoforge/client/model/data/ModelData;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/block/BlockModelShaper;getBlockModel(Lnet/minecraft/world/level/block/state/BlockState;)Lnet/minecraft/client/resources/model/BakedModel;")) | ||
public BakedModel enderio$checkFacades(BlockModelShaper instance, BlockState state, Operation<BakedModel> original, | ||
BlockState localState, BlockPos pos, BlockAndTintGetter level) { | ||
BlockState facadeState = ConduitBundleBlockEntity.FACADES.getOrDefault(pos.asLong(), null); | ||
|
||
return original.call(instance, facadeState == null ? state : facadeState); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
enderio-conduits/src/main/resources/enderioconduits.mixins.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"required" : true, | ||
"package" : "com.enderio.conduits.mixin", | ||
"compatibilityLevel" : "JAVA_17", | ||
"client" : [ | ||
"BlockRenderDispatcherMixin" | ||
], | ||
"minVersion" : "0.8" | ||
} |
Oops, something went wrong.