Skip to content

Commit

Permalink
Added flux capacitor block
Browse files Browse the repository at this point in the history
  • Loading branch information
northernlimit committed Dec 13, 2024
1 parent 8f0ad9e commit 41ec0e2
Show file tree
Hide file tree
Showing 30 changed files with 1,402 additions and 174 deletions.
795 changes: 674 additions & 121 deletions LICENSE

Large diffs are not rendered by default.

24 changes: 7 additions & 17 deletions src/main/java/net/limit/cubliminal/CubliminalClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.limit.cubliminal.client.CubliminalRenderLayers;
import net.limit.cubliminal.client.hud.NoClippingHudOverlay;
import net.limit.cubliminal.client.hud.SanityBarHudOverlay;
import net.limit.cubliminal.client.render.FluxCapacitorRenderer;
import net.limit.cubliminal.client.render.ManilaGatewayRenderer;
import net.limit.cubliminal.entity.client.SeatRenderer;
import net.limit.cubliminal.event.KeyInputHandler;
Expand All @@ -23,22 +25,6 @@
@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());
Expand All @@ -48,15 +34,19 @@ public void onInitializeClient() {
CubliminalBlocks.MOLD,
CubliminalBlocks.JUMBLED_DOCUMENTS,
CubliminalBlocks.EXIT_SIGN,
CubliminalBlocks.SMOKE_DETECTOR);
CubliminalBlocks.SMOKE_DETECTOR,
CubliminalBlocks.FLUX_CAPACITOR);

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

KeyInputHandler.register();

EntityRendererRegistry
.register(CubliminalEntities.SEAT_ENTITY, SeatRenderer::new);

CubliminalRenderLayers.init();


ClientPlayNetworking.registerGlobalReceiver(CubliminalPackets.NoClipSyncPayload.ID, (payload, context) -> {
ClientPlayerEntity player = context.player();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package net.limit.cubliminal.block.custom;

import com.mojang.serialization.MapCodec;
import net.limit.cubliminal.block.entity.FluxCapacitorBlockEntity;
import net.limit.cubliminal.init.CubliminalBlockEntities;
import net.limit.cubliminal.init.CubliminalSounds;
import net.minecraft.block.*;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.sound.SoundCategory;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.block.WireOrientation;
import org.jetbrains.annotations.Nullable;

public class FluxCapacitorBlock extends BlockWithEntity implements BlockEntityProvider {
public static final MapCodec<FluxCapacitorBlock> CODEC = FluxCapacitorBlock.createCodec(FluxCapacitorBlock::new);
public static final BooleanProperty POWERED = Properties.POWERED;
public static final EnumProperty<Direction> FACING = HorizontalFacingBlock.FACING;
public FluxCapacitorBlock(Settings settings) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState().with(POWERED, false).with(FACING, Direction.NORTH));
}

@Override
protected MapCodec<? extends BlockWithEntity> getCodec() {
return CODEC;
}

@Nullable
@Override
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
return new FluxCapacitorBlockEntity(pos, state);
}

@Override
public BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return validateTicker(type, CubliminalBlockEntities.FLUX_CAPACITOR_BLOCK_ENTITY, FluxCapacitorBlockEntity::tick);
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(POWERED, FACING);
}

@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return this.getDefaultState().with(FACING, ctx.getHorizontalPlayerFacing().getOpposite())
.with(POWERED, shouldBePowered(ctx.getWorld(), ctx.getBlockPos()));
}

@Override
protected void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, @Nullable WireOrientation wireOrientation, boolean notify) {
if (shouldBePowered(world, pos)) {
world.setBlockState(pos, state.with(POWERED, true));
}
}

protected boolean shouldBePowered(World world, BlockPos pos) {
return world.isReceivingRedstonePower(pos) && world.getBlockState(pos.up())
.equals(Blocks.LIGHTNING_ROD.getDefaultState().with(LightningRodBlock.POWERED, true));
}

