Skip to content

Commit

Permalink
Closes #421
Browse files Browse the repository at this point in the history
Closes #417
  • Loading branch information
Jeryn99 committed Dec 26, 2024
1 parent 3709c78 commit 1f6b44e
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 120 deletions.
51 changes: 51 additions & 0 deletions common/src/main/java/whocraft/tardis_refined/TRMixinPlugin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package whocraft.tardis_refined;

import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
import whocraft.tardis_refined.compat.ModCompatChecker;

import java.util.List;
import java.util.Set;

public class TRMixinPlugin implements IMixinConfigPlugin {

@Override
public void onLoad(String mixinPackage) {

}

@Override
public String getRefMapperConfig() {
return "";
}

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (ModCompatChecker.immersivePortals() && mixinClassName.contains("whocraft.tardis_refined.mixin.render.buffer")) {
TardisRefined.LOGGER.info("Immersive Portals Detected, we will NOT be activating our Mixin: {}", mixinClassName);
return false;
}
return false;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {

}

@Override
public List<String> getMixins() {
return List.of();
}

@Override
public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}

@Override
public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level lev
TardisClientData reactions = TardisClientData.getInstance(level.dimension());
if (globalConsoleBlock == null) return;

Boolean powered = globalConsoleBlock.getBlockState().getValue(GlobalConsoleBlock.POWERED);
Boolean powered = globalConsoleBlock.getBlockState() == null ? true : globalConsoleBlock.getBlockState().getValue(GlobalConsoleBlock.POWERED);


