Skip to content

Commit

Permalink
Merge pull request #192 from KevinDaGame/feat/blendbrush_correct
Browse files Browse the repository at this point in the history
Restore blendball to original functionality
  • Loading branch information
KevinDaGame authored Jun 12, 2023
2 parents b444a0f + 0539a9e commit 82e233e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ abstract class AbstractBrush : IBrush {
*/
override var name by initOnce<String>()
override var permissionNode: String by initOnce()
protected var snipeAction: SnipeAction? = null
protected lateinit var snipeAction: SnipeAction

private fun preparePerform(v: SnipeData, clickedBlock: IBlock, clickedFace: BlockFace): Boolean {
if (getTarget(v, clickedBlock, clickedFace)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class PolyBrush(
}
}
if (operation != null) {
properties.add(PolyPropertiesEnum.EXCLUDEWATER)
properties.add(PolyPropertiesEnum.EXCLUDEAIR)
properties.addAll(operation.getProperties())

}
for (property in properties) {
Expand Down Expand Up @@ -88,7 +87,7 @@ class PolyBrush(
}
if (operation != null) {
val brushSize = v.brushSize
val newMaterials = operation.apply(brushSize, this, excludeAir, excludeWater)
val newMaterials = operation.apply(brushSize, this, snipeAction, excludeAir, excludeWater)
for (position in positions) {
val material: VoxelMaterial =
newMaterials[position.blockX - targetBlock.x + brushSize][position.blockY - targetBlock.y + brushSize][position.blockZ - targetBlock.z + brushSize]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ package com.github.kevindagame.brush.polymorphic.operation

import com.github.kevindagame.brush.polymorphic.PolyBrush
import com.github.kevindagame.brush.polymorphic.PolyOperationType
import com.github.kevindagame.brush.polymorphic.property.PolyPropertiesEnum
import com.github.kevindagame.snipe.SnipeAction
import com.github.kevindagame.voxelsniper.material.VoxelMaterial

class BlendOperation: PolyOperation(listOf(PolyOperationType.BLOCK)) {
override fun apply(
brushSize: Int,
brush: PolyBrush,
snipeAction: SnipeAction,
excludeAir: Boolean,
excludeWater: Boolean
): Array<Array<Array<VoxelMaterial>>> {
val doExcludeAir = snipeAction == SnipeAction.GUNPOWDER
val targetBlock = brush.targetBlock
val brushSizeDoubled = 2 * brushSize
// Array that holds the original materials plus a buffer
Expand All @@ -32,7 +36,6 @@ class BlendOperation: PolyOperation(listOf(PolyOperationType.BLOCK)) {
}
}
}
//TODO: Validate that this is the correct way to clone the array
//clone oldMaterials into newMaterials
val newMaterials = oldMaterials.clone()

Expand All @@ -58,15 +61,15 @@ class BlendOperation: PolyOperation(listOf(PolyOperationType.BLOCK)) {

// Find most common neighbouring material
for ((key, value) in materialFrequency) {
if (value > highestMaterialCount && !(excludeAir && key!!.isAir) && !(excludeWater && key!!.equals(VoxelMaterial.WATER()))) {
if (value > highestMaterialCount && !(doExcludeAir && key!!.isAir) && !(excludeWater && key!!.equals(VoxelMaterial.WATER()))) {
highestMaterialCount = value
highestMaterial = key
}
}

// Make sure that there's no tie in the highest material
for ((key, value) in materialFrequency) {
if (value == highestMaterialCount && !(excludeAir && key!!.isAir) && !(excludeWater && key!!.equals(VoxelMaterial.WATER()))) {
if (value == highestMaterialCount && !(doExcludeAir && key!!.isAir) && !(excludeWater && key!!.equals(VoxelMaterial.WATER()))) {
if (key!!.equals(highestMaterial)) {
continue
}
Expand All @@ -84,4 +87,8 @@ class BlendOperation: PolyOperation(listOf(PolyOperationType.BLOCK)) {
return newMaterials as Array<Array<Array<VoxelMaterial>>>
}

override fun getProperties(): Collection<PolyPropertiesEnum> {
return listOf(PolyPropertiesEnum.EXCLUDEWATER)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package com.github.kevindagame.brush.polymorphic.operation

import com.github.kevindagame.brush.polymorphic.PolyBrush
import com.github.kevindagame.brush.polymorphic.PolyOperationType
import com.github.kevindagame.brush.polymorphic.property.PolyPropertiesEnum
import com.github.kevindagame.snipe.SnipeAction
import com.github.kevindagame.voxelsniper.material.VoxelMaterial

/**
* Base class for operations such as blending and splatter
*/
abstract class PolyOperation(val supportedOperationTypes: List<PolyOperationType>) {
abstract fun apply(brushSize: Int, brush: PolyBrush, excludeAir: Boolean, excludeWater: Boolean): Array<Array<Array<VoxelMaterial>>>
abstract fun apply(brushSize: Int, brush: PolyBrush, snipeAction: SnipeAction, excludeAir: Boolean, excludeWater: Boolean): Array<Array<Array<VoxelMaterial>>>

abstract fun getProperties(): Collection<PolyPropertiesEnum>
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class PolymorphicBrushTest {
}

@Test
fun operation_brush_should_have_exclude_water_and_exclude_air() {
fun operation_brush_should_have_exclude_water() {
//arrange
val brush = PolyBrush(
"Test",
Expand All @@ -74,11 +74,9 @@ class PolymorphicBrushTest {

//act
val hasExcludeWater = brush.properties.any { it is ExcludeWaterProperty }
val hasExcludeAir = brush.properties.any { it is ExcludeAirProperty }

//assert
assert(hasExcludeWater)
assert(hasExcludeAir)
}

}

0 comments on commit 82e233e

Please sign in to comment.