remove/refactor Directions::getBlock

This commit is contained in:
Moritz Zwerger 2024-01-12 21:20:29 +01:00
parent 44813001a1
commit fbc4e88f8c
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 59 additions and 62 deletions

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -22,10 +22,7 @@ import de.bixilon.kutil.enums.ValuesEnum
import de.bixilon.kutil.reflection.ReflectionUtil.forceSet
import de.bixilon.kutil.reflection.ReflectionUtil.jvmField
import de.bixilon.minosoft.data.Axes
import de.bixilon.minosoft.data.registries.blocks.state.BlockState
import de.bixilon.minosoft.data.world.chunk.ChunkSection
import de.bixilon.minosoft.gui.rendering.util.vec.vec3.Vec3iUtil.get
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
enum class Directions(
val vector: Vec3i,
@ -60,60 +57,6 @@ enum class Directions(
return vector[axis]
}
@Deprecated("outsource")
fun getBlock(x: Int, y: Int, z: Int, section: ChunkSection, neighbours: Array<ChunkSection?>): BlockState? {
return when (this) {
DOWN -> {
if (y == 0) {
neighbours[Directions.O_DOWN]?.blocks?.let { it[x, ProtocolDefinition.SECTION_MAX_Y, z] }
} else {
section.blocks[x, y - 1, z]
}
}
UP -> {
if (y == ProtocolDefinition.SECTION_MAX_Y) {
neighbours[Directions.O_UP]?.blocks?.let { it[x, 0, z] }
} else {
section.blocks[x, y + 1, z]
}
}
NORTH -> {
if (z == 0) {
neighbours[Directions.O_NORTH]?.blocks?.let { it[x, y, ProtocolDefinition.SECTION_MAX_Z] }
} else {
section.blocks[x, y, z - 1]
}
}
SOUTH -> {
if (z == ProtocolDefinition.SECTION_MAX_Z) {
neighbours[Directions.O_SOUTH]?.blocks?.let { it[x, y, 0] }
} else {
section.blocks[x, y, z + 1]
}
}
WEST -> {
if (x == 0) {
neighbours[Directions.O_WEST]?.blocks?.let { it[ProtocolDefinition.SECTION_MAX_X, y, z] }
} else {
section.blocks[x - 1, y, z]
}
}
EAST -> {
if (x == ProtocolDefinition.SECTION_MAX_X) {
neighbours[Directions.O_EAST]?.blocks?.let { it[0, y, z] }
} else {
section.blocks[x + 1, y, z]
}
}
}
}
companion object : ValuesEnum<Directions> {
const val O_DOWN = 0 // Directions.DOWN.ordinal
const val O_UP = 1 // Directions.UP.ordinal

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -14,6 +14,7 @@ package de.bixilon.minosoft.data.world.chunk
import de.bixilon.kotlinglm.vec2.Vec2i
import de.bixilon.kotlinglm.vec3.Vec3i
import de.bixilon.minosoft.data.direction.Directions
import de.bixilon.minosoft.data.entities.block.BlockEntity
import de.bixilon.minosoft.data.world.chunk.chunk.Chunk
import de.bixilon.minosoft.data.world.chunk.light.SectionLight
@ -22,6 +23,7 @@ import de.bixilon.minosoft.data.world.container.biome.BiomeSectionDataProvider
import de.bixilon.minosoft.data.world.container.block.BlockSectionDataProvider
import de.bixilon.minosoft.gui.rendering.util.VecUtil.of
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
import java.util.*
/**
@ -68,6 +70,57 @@ class ChunkSection(
blockEntities.clear()
}
fun traceBlock(x: Int, y: Int, z: Int, direction: Directions) = when (direction) {
Directions.DOWN -> {
if (y == 0) {
neighbours?.get(Directions.O_DOWN)?.blocks?.let { it[x, ProtocolDefinition.SECTION_MAX_Y, z] }
} else {
blocks[x, y - 1, z]
}
}
Directions.UP -> {
if (y == ProtocolDefinition.SECTION_MAX_Y) {
neighbours?.get(Directions.O_UP)?.blocks?.let { it[x, 0, z] }
} else {
blocks[x, y + 1, z]
}
}
Directions.NORTH -> {
if (z == 0) {
neighbours?.get(Directions.O_NORTH)?.blocks?.let { it[x, y, ProtocolDefinition.SECTION_MAX_Z] }
} else {
blocks[x, y, z - 1]
}
}
Directions.SOUTH -> {
if (z == ProtocolDefinition.SECTION_MAX_Z) {
neighbours?.get(Directions.O_SOUTH)?.blocks?.let { it[x, y, 0] }
} else {
blocks[x, y, z + 1]
}
}
Directions.WEST -> {
if (x == 0) {
neighbours?.get(Directions.O_WEST)?.blocks?.let { it[ProtocolDefinition.SECTION_MAX_X, y, z] }
} else {
blocks[x - 1, y, z]
}
}
Directions.EAST -> {
if (x == ProtocolDefinition.SECTION_MAX_X) {
neighbours?.get(Directions.O_EAST)?.blocks?.let { it[0, y, z] }
} else {
blocks[x + 1, y, z]
}
}
}
companion object {
inline val Vec3i.index: Int
get() = getIndex(x, y, z)

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -161,6 +161,7 @@ class ChunkNeighbours(val chunk: Chunk) : Iterable<Chunk?> {
return trace(chunkOffset)?.get(x, y, z)
}
companion object {
const val COUNT = 8
const val NORTH = 3

View File

@ -1,6 +1,6 @@
/*
* Minosoft
* Copyright (C) 2020-2023 Moritz Zwerger
* Copyright (C) 2020-2024 Moritz Zwerger
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
@ -87,7 +87,7 @@ class FluidSectionMesher(
val height = fluid.getHeight(state)
fun isSideCovered(direction: Directions): Boolean {
val neighbour = direction.getBlock(x, y, z, section, neighbours) ?: return false
val neighbour = section.traceBlock(x, y, z, direction) ?: return false
if (fluid.matches(neighbour)) {
return true