@Override
public void onBroken(WorldAccess world, BlockPos pos, BlockState state) {
if (!world.isClient()) {
CubliminalSounds.clientStopSound(world.getServer().getOverworld().getPlayers(),
SoundCategory.BLOCKS, CubliminalSounds.FLUX_CAPACITOR.value().id());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundCategory;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.EnumProperty;
Expand All @@ -27,7 +26,6 @@
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import net.minecraft.world.tick.ScheduledTickView;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package net.limit.cubliminal.block.entity;

import net.limit.cubliminal.block.custom.FluxCapacitorBlock;
import net.limit.cubliminal.client.hud.NoClippingHudOverlay;
import net.limit.cubliminal.init.CubliminalBlockEntities;
import net.limit.cubliminal.init.CubliminalSounds;
import net.limit.cubliminal.util.NoClipEngine;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;

import java.util.function.Predicate;

public class FluxCapacitorBlockEntity extends BlockEntity {

public FluxCapacitorBlockEntity(BlockPos pos, BlockState state) {
super(CubliminalBlockEntities.FLUX_CAPACITOR_BLOCK_ENTITY, pos, state);
}

private boolean canBreakReality;
private int realityTicks;


@Override
protected void writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) {
super.writeNbt(nbt, registryLookup);
nbt.putInt("RealityTicks", this.realityTicks);
}

@Override
protected void readNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) {
super.readNbt(nbt, registryLookup);
this.realityTicks = nbt.getInt("RealityTicks");
}


public static void tick(World world, BlockPos pos, BlockState state, FluxCapacitorBlockEntity entity) {
if (state.get(FluxCapacitorBlock.POWERED) && !entity.canBreakReality) {
entity.canBreakReality = true;
world.playSoundAtBlockCenter(pos, CubliminalSounds.FLUX_CAPACITOR.value(),
SoundCategory.BLOCKS, 1.0f, 1.0f, false);
}
if (entity.canBreakReality) {
entity.breakReality(world, state);
}
}


@Override
public boolean onSyncedBlockEvent(int type, int data) {
if (type == 1) {
return true;
} else return super.onSyncedBlockEvent(type, data);
}

public void breakReality(World world, BlockState state) {
if (this.realityTicks > 279) {
world.setBlockState(pos, state.with(FluxCapacitorBlock.POWERED, false));
this.canBreakReality = false;
this.realityTicks = 0;
} else {
++this.realityTicks;
if (this.realityTicks == 220) {
if (world.isClient) {
NoClippingHudOverlay.INSTANCE.setAux_renderOverlay(false);
} else {
for (PlayerEntity player : world.getPlayers().stream().filter(Predicate.not(PlayerEntity::isSpectator)).toList()) {
NoClipEngine.noClip(player);
}
}
} else if (world.isClient && this.realityTicks == 100 &&
!MinecraftClient.getInstance().player.isSpectator()) {
NoClippingHudOverlay.INSTANCE.setAux_renderOverlay(true);
}
}
}

public int getRealityTicks() {
return this.realityTicks;
}

public boolean canBreakReality() {
return this.canBreakReality;
}

@Override
public NbtCompound toInitialChunkDataNbt(RegistryWrapper.WrapperLookup registryLookup) {
return this.createNbt(registryLookup);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.limit.cubliminal.client;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.limit.cubliminal.Cubliminal;
import net.minecraft.client.gl.ShaderProgramKey;
import net.minecraft.client.gl.ShaderProgramKeys;
import net.minecraft.client.render.RenderLayer;
import net.minecraft.client.render.RenderPhase;
import net.minecraft.client.render.VertexFormat;
import net.minecraft.client.render.VertexFormats;

@Environment(EnvType.CLIENT)
public class CubliminalRenderLayers {
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));


public static final ShaderProgramKey RENDERTYPE_BLOOM_DOT = ShaderProgramKeys.register("rendertype_bloom_dot", VertexFormats.POSITION_COLOR);

public static final RenderPhase.ShaderProgram BLOOM_PROGRAM = new RenderPhase.ShaderProgram(RENDERTYPE_BLOOM_DOT);

public static final RenderLayer BLOOM = RenderLayer.of("bloom", VertexFormats.POSITION_COLOR_LIGHT,
VertexFormat.DrawMode.QUADS, 1536, false, false,
RenderLayer.MultiPhaseParameters.builder().program(BLOOM_PROGRAM).build(false));


public static void init() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class NoClippingHudOverlay implements HudRenderCallback {

public static NoClippingHudOverlay INSTANCE = new NoClippingHudOverlay();
private boolean clippingIntoWall = false;
private boolean aux_renderOverlay = false;

private static final Identifier GLITCH_OVERLAY_1 = Cubliminal.id("textures/hud/noclip/glitch_overlay_1.png");
private static final Identifier GLITCH_OVERLAY_2 = Cubliminal.id("textures/hud/noclip/glitch_overlay_2.png");
Expand Down Expand Up @@ -48,7 +49,7 @@ public void onHudRender(DrawContext drawContext, RenderTickCounter tickCounter)
break;
}
}
} else if (this.clippingIntoWall) {
} else if (this.clippingIntoWall || this.aux_renderOverlay) {
for (int i = 0; i < 2; i++) {
if ((player.getWorld().getTime() + i) % 6 == 0) {
Random random = player.getRandom();
Expand Down Expand Up @@ -96,4 +97,8 @@ public boolean isClippingIntoWall() {
public void setClippingIntoWall(boolean clippingIntoWall) {
this.clippingIntoWall = clippingIntoWall;
}

public void setAux_renderOverlay(boolean aux_renderOverlay) {
this.aux_renderOverlay = aux_renderOverlay;
}
}
Loading

0 comments on commit 41ec0e2

Please sign in to comment.