Skip to content

Commit

Permalink
- You can now view your TARDIS exterior via the Monitor
Browse files Browse the repository at this point in the history
- Holographic exteriors on consoles now spin according to throttle
- Improved UI for Gravity Shaft
  • Loading branch information
Jeryn99 committed Nov 25, 2024
1 parent 84a6a7d commit 9c08ea0
Show file tree
Hide file tree
Showing 20 changed files with 313 additions and 111 deletions.
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@
## Gameplay changes
- Standing in a Crashed smoke of a crashed TARDIS will cause 0.5 damage to the player for the duration their standing in it
- Recovery Progress of crashed TARDIS now displayed on controls until repair is complete
- Recovery Progress of crashed TARDIS is now displayed on Key tooltip
- Recovery Progress of crashed TARDIS is now displayed on Key tooltip
- You can now view your TARDIS exterior via the Monitor
- Holographic exteriors on consoles now spin according to throttle
- Improved UI for Gravity Shaft

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package whocraft.tardis_refined.client;

import net.minecraft.client.KeyMapping;
import org.lwjgl.glfw.GLFW;
import whocraft.tardis_refined.TardisRefined;

public class TRKeybinds {

public static KeyMapping EXIT_EXTERIOR_VIEW = new KeyMapping("exit_exterior_view", GLFW.GLFW_KEY_TAB, TardisRefined.NAME);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package whocraft.tardis_refined.client.overlays;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.math.Transformation;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import whocraft.tardis_refined.TardisRefined;
import whocraft.tardis_refined.client.TRKeybinds;
import whocraft.tardis_refined.common.capability.player.TardisPlayerInfo;
import whocraft.tardis_refined.constants.ModMessages;

public class ExteriorViewOverlay {

public static ResourceLocation IMAGE = new ResourceLocation(TardisRefined.MODID, "textures/gui/external_view.png");


public static void renderOverlay(GuiGraphics guiGraphics) {
Minecraft mc = Minecraft.getInstance();

TardisPlayerInfo.get(mc.player).ifPresent(tardisPlayerInfo -> {
PoseStack poseStack = guiGraphics.pose();
poseStack.pushPose();

if(!tardisPlayerInfo.isViewingTardis()) return;
if(mc.getDebugOverlay().showDebugScreen()) return;

Font fontRenderer = mc.font;
int x = 10;
int y = 10;

// Create the message with a keybind
MutableComponent ascendKey = Component.translatable(TRKeybinds.EXIT_EXTERIOR_VIEW.getDefaultKey().getName());
MutableComponent message = Component.translatable(ModMessages.EXIT_EXTERNAL_VIEW, ascendKey)
.withStyle(ChatFormatting.BOLD, ChatFormatting.AQUA);

// Render a semi-transparent background for better text readability
guiGraphics.fill(x - 5, y - 5, x + fontRenderer.width(message.getString()) + 5, y + 15, 0x88000000);

// Render the text with a shadow
MultiBufferSource.BufferSource renderImpl = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());
fontRenderer.drawInBatch(
message.getString(),
x,
y,
ChatFormatting.WHITE.getColor(),
false,
Transformation.identity().getMatrix(),
renderImpl,
Font.DisplayMode.NORMAL,
0,
15728880
);
renderImpl.endBatch();

// Pop pose to reset transformations
poseStack.popPose();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package whocraft.tardis_refined.client.overlays;

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.math.Transformation;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.player.Player;
import whocraft.tardis_refined.common.GravityUtil;
import whocraft.tardis_refined.constants.ModMessages;

public class GravityOverlay {

private static boolean isInShaft = false;

private static void checkOverlay(Player player){
isInShaft = GravityUtil.isInGravityShaft(player);
}

public static void renderOverlay(GuiGraphics guiGraphics) {
Minecraft mc = Minecraft.getInstance();
Font fontRenderer = mc.font;
LocalPlayer player = mc.player;
PoseStack poseStack = guiGraphics.pose();

// Perform overlay checks periodically
if (player.tickCount % 100 == 0) {
checkOverlay(player);
}

if (isInShaft && !mc.getDebugOverlay().showDebugScreen()) {
poseStack.pushPose();
poseStack.scale(1.2f, 1.2f, 1.2f);

// Padding for better positioning
int padding = 15; // Amount of padding from the screen edges
int x = padding;
int y = padding;

MutableComponent ascendKey = Component.translatable(mc.options.keyJump.getDefaultKey().getName());
MutableComponent descendKey = Component.translatable(mc.options.keyShift.getDefaultKey().getName());

// Get the translated strings for both keys
String ascendKeyText = Component.translatable(ModMessages.ASCEND_KEY, ascendKey).getString();
String descendKeyText = Component.translatable(ModMessages.DESCEND_KEY, descendKey).getString();

// Calculate the longest key text width
int maxWidth = Math.max(fontRenderer.width(ascendKeyText), fontRenderer.width(descendKeyText));

MultiBufferSource.BufferSource renderImpl = MultiBufferSource.immediate(Tesselator.getInstance().getBuilder());

// Render both key texts
fontRenderer.drawInBatch(
ascendKeyText,
x,
y,
ChatFormatting.WHITE.getColor(),
true,
Transformation.identity().getMatrix(),
renderImpl,
Font.DisplayMode.NORMAL,
0,
15728880
);

fontRenderer.drawInBatch(
descendKeyText,
x,
y + fontRenderer.lineHeight,
ChatFormatting.WHITE.getColor(),
true,
Transformation.identity().getMatrix(),
renderImpl,
Font.DisplayMode.NORMAL,
0,
15728880
);

renderImpl.endBatch();

guiGraphics.fill(
x - 5,
y - 5,
x + maxWidth,
y + fontRenderer.lineHeight * 2,
0x88000000
);

poseStack.popPose();
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@

import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.math.Axis;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.world.phys.Vec3;
import org.joml.Matrix4f;
import whocraft.tardis_refined.client.TardisClientData;
import whocraft.tardis_refined.client.model.blockentity.console.ConsoleModelCollection;
import whocraft.tardis_refined.client.model.blockentity.console.ConsoleUnit;
Expand All @@ -23,7 +17,6 @@
import whocraft.tardis_refined.common.block.console.GlobalConsoleBlock;
import whocraft.tardis_refined.common.blockentity.console.GlobalConsoleBlockEntity;
import whocraft.tardis_refined.common.tardis.themes.ConsoleTheme;
import whocraft.tardis_refined.common.tardis.themes.ShellTheme;
import whocraft.tardis_refined.patterns.ShellPattern;
import whocraft.tardis_refined.patterns.ShellPatterns;

Expand Down Expand Up @@ -74,6 +67,8 @@ public void render(GlobalConsoleBlockEntity blockEntity, float partialTick, Pose
private void renderHoloShell(Vec3 offset, int rotation, GlobalConsoleBlockEntity blockEntity, PoseStack poseStack, MultiBufferSource bufferSource, int packedLight, Vec3 color) {
if (blockEntity.getLevel().random.nextInt(20) != 0) {
poseStack.pushPose();

// Fetch shell data
TardisClientData reactions = TardisClientData.getInstance(blockEntity.getLevel().dimension());
ResourceLocation shellTheme = reactions.getShellTheme();
ResourceLocation shellPattern = reactions.getShellPattern();
Expand All @@ -82,12 +77,29 @@ private void renderHoloShell(Vec3 offset, int rotation, GlobalConsoleBlockEntity
var model = ShellModelCollection.getInstance().getShellEntry(shellTheme).getShellModel(pattern);
model.setDoorPosition(false);

// Base rotation and positioning
poseStack.mulPose(Axis.ZP.rotationDegrees(180F));
poseStack.translate(offset.x, offset.y, offset.z);
poseStack.translate(0, blockEntity.getLevel().random.nextFloat() * 0.01, 0);
poseStack.scale(0.1f, 0.1f, 0.1f);

// Add subtle floating animation
if (reactions.isFlying()) {
poseStack.mulPose(Axis.YP.rotationDegrees(((blockEntity.getLevel().getGameTime() % 360)) * 25f));
float floatingOffset = (float) Math.sin(blockEntity.getLevel().getGameTime() / 15.0) * 0.05f;
poseStack.translate(0, floatingOffset, 0);
}

// Random subtle jitter
poseStack.translate(
blockEntity.getLevel().random.nextFloat() * 0.005f - 0.0025f,
blockEntity.getLevel().random.nextFloat() * 0.005f - 0.0025f,
blockEntity.getLevel().random.nextFloat() * 0.005f - 0.0025f
);

float scaleModifier = 0.1f + (float) Math.sin(blockEntity.getLevel().getGameTime() / 20.0) * 0.005f;
poseStack.scale(scaleModifier, scaleModifier, scaleModifier);

// Add rotation effect
if (reactions.isFlying()) {
poseStack.mulPose(Axis.YP.rotationDegrees((blockEntity.getLevel().getGameTime() % 360) * (reactions.getThrottleStage() * 5L)));
} else {
poseStack.mulPose(Axis.YP.rotationDegrees(rotation % 360));
}
Expand All @@ -96,11 +108,33 @@ private void renderHoloShell(Vec3 offset, int rotation, GlobalConsoleBlockEntity
ShellSelectionScreen.generateDummyGlobalShell();
}

model.renderShell(ShellSelectionScreen.globalShellBlockEntity, false, true, poseStack, bufferSource.getBuffer(RenderType.entityTranslucent(pattern.exteriorDoorTexture().texture())), packedLight, OverlayTexture.NO_OVERLAY, (float) color.x, (float) color.y, (float) color.z, 0.25f);
// Dynamic flickering alpha for a hologram effect
float flickerAlpha = 0.2f + blockEntity.getLevel().random.nextFloat() * 0.1f;

boolean recoveryOrCrashing = reactions.isCrashing() || reactions.isInRecovery();

float time = blockEntity.getLevel().getGameTime() / 100.0f;
float red = recoveryOrCrashing ? 0.5f + (float) Math.sin(time) * 0.5f : (float) color.x;
float green = recoveryOrCrashing ? 0.5f + (float) Math.sin(time + Math.PI / 2) * 0.5f : (float) color.y;
float blue = recoveryOrCrashing ? 0.5f + (float) Math.sin(time + Math.PI) * 0.5f : (float) color.z;

model.renderShell(
ShellSelectionScreen.globalShellBlockEntity,
false,
true,
poseStack,
bufferSource.getBuffer(RenderType.entityTranslucent(pattern.exteriorDoorTexture().texture())),
packedLight,
OverlayTexture.NO_OVERLAY,
red,
green,
blue,
flickerAlpha
);

poseStack.popPose();

}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Abilities;
import net.minecraft.world.entity.player.Player;
import whocraft.tardis_refined.common.capability.tardis.TardisLevelOperator;
import whocraft.tardis_refined.common.tardis.TardisNavLocation;
Expand All @@ -11,6 +12,8 @@

public interface TardisPilot {

void updatePlayerAbilities(ServerPlayer player, Abilities abilities, boolean isWatcher);

void setupPlayerForInspection(ServerPlayer serverPlayer, TardisLevelOperator tardisLevelOperator, TardisNavLocation spectateTarget);

void endPlayerForInspection(ServerPlayer serverPlayer, TardisLevelOperator tardisLevelOperator);
Expand Down
Loading

0 comments on commit 9c08ea0

Please sign in to comment.