1
0
mirror of https://github.com/chylex/Hardcore-Ender-Expansion-2.git synced 2025-04-11 03:15:44 +02:00

Refactor structure piece connection definition

This commit is contained in:
chylex 2019-06-07 17:15:06 +02:00
parent e9d50e5cdf
commit 4a22839a10
3 changed files with 12 additions and 11 deletions

View File

@ -3,16 +3,11 @@ import net.minecraft.util.EnumFacing
import net.minecraft.util.math.BlockPos
interface IStructurePieceConnection{
val type: IStructurePieceConnectionType
val offset: BlockPos
val facing: EnumFacing
@JvmDefault
val isEvenWidth
get() = false
/**
* Returns true if the current connection, which is always on a new piece, can be connected to the [target] connection of an already generated piece.
* The relation defined by the method does not have to be symmetric, which allows for one-directional connections.
*/
fun canBeAttachedTo(target: IStructurePieceConnection): Boolean
}

View File

@ -0,0 +1,9 @@
package chylex.hee.game.world.structure.piece
interface IStructurePieceConnectionType{
/**
* Returns true if the current connection, which is always on a new piece, can be connected to the [target] connection of an already generated piece.
* The relation defined by the method does not have to be symmetric, which allows for one-directional connections.
*/
fun canBeAttachedTo(target: IStructurePieceConnectionType): Boolean
}

View File

@ -28,16 +28,13 @@ abstract class StructurePiece : IStructurePiece, IStructureGenerator{
// Rotated connection
private class RotatedStructurePieceConnection(private val original: IStructurePieceConnection, size: Size, rotation: Rotation) : IStructurePieceConnection{
override val type = original.type
override val offset = RotatedStructureWorld.rotatePos(original.offset, size, rotation)
override val facing = rotation.rotate(original.facing)!!
override val isEvenWidth
get() = original.isEvenWidth
override fun canBeAttachedTo(target: IStructurePieceConnection): Boolean{
return original.canBeAttachedTo((target as? RotatedStructurePieceConnection)?.original ?: target)
}
fun matches(other: IStructurePieceConnection): Boolean{
return this === other || original === other
}
@ -63,7 +60,7 @@ abstract class StructurePiece : IStructurePiece, IStructureGenerator{
fun findAvailableConnections(targetConnection: IStructurePieceConnection): List<IStructurePieceConnection>{
val targetFacing = targetConnection.facing.opposite
return availableConnections.filter { it.facing == targetFacing && it.canBeAttachedTo(targetConnection) }
return availableConnections.filter { it.facing == targetFacing && it.type.canBeAttachedTo(targetConnection.type) }
}
fun isConnectionUsed(connection: IStructurePieceConnection): Boolean{