Skip to content

Commit

Permalink
Gateway Special Model is back babyyy + sanity manager enhancements + …
Browse files Browse the repository at this point in the history
…emissive textures
  • Loading branch information
northernlimit committed Dec 6, 2024
1 parent b6dafd3 commit 8f0ad9e
Show file tree
Hide file tree
Showing 25 changed files with 307 additions and 409 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ base {
archivesName = project.archives_base_name
}

loom {
accessWidenerPath = file("src/main/resources/cubliminal.accesswidener")
}

repositories {
mavenCentral()
maven {
Expand Down
32 changes: 29 additions & 3 deletions src/main/java/net/limit/cubliminal/CubliminalClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,50 @@
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.limit.cubliminal.client.hud.NoClippingHudOverlay;
import net.limit.cubliminal.client.hud.SanityBarHudOverlay;
import net.limit.cubliminal.client.render.ManilaGatewayRenderer;
import net.limit.cubliminal.entity.client.SeatRenderer;
import net.limit.cubliminal.event.KeyInputHandler;
import net.limit.cubliminal.init.*;
import net.limit.cubliminal.util.IEntityDataSaver;
import net.minecraft.client.gl.ShaderProgramKey;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.*;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactories;

@Environment(EnvType.CLIENT)
public class CubliminalClient implements ClientModInitializer {

public static final ShaderProgramKey RENDERTYPE_CUBLIMINAL_MANILA_SKYBOX = ShaderProgramKeys.register("rendertype_cubliminal_manila_skybox", VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL);

public static final RenderPhase.ShaderProgram MANILA_PROGRAM = new RenderPhase.ShaderProgram(RENDERTYPE_CUBLIMINAL_MANILA_SKYBOX);

public static final RenderLayer MANILA = RenderLayer.of("manila", VertexFormats.POSITION,
VertexFormat.DrawMode.QUADS, 1536, false, false,
RenderLayer.MultiPhaseParameters.builder().program(MANILA_PROGRAM).texture(
RenderPhase.Textures.create()
.add(Cubliminal.id("textures/sky/manila_" + 0 + ".png"), false, false)
.add(Cubliminal.id("textures/sky/manila_" + 1 + ".png"), false, false)
.add(Cubliminal.id("textures/sky/manila_" + 2 + ".png"), false, false)
.add(Cubliminal.id("textures/sky/manila_" + 3 + ".png"), false, false)
.add(Cubliminal.id("textures/sky/manila_" + 4 + ".png"), false, false)
.add(Cubliminal.id("textures/sky/manila_" + 5 + ".png"), false, false)
.build()).build(false));

@Override
public void onInitializeClient() {
BlockRenderLayerMap.INSTANCE.putBlock(CubliminalBlocks.THE_LOBBY_GATEWAY_BLOCK, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlocks(RenderLayer.getTranslucent(),
CubliminalBlocks.THE_LOBBY_GATEWAY_BLOCK,
CubliminalBlocks.EMERGENCY_EXIT_DOOR_0,
CubliminalBlocks.MOLD,
CubliminalBlocks.JUMBLED_DOCUMENTS);
CubliminalBlocks.JUMBLED_DOCUMENTS,
CubliminalBlocks.EXIT_SIGN,
CubliminalBlocks.SMOKE_DETECTOR);

BlockEntityRendererFactories.register(CubliminalBlockEntities.THE_LOBBY_GATEWAY_BLOCK_ENTITY, ManilaGatewayRenderer::new);

KeyInputHandler.register();
//CubliminalModelRenderers.init();

EntityRendererRegistry
.register(CubliminalEntities.SEAT_ENTITY, SeatRenderer::new);
Expand All @@ -46,4 +71,5 @@ public void onInitializeClient() {
HudRenderCallback.EVENT.register(NoClippingHudOverlay.INSTANCE);
HudRenderCallback.EVENT.register(new SanityBarHudOverlay());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public class TheLobbyGatewayBlock extends BlockWithEntity implements BlockEntityProvider {
public static final MapCodec<TheLobbyGatewayBlock> CODEC = TheLobbyGatewayBlock.createCodec(TheLobbyGatewayBlock::new);
private static final BooleanProperty LIT = Properties.LIT;
public static final BooleanProperty LIT = Properties.LIT;
public TheLobbyGatewayBlock(Settings settings) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState().with(LIT, true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import net.limit.cubliminal.init.CubliminalBlockEntities;
import net.limit.cubliminal.init.CubliminalBlocks;
import net.limit.cubliminal.init.CubliminalRegistrar;
import net.limit.cubliminal.util.SanityData;
import net.limit.cubliminal.util.SanityManager;
import net.minecraft.advancement.criterion.Criteria;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.Entity;
Expand All @@ -20,6 +21,7 @@
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.TeleportTarget;
import net.minecraft.world.World;
Expand Down Expand Up @@ -68,7 +70,7 @@ public static void tick(World world, BlockPos pos, BlockState state, TheLobbyGat
.getDefaultState().with(Properties.LIT, false))) {

for (Entity entity : world.getEntitiesByClass(Entity.class, new Box(pos).expand(16, 2, 11), Entity::isPlayer)) {
SanityData.resetTimer((ServerPlayerEntity) entity);
SanityManager.resetTimer((ServerPlayerEntity) entity);
}
}
List<Entity> list = world.getEntitiesByClass(Entity.class, new Box(pos), TheLobbyGatewayBlockEntity::canTeleport);
Expand Down Expand Up @@ -129,4 +131,8 @@ public static boolean canTeleport(Entity entity) {
public NbtCompound toInitialChunkDataNbt(RegistryWrapper.WrapperLookup registryLookup) {
return this.createNbt(registryLookup);
}

public boolean shouldDrawSide(Direction direction) {
return Block.shouldDrawSide(this.getCachedState(), this.world.getBlockState(this.getPos().offset(direction)), direction);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,26 @@ public void onHudRender(DrawContext drawContext, RenderTickCounter tickCounter)
Identifier texture;
RenderSystem.enableBlend();

if (i > 8) {
if (i > 80) {
texture = SANITY_BAR_0;
} else if (i > 6) {
} else if (i > 60) {
texture = SANITY_BAR_1;
} else if (i > 3) {
} else if (i > 30) {
texture = SANITY_BAR_2;
} else if (i > 1) {
} else if (i > 10) {
texture = SANITY_BAR_3;
} else {
texture = SANITY_BAR_4;
}

//drawContext.drawTexture(texture, x, l, 2, 0, 12, 32, 32, 32);
drawContext.drawTexture(RenderLayer::getGuiTextured, texture, x, l, 2, 0, 12, 32, 32, 32);

if (i > 0) {
int k = (int) (i * 0.1 * 28);
//drawContext.drawTexture(texture, x + 2, l + 30 - k, 20, 30 - k, 8, k, 32, 32);
int k = (int) (i * 0.01 * 28);
drawContext.drawTexture(RenderLayer::getGuiTextured, texture, x + 2, l + 30 - k, 20, 30 - k, 8, k, 32, 32);
}
int j = 3;
if (i > 9) j = 4;
String string = i * 10 + "%";
int j = i > 90 ? 4 : 3;
String string = i + "%";
drawContext.drawText(client.inGameHud.getTextRenderer(), string, x - j, l - 7, 20165255, true);
RenderSystem.disableBlend();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package net.limit.cubliminal.client.render;

import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.limit.cubliminal.CubliminalClient;
import net.limit.cubliminal.block.custom.TheLobbyGatewayBlock;
import net.limit.cubliminal.block.entity.TheLobbyGatewayBlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gl.ShaderProgram;
import net.minecraft.client.render.*;
import net.minecraft.client.render.block.entity.BlockEntityRenderer;
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.RotationAxis;
import org.joml.Matrix4f;

@Environment(EnvType.CLIENT)
public class ManilaGatewayRenderer implements BlockEntityRenderer<TheLobbyGatewayBlockEntity> {

public ManilaGatewayRenderer(BlockEntityRendererFactory.Context ctx) {
}

@Override
public void render(TheLobbyGatewayBlockEntity entity, float tickDelta, MatrixStack matrices,
VertexConsumerProvider vertexConsumers, int light, int overlay) {
if (entity.getCachedState().get(TheLobbyGatewayBlock.LIT)) {
matrices.push();

MinecraftClient client = MinecraftClient.getInstance();

VertexConsumer vertexConsumer = vertexConsumers.getBuffer(getLayer());
ShaderProgram shader = RenderSystem.setShader(CubliminalClient.RENDERTYPE_CUBLIMINAL_MANILA_SKYBOX);


Matrix4f positionMatrix = matrices.peek().getPositionMatrix();
this.renderSide(entity, positionMatrix, vertexConsumer, 0.0F, 1.0F, 0.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, Direction.SOUTH);
this.renderSide(entity, positionMatrix, vertexConsumer, 0.0F, 1.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 0.0F, Direction.NORTH);
this.renderSide(entity, positionMatrix, vertexConsumer, 1.0F, 1.0F, 1.0F, 0.0F, 0.0F, 1.0F, 1.0F, 0.0F, Direction.EAST);
this.renderSide(entity, positionMatrix, vertexConsumer, 0.0F, 0.0F, 0.0F, 1.0F, 0.0F, 1.0F, 1.0F, 0.0F, Direction.WEST);
this.renderSide(entity, positionMatrix, vertexConsumer, 0.0F, 1.0F, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F, 1.0F, Direction.DOWN);
this.renderSide(entity, positionMatrix, vertexConsumer, 0.0F, 1.0F, 1.0F, 1.0F, 1.0F, 1.0F, 0.0F, 0.0F, Direction.UP);

Camera camera = client.gameRenderer.getCamera();
Matrix4f rotation = new MatrixStack().peek().getPositionMatrix();
rotation.rotate(RotationAxis.POSITIVE_X.rotationDegrees(camera.getPitch()));
rotation.rotate(RotationAxis.POSITIVE_Y.rotationDegrees(camera.getYaw() + 180.0F));

if (shader.getUniform("RotMat") != null) {
shader.getUniform("RotMat").set(rotation);
}

matrices.pop();
}
}

private void renderSide(TheLobbyGatewayBlockEntity entity, Matrix4f model, VertexConsumer vertices, float x1, float x2, float y1, float y2, float z1, float z2, float z3, float z4, Direction side) {
if (entity.shouldDrawSide(side)) {
vertices.vertex(model, x1, y1, z1);
vertices.vertex(model, x2, y1, z2);
vertices.vertex(model, x2, y2, z3);
vertices.vertex(model, x1, y2, z4);
}
}

public RenderLayer getLayer() {
return CubliminalClient.MANILA;
}
}

This file was deleted.

15 changes: 7 additions & 8 deletions src/main/java/net/limit/cubliminal/event/ServerTickHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import net.limit.cubliminal.advancements.AdvancementHelper;
import net.limit.cubliminal.util.IEntityDataSaver;
import net.limit.cubliminal.util.NoClipEngine;
import net.limit.cubliminal.util.SanityData;
import net.limit.cubliminal.util.SanityManager;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryKey;
import net.minecraft.server.MinecraftServer;
Expand All @@ -27,18 +27,17 @@ public void onStartTick(MinecraftServer server) {
for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
boolean isVulnerable = !player.isCreative() && !player.isSpectator();
// sync both sanity and no-clip cooldown
SanityData.syncSanity(player);
SanityManager.syncSanity(player);
NoClipEngine.syncNoClip(player);
// run no-clip cooldown
if (NoClipEngine.isNoClipping(player) || (isVulnerable && AdvancementHelper.visitedManilaRoom(player))) {
if (NoClipEngine.isNoClipping(player) || (isVulnerable && inBackrooms(player.getWorld().getRegistryKey())
&& AdvancementHelper.visitedManilaRoom(player))) {
NoClipEngine.run(player);
}
// run sanity stuff
if (isVulnerable && inBackrooms(player.getWorld().getRegistryKey())
&& !player.getWorld().getDifficulty().equals(Difficulty.PEACEFUL)) {
if (player.getWorld().getTime() % 200 == 0) {
SanityData.run(player);
}
SanityManager.run(player);
}
}

Expand All @@ -49,14 +48,14 @@ public static void afterWorldChange(ServerPlayerEntity player, ServerWorld origi
RegistryKey<World> key = destination.getRegistryKey();
if (inBackrooms(key) && !AdvancementHelper.visitedManilaRoom(player)) {
// reset sanity as it was uninitialized
SanityData.resetTimer(player);
SanityManager.resetTimer(player);
}
}

public static void onAfterDeath(ServerPlayerEntity oldPlayer, ServerPlayerEntity newPlayer, boolean alive) {
NbtCompound oldNbt = IEntityDataSaver.cast(oldPlayer);
NbtCompound newNbt = IEntityDataSaver.cast(newPlayer);
newNbt.putInt("ticksToNc", oldNbt.getInt("ticksToNc"));
SanityData.resetTimer(newPlayer);
SanityManager.resetTimer(newPlayer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static void register(CommandDispatcher<ServerCommandSource> dispatcher, C
.then(CommandManager.argument("targets", EntityArgumentType.players())
.executes(context -> execute(context.getSource(), EntityArgumentType.getPlayers(context, "targets")))
.then(CommandManager.literal("set")
.then(CommandManager.argument("amount", IntegerArgumentType.integer(0, 10))
.then(CommandManager.argument("amount", IntegerArgumentType.integer(0, 100))
.executes(context -> execute(context.getSource(), EntityArgumentType.getPlayers(context, "targets"),
IntegerArgumentType.getInteger(context, "amount")))))));
}
Expand All @@ -45,7 +45,7 @@ private static int execute(ServerCommandSource source, Collection<ServerPlayerEn
}

private static int execute(ServerCommandSource source, Collection<ServerPlayerEntity> targets, int amount) {
if (amount < 0 || amount > 10) {
if (amount < 0 || amount > 100) {
source.sendError(Text.translatable("commands.sanity.failed.invalid_range"));
return 0;
}
Expand Down

This file was deleted.

Loading

0 comments on commit 8f0ad9e

Please sign in to comment.