if (powered) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,8 @@ public void renderConsole(GlobalConsoleBlockEntity globalConsoleBlock, Level lev
root().getAllParts().forEach(ModelPart::resetPose);
TardisClientData reactions = TardisClientData.getInstance(level.dimension());

Boolean powered = globalConsoleBlock.getBlockState().getValue(GlobalConsoleBlock.POWERED);
Boolean powered = globalConsoleBlock.getBlockState() == null ? true : globalConsoleBlock.getBlockState().getValue(GlobalConsoleBlock.POWERED);

if (powered) {
if (!globalConsoleBlock.powerOn.isStarted()) {
globalConsoleBlock.powerOff.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
import whocraft.tardis_refined.common.VortexRegistry;
import whocraft.tardis_refined.common.block.door.InternalDoorBlock;
import whocraft.tardis_refined.common.blockentity.door.GlobalDoorBlockEntity;
import whocraft.tardis_refined.compat.ModCompatChecker;
import whocraft.tardis_refined.compat.portals.ImmersivePortals;
import whocraft.tardis_refined.compat.portals.ImmersivePortalsClient;

import java.util.SortedMap;

Expand Down Expand Up @@ -71,6 +74,11 @@ public static void copyRenderTarget(RenderTarget src, RenderTarget dest) {
private static ResourceLocation BLACK = new ResourceLocation(TardisRefined.MODID, "textures/black_portal.png");

private static void renderDoorOpen(GlobalDoorBlockEntity blockEntity, PoseStack stack, int packedLight, float rotation, ShellDoorModel currentModel, boolean isOpen, TardisClientData tardisClientData) {
if(ModCompatChecker.immersivePortals()){
if(ImmersivePortalsClient.shouldStopRenderingInPortal()){
return;
}
}
stack.pushPose();

// Fix transform
Expand All @@ -82,6 +90,9 @@ private static void renderDoorOpen(GlobalDoorBlockEntity blockEntity, PoseStack
// Unbind RenderTarget
Minecraft.getInstance().getMainRenderTarget().unbindWrite();
RENDER_TARGET_HELPER.start();
if (!getIsStencilEnabled(RENDER_TARGET_HELPER.renderTarget))
setIsStencilEnabled(RENDER_TARGET_HELPER.renderTarget, true);

copyRenderTarget(Minecraft.getInstance().getMainRenderTarget(), RENDER_TARGET_HELPER.renderTarget);

// Render Door Frame
Expand All @@ -92,10 +103,10 @@ private static void renderDoorOpen(GlobalDoorBlockEntity blockEntity, PoseStack

// Enable and configure stencil buffer
GL11.glEnable(GL11.GL_STENCIL_TEST);
RenderSystem.stencilMask(0xFF); // Ensure stencil mask is set before clearing
RenderSystem.clear(GL11.GL_STENCIL_BUFFER_BIT, true); // Clear stencil buffer
RenderSystem.stencilFunc(GL11.GL_ALWAYS, 1, 0xFF);
RenderSystem.stencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE);
GL11.glStencilMask(0xFF); // Ensure stencil mask is set before clearing
GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT); // Clear stencil buffer
GL11.glStencilFunc(GL11.GL_ALWAYS, 1, 0xFF);
GL11.glStencilOp(GL11.GL_KEEP, GL11.GL_KEEP, GL11.GL_REPLACE);

// Render portal mask with depth writing enabled
RenderSystem.depthMask(true);
Expand All @@ -106,28 +117,34 @@ private static void renderDoorOpen(GlobalDoorBlockEntity blockEntity, PoseStack
RenderSystem.depthMask(false); // Disable depth writing for subsequent rendering

// Render vortex based on stencil buffer
RenderSystem.stencilMask(0x00);
RenderSystem.stencilFunc(GL11.GL_EQUAL, 1, 0xFF);
RenderSystem.depthFunc(GL11.GL_ALWAYS); // Ignore depth buffer
GL11.glStencilMask(0x00);
GL11.glStencilFunc(GL11.GL_EQUAL, 1, 0xFF);
GlStateManager._depthFunc(GL11.GL_ALWAYS); // Ignore depth buffer

RenderSystem.colorMask(true, true, true, false);
GL11.glColorMask(true, true, true, false);
stack.pushPose();
stack.scale(10, 10, 10);

VORTEX.time.speed = (0.3f + tardisClientData.getThrottleStage() * 0.1f);
VORTEX.renderVortex(stack, 1, false);
stack.popPose();

RenderSystem.depthFunc(GL11.GL_LEQUAL); // Restore depth function
RenderSystem.colorMask(false, false, false, true);
GlStateManager._depthFunc(GL11.GL_LEQUAL); // Restore depth function
GL11.glColorMask(false, false, false, true);

// Copy render target back to main buffer

Minecraft.getInstance().getMainRenderTarget().bindWrite(true);
copyRenderTarget(RENDER_TARGET_HELPER.renderTarget, Minecraft.getInstance().getMainRenderTarget());

if (getIsStencilEnabled(RENDER_TARGET_HELPER.renderTarget))
setIsStencilEnabled(RENDER_TARGET_HELPER.renderTarget, false);

Minecraft.getInstance().getMainRenderTarget().bindWrite(true);

GL11.glDisable(GL11.GL_STENCIL_TEST); // Disable stencil test
RenderSystem.stencilMask(0xFF);
RenderSystem.colorMask(true, true, true, true);
GL11.glStencilMask(0xFF);
GL11.glColorMask(true, true, true, true);
RenderSystem.depthMask(true);
GL11.glGetError();
stack.popPose();
Expand All @@ -149,6 +166,15 @@ private static void renderNoVortex(GlobalDoorBlockEntity blockEntity, PoseStack
stack.popPose();
}

@Environment(EnvType.CLIENT)
public static boolean getIsStencilEnabled(RenderTarget renderTarget) {
return ((RenderTargetStencil) renderTarget).tr$getisStencilEnabled();
}

@Environment(EnvType.CLIENT)
public static void setIsStencilEnabled(RenderTarget renderTarget, boolean cond) {
((RenderTargetStencil) renderTarget).tr$setisStencilEnabledAndReload(cond);
}

public void start() {
Window window = Minecraft.getInstance().getWindow();
Expand All @@ -171,17 +197,6 @@ public void end(boolean clear) {
}


@Environment(EnvType.CLIENT)
public static boolean getIsStencilEnabled(RenderTarget renderTarget) {
return ((RenderTargetStencil) renderTarget).tr$getisStencilEnabled();
}

@Environment(EnvType.CLIENT)
public static void setIsStencilEnabled(RenderTarget renderTarget, boolean cond) {
((RenderTargetStencil) renderTarget).tr$setisStencilEnabledAndReload(cond);
}


@Environment(value = EnvType.CLIENT)
public static class StencilBufferStorage extends RenderBuffers {

Expand All @@ -191,6 +206,7 @@ public static class StencilBufferStorage extends RenderBuffers {
private final Object2ObjectLinkedOpenHashMap typeBufferBuilder = Util.make(new Object2ObjectLinkedOpenHashMap(), map -> {
put(map, getConsumer());
});
private final MultiBufferSource.BufferSource consumer = MultiBufferSource.immediateWithBuffers(typeBufferBuilder, new BufferBuilder(256));

public static RenderType getConsumer() {
RenderType.CompositeState parameters = RenderType.CompositeState.builder()
Expand All @@ -201,8 +217,6 @@ public static RenderType getConsumer() {
QUADS, 256, false, true, parameters);
}

private final MultiBufferSource.BufferSource consumer = MultiBufferSource.immediateWithBuffers(typeBufferBuilder, new BufferBuilder(256));

private static void put(Object2ObjectLinkedOpenHashMap<RenderType, BufferBuilder> builderStorage, RenderType layer) {
builderStorage.put(layer, new BufferBuilder(layer.bufferSize()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ public void tick() {
public boolean isPortalValid() {
UUID tardisId = getTardisId();


if (level() instanceof ServerLevel serverLevel && tickCount > (20 * 40)) {
PortalEntry portalEntry = ImmersivePortals.getPortalsForTardis(tardisId);


if (portalEntry == null && this.tickCount > (2 * 20) && !this.getOriginWorld().isClientSide()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ public static boolean onDoorRemoved(Level level, Player player, BlockPos blockPo

public static void createPortals(TardisLevelOperator operator) {

if(operator.getPilotingManager().isInFlight()){
destroyPortals(operator);
return;
}

// Just for debugging editing values
if (!Platform.isProduction()) {
setupPortalsForShellThemes();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package whocraft.tardis_refined.compat.portals;

import com.mojang.blaze3d.pipeline.RenderTarget;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
import qouteall.imm_ptl.core.compat.IPPortingLibCompat;
import qouteall.imm_ptl.core.render.context_management.PortalRendering;

public class ImmersivePortalsClient {
Expand All @@ -13,7 +15,17 @@ public static void doClientRenderers() {
EntityRendererRegistry.register(ImmersivePortals.BOTI_PORTAL.get(), BotiPortalRenderer::new);
}

@Environment(EnvType.CLIENT)
public static boolean isStencilEnabled(RenderTarget renderTarget){
return IPPortingLibCompat.getIsStencilEnabled(renderTarget);
}

@Environment(EnvType.CLIENT)
public static void setStencilEnabled(RenderTarget renderTarget, boolean cond){
IPPortingLibCompat.setIsStencilEnabled(renderTarget, cond);
}

@Environment(EnvType.CLIENT)
public static boolean shouldStopRenderingInPortal() {
if (PortalRendering.isRendering()) return true;
return false;
Expand Down

This file was deleted.

9 changes: 4 additions & 5 deletions common/src/main/resources/tardis_refined-common.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
"VillagerMixin"
],
"client": [
"render.FogRendererMixin",
"render.ui.GuiMixin",
"LocalPlayerMixin",
"MultiplayerGameModeMixin",
"render.FogRendererMixin",
"render.PlayerRenderMixin",
"render.ui.SpectatorGuiMixin",
"render.buffer.MixinMainTarget",
"render.buffer.MixinRenderTarget"
"render.buffer.MixinRenderTarget",
"render.ui.GuiMixin",
"render.ui.SpectatorGuiMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
5 changes: 5 additions & 0 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ dependencies {
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-world:${rootProject.cardinal_version}"
modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${rootProject.cardinal_version}"

// Create - dependencies are added transitively
modImplementation("com.simibubi.create:create-fabric-${minecraft_version}:${create_version_fabric}")

// Includes Cardinal Components API as a Jar-in-Jar dependency (optional)
include "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${rootProject.cardinal_version}"
Expand Down Expand Up @@ -190,6 +192,9 @@ processResources {
inputs.properties replaceProperties
replaceProperties.put 'project', project

duplicatesStrategy = DuplicatesStrategy.INCLUDE


filesMatching(resourceTargets) {
expand replaceProperties
}
Expand Down

0 comments on commit 1f6b44e

Please sign in to comment.