Skip to content

Commit

Permalink
Added noclip blocks which allow you to get from level 0 to level 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
MegDuck committed Sep 14, 2024
1 parent 4e40235 commit 166bb77
Show file tree
Hide file tree
Showing 15 changed files with 146 additions and 171 deletions.
40 changes: 40 additions & 0 deletions src/main/java/com/kpabr/backrooms/block/NoclipBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.kpabr.backrooms.block;

import com.kpabr.backrooms.util.EntityHelper;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class NoclipBlock extends Block {
public NoclipBlock(Settings settings) {
super(settings);
}

@SuppressWarnings("deprecation")
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
super.onEntityCollision(state, world, pos, entity);

if (world.isClient) {
return;
}

if (entity.isPlayer()) {
World portalBlockWorld = entity.getServer().getWorld(
RegistryKey.of(
RegistryKeys.WORLD,
new Identifier("backrooms:level_1")
)
);

EntityHelper.teleportToLevel((ServerPlayerEntity) entity, portalBlockWorld);
}
}

}
7 changes: 7 additions & 0 deletions src/main/java/com/kpabr/backrooms/config/BackroomsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public class BackroomsConfig implements ConfigData {
@ConfigEntry.Category("Entities/AI")
public boolean aiDebug = false;

@ConfigEntry.Category("Gameplay")
public double noclipCarpetingSpawnChance = 0.001;

@ConfigEntry.Category("Gameplay")
public double noclipWallSpawnChance = 0.005;


public static void init() {
AutoConfig.register(BackroomsConfig.class, GsonConfigSerializer::new);
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/kpabr/backrooms/init/BackroomsBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.ArrayList;
import java.util.HashMap;

import org.spongepowered.asm.mixin.injection.struct.InjectorGroupInfo.Map;

import com.kpabr.backrooms.block.entity.MaskBlockEntity;

import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroupEntries;
Expand Down Expand Up @@ -34,7 +32,6 @@
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;

@SuppressWarnings("unused")
public class BackroomsBlocks {
Expand Down Expand Up @@ -314,6 +311,12 @@ public class BackroomsBlocks {
public static final Block RED_CARPETING = add("red_carpeting", new CarpetingBlock(DyeColor.RED),
ItemGroups.BUILDING_BLOCKS);
public static final Block PORTAL_BLOCK = add("portal_block", new PortalBlock(), ItemGroups.BUILDING_BLOCKS);
public static final Block NOCLIP_CARPETING = add("noclip_carpeting",
new NoclipBlock(FabricBlockSettings.copyOf(Blocks.WHITE_WOOL).noCollision()),
ItemGroups.FUNCTIONAL);
public static final Block NOCLIP_WALL = add("noclip_wall",
new NoclipBlock(FabricBlockSettings.copyOf(Blocks.OAK_PLANKS).noCollision()),
ItemGroups.FUNCTIONAL);

private static <T extends BlockEntity> BlockEntityType<T> add(String name, BlockEntityType<T> blockEntity) {
Identifier id = BackroomsMod.id(name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class LevelOneChunkGenerator extends ChunkGenerator {
private static final BlockState ROOF_BLOCK = BackroomsBlocks.BEDROCK_BRICKS.getDefaultState();

private static final int ROOF_BEGIN_Y = 8 * (getFloorCount() + 1) + 1;
private RegistryEntryLookup<Block> blockLookup;
private final RegistryEntryLookup<Block> blockLookup;

public LevelOneChunkGenerator(RegistryEntryLookup<Biome> biomeRegistry, RegistryEntryLookup<Block> blockLookup) {
super(new LevelOneBiomeSource(biomeRegistry));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ public class LevelZeroChunkGenerator extends ChunkGenerator {
private static final BlockState ROOF_BLOCK = BackroomsBlocks.BEDROCK_BRICKS.getDefaultState();

private final HashMap<String, NbtPlacerUtil> loadedStructures = new HashMap<String, NbtPlacerUtil>(30);
private Identifier nbtId = BackroomsMod.id("level_zero");
private final Identifier nbtId = BackroomsMod.id("level_zero");

private Random moldPlacementRandom;
// Random object controlling generation of walls.
private Random random;
private RegistryEntryLookup<Block> blockLookup;

public LevelZeroChunkGenerator(RegistryEntryLookup<Biome> biomeRegistry, RegistryEntryLookup<Block> blockLookup) {
Expand All @@ -77,7 +79,6 @@ public void carve(ChunkRegion chunkRegion, long seed, NoiseConfig noiseConfig, B

@Override
public void buildSurface(ChunkRegion region, StructureAccessor structures, NoiseConfig noiseConfig, Chunk chunk) {

if (this.moldPlacementRandom == null) {
this.moldPlacementRandom = new Random(BackroomsLevels.LEVEL_0_WORLD.getSeed());
}
Expand All @@ -104,6 +105,10 @@ public void buildSurface(ChunkRegion region, StructureAccessor structures, Noise
.nextDouble() < BackroomsConfig.getInstance().moldyCorkTileChance) {

replace(BackroomsBlocks.MOLDY_CORK_TILE, chunk, pos);
} else if(block == BackroomsBlocks.NOCLIP_CARPETING.getDefaultState()) {
replace(BackroomsBlocks.RED_CARPETING, chunk, pos);
} else if(block == BackroomsBlocks.NOCLIP_WALL.getDefaultState()) {
replace(BackroomsBlocks.RED_PATTERNED_WALLPAPER, chunk, pos);
}
} else if (isBiomeEquals(BackroomsLevels.DECREPIT_BIOME, chunk, biomePos)) {
final BlockPos pos = chunkPos.getBlockPos(x, y, z);
Expand All @@ -113,6 +118,8 @@ public void buildSurface(ChunkRegion region, StructureAccessor structures, Noise
replace(BackroomsBlocks.MOLDY_WOOLEN_CARPET, chunk, pos);
} else if (block == BackroomsBlocks.FLUORESCENT_LIGHT.getDefaultState()) {
replace(BackroomsBlocks.REPAIRED_FLUORESCENT_LIGHT, chunk, pos);
} else if(block == BackroomsBlocks.NOCLIP_CARPETING.getDefaultState()) {
replace(BackroomsBlocks.MOLDY_WOOLEN_CARPET, chunk, pos);
}
}
}
Expand All @@ -133,6 +140,10 @@ public int getWorldHeight() {
@Override
public CompletableFuture<Chunk> populateNoise(Executor executor, Blender blender, NoiseConfig noiseConfig,
StructureAccessor structureAccessor, Chunk chunk) {
if (this.random == null) {
this.random = new Random(BackroomsLevels.LEVEL_0_WORLD.getSeed());
}

// IMPORTANT NOTE:
// For biomes generation we're using various "placeholder" blocks to replace
// them later with blocks we actually need in biomes.
Expand Down Expand Up @@ -164,7 +175,6 @@ public CompletableFuture<Chunk> populateNoise(Executor executor, Blender blender
}

if (isBiomeEquals(BackroomsLevels.MEGALOPHOBIA_BIOME, chunk, biomePos)) {

// Create 3 floors, top to bottom, because one Megalophobia floor equals 2
// normal floors.
for (int y = 2; y >= 0; y--) {
Expand All @@ -174,11 +184,6 @@ public CompletableFuture<Chunk> populateNoise(Executor executor, Blender blender
// southeasternmost space.
for (int x = 1; x >= 0; x--) {
for (int z = 1; z >= 0; z--) {
// Make a Random object controlling the generation of the section.
final Random random = new Random(BackroomsLevels.LEVEL_0_WORLD.getSeed()
+ BlockPos.asLong(startX, startZ, x + 4 * z + 20 * y));
// Decide the arrangement of the walls of the section. The two numbers with an F
// directly after them denote the probability of an eastern wall and a southern
// wall generating, respectively.
final int wallType = (random.nextFloat() < 0.4F ? 1 : 0) + (random.nextFloat() < 0.4F ? 2 : 0);

Expand All @@ -202,6 +207,7 @@ public CompletableFuture<Chunk> populateNoise(Executor executor, Blender blender
if ((wallType & 2) == 2) {
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 10; j++) {

for (int k = 0; k < 2; k++) {
chunk.setBlockState(
new BlockPos(startX + x * 8 + i, 2 + 12 * y + j,
Expand Down Expand Up @@ -275,14 +281,12 @@ public CompletableFuture<Chunk> populateNoise(Executor executor, Blender blender

// Mold placement code; will be subject to heavy revisions, so ignore for now.
for (int y = getFloorCount(); y >= 0; y--) {
final Random fullFloorRandom = new Random(BackroomsLevels.LEVEL_0_WORLD.getSeed()
+ BlockPos.asLong(chunk.getPos().getStartX(), chunk.getPos().getStartZ(), y));

for (int i = 0; i < 300; i++) {
final int x = fullFloorRandom.nextInt(16);
final int z = fullFloorRandom.nextInt(16);
int x2 = x + fullFloorRandom.nextInt(3) - 1;
int z2 = fullFloorRandom.nextInt(3) - 1;
final int x = random.nextInt(16);
final int z = random.nextInt(16);
int x2 = x + random.nextInt(3) - 1;
int z2 = random.nextInt(3) - 1;
if (chunk.getBlockState(new BlockPos(startX + x, 1 + 12 * y,
startZ + z)) == BackroomsBlocks.WOOLEN_CARPET.getDefaultState()) {
if (x2 < 0)
Expand All @@ -293,7 +297,7 @@ else if (x2 > 15)
z2 = 0;
else if (z2 > 15)
z2 = 15;
if (fullFloorRandom.nextFloat() < 0.1F || chunk.getBlockState(new BlockPos(startX + x2,
if (random.nextFloat() < 0.1F || chunk.getBlockState(new BlockPos(startX + x2,
1 + 12 * y, startZ + z2)) == BackroomsBlocks.CORK_TILE.getDefaultState()) {
chunk.setBlockState(
new BlockPos(startX + x, 1 + 12 * y, startZ + z),
Expand All @@ -320,9 +324,6 @@ else if (z2 > 15)
// southeasternmost space.
for (int x = 3; x >= 0; x--) {
for (int z = 3; z >= 0; z--) {
// Make a Random object controlling the generation of the section.
final Random random = new Random(BackroomsLevels.LEVEL_0_WORLD.getSeed()
+ BlockPos.asLong(startX, startZ, x + 4 * z + 20 * y));
// Decide the arrangement of the walls of the section. The two numbers with an F
// directly after them denote the probability of an eastern wall and a southern
// wall generating, respectively.
Expand All @@ -331,12 +332,22 @@ else if (z2 > 15)
// Check if the arrangement includes the eastern wall.
// and create eastern wall if true
if ((wallType & 1) == 1) {
double noclipWallChance = random.nextDouble(0, 1);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
chunk.setBlockState(
new BlockPos(startX + x * 4 + 3, 2 + 6 * y + j, startZ + z * 4 + i),
BackroomsBlocks.PATTERNED_WALLPAPER.getDefaultState(),
false);

if(noclipWallChance <= BackroomsConfig.getInstance().noclipWallSpawnChance) {
if(j <= 2) {
chunk.setBlockState(
new BlockPos(startX + x * 4 + 3, 2 + 6 * y + j, startZ + z * 4 + i),
BackroomsBlocks.NOCLIP_WALL.getDefaultState(),
false);
}
}
}
}
}
Expand Down Expand Up @@ -388,8 +399,15 @@ else if (z2 > 15)
// Generate the carpeting and the ceiling.
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
chunk.setBlockState(new BlockPos(startX + x * 4 + i, 1 + 6 * y, startZ + z * 4 + j),
BackroomsBlocks.WOOLEN_CARPET.getDefaultState(), false);
double noclipCarpetingChance = random.nextDouble(0, 1);

if(noclipCarpetingChance < BackroomsConfig.getInstance().noclipCarpetingSpawnChance) {
chunk.setBlockState(new BlockPos(startX + x * 4 + i, 1 + 6 * y, startZ + z * 4 + j),
BackroomsBlocks.NOCLIP_CARPETING.getDefaultState(), false);
} else {
chunk.setBlockState(new BlockPos(startX + x * 4 + i, 1 + 6 * y, startZ + z * 4 + j),
BackroomsBlocks.WOOLEN_CARPET.getDefaultState(), false);
}
chunk.setBlockState(new BlockPos(startX + x * 4 + i, 6 + 6 * y, startZ + z * 4 + j),
BackroomsBlocks.CORK_TILE.getDefaultState(), false);
}
Expand All @@ -400,32 +418,30 @@ else if (z2 > 15)
}
}

// Create an unique random Object for the current floor.
final Random fullFloorRandom = new Random(BackroomsLevels.LEVEL_0_WORLD.getSeed()
+ BlockPos.asLong(chunk.getPos().getStartX(), chunk.getPos().getStartZ(), y));

// Check whether a random number between zero and one is less than the number
// with an F directly after it. Currently, for debugging reasons, a "|| true"
// has been placed, which means that the following code will be excecuted
// anyways.
// Place a large (7x7 or bigger) room in the current chunk at the current floor.
// Both dimensions of the base of the room must be of the form 4x-1.
if (fullFloorRandom.nextFloat() < 0.1F || true) {
if (random.nextFloat() < 0.1F || true) {
// Define the amounts of regular and nofill rooms.
final int regularRooms = 14;
final int nofillRooms = 4;
// Choose the room that will be placed.
int roomNumber = (fullFloorRandom.nextInt(regularRooms + nofillRooms) + 1);
int roomNumber = (random.nextInt(regularRooms + nofillRooms) + 1);
// The number with an F directly after it denotes the probability of an empty
// room being generated regardless.
if (fullFloorRandom.nextFloat() < 0.6F) {
if (random.nextFloat() < 0.6F) {
roomNumber = 0;
}
String roomName = "backrooms_large_" + roomNumber;
if (roomNumber > regularRooms) {
roomName = "backrooms_large_nofill_" + (roomNumber - regularRooms);
}
// Choose the rotation for the room.
Direction dir = Direction.fromHorizontal(fullFloorRandom.nextInt(4));
Direction dir = Direction.fromHorizontal(random.nextInt(4));
BlockRotation rotation = switch (dir) {
case NORTH -> BlockRotation.COUNTERCLOCKWISE_90;
case EAST -> BlockRotation.NONE;
Expand All @@ -448,8 +464,8 @@ else if (z2 > 15)
// Place a structure only if it fits before the bedrock
if (6 * y + sizeY < ROOF_BEGIN_Y) {
// Choose a spot in the chunk.
final int x = fullFloorRandom.nextInt(5 - (sizeX + 1) / 4);
final int z = fullFloorRandom.nextInt(5 - (sizeZ + 1) / 4);
final int x = random.nextInt(5 - (sizeX + 1) / 4);
final int z = random.nextInt(5 - (sizeZ + 1) / 4);
// Fill the area the room will be placed in with air.
if (roomNumber <= regularRooms) {
for (int i = 0; i < sizeX; i++) {
Expand All @@ -473,14 +489,12 @@ else if (z2 > 15)

// Mold placement code; will be subject to heavy revisions, so ignore for now.
for (int y = getFloorCount(); y >= 0; y--) {
final Random fullFloorRandom = new Random(BackroomsLevels.LEVEL_0_WORLD.getSeed()
+ BlockPos.asLong(chunk.getPos().getStartX(), chunk.getPos().getStartZ(), y));

for (int i = 0; i < 300; i++) {
final int x = fullFloorRandom.nextInt(16);
final int z = fullFloorRandom.nextInt(16);
int x2 = x + fullFloorRandom.nextInt(3) - 1;
int z2 = fullFloorRandom.nextInt(3) - 1;
final int x = random.nextInt(16);
final int z = random.nextInt(16);
int x2 = x + random.nextInt(3) - 1;
int z2 = random.nextInt(3) - 1;
if (chunk.getBlockState(new BlockPos(startX + x, 1 + 6 * y,
startZ + z)) == BackroomsBlocks.WOOLEN_CARPET.getDefaultState()) {
if (x2 < 0)
Expand All @@ -491,7 +505,7 @@ else if (x2 > 15)
z2 = 0;
else if (z2 > 15)
z2 = 15;
if (fullFloorRandom.nextFloat() < 0.1F || chunk.getBlockState(new BlockPos(startX + x2,
if (random.nextFloat() < 0.1F || chunk.getBlockState(new BlockPos(startX + x2,
1 + 6 * y, startZ + z2)) == BackroomsBlocks.CORK_TILE.getDefaultState()) {
chunk.setBlockState(
new BlockPos(startX + x, 1 + 6 * y, startZ + z),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "backrooms:block/noclip_carpeting"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "backrooms:block/noclip_wall"
}
}
}
4 changes: 4 additions & 0 deletions src/main/resources/assets/backrooms/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
"block.backrooms.machinery": "Machinery",
"block.backrooms.roof_wiring": "Roof Wiring",
"block.backrooms.portal_block": "Portal Block",
"block.backrooms.noclip_wall": "Noclip Wallpaper",
"block.backrooms.noclip_carpeting": "Noclip Carpeting",

"container.backrooms.crate": "Crate",

Expand All @@ -120,6 +122,8 @@
"text.autoconfig.backrooms.option.almondMilkRestoring": "Almond milk decreasing the wretched meter",
"text.autoconfig.backrooms.option.wretchedCycleStepTime": "Seconds between increasing of wretched cycle",
"text.autoconfig.backrooms.option.moldyCorkTileChance": "Chance to spawn moldy cork in crimson halls",
"text.autoconfig.backrooms.option.noclipCarpetingSpawnChance": "Chance to spawn a noclip carpeting",
"text.autoconfig.backrooms.option.noclipWallSpawnChance": "Chance to spawn a noclip wallpaper",
"text.autoconfig.backrooms.option.aiDebug": "Enable ai debugging",

"text.autoconfig.backrooms.category.Gameplay": "Gameplay",
Expand Down
Loading

0 comments on commit 166bb77

Please sign in to comment.