Skip to content

Commit

Permalink
🎨 clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
PriestOfFerns committed Mar 13, 2024
1 parent 27f00f2 commit 6121b38
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.priestoffern.vs_ship_assembler.items

import de.m_marvin.univec.impl.Vec3d
import io.github.priestoffern.vs_ship_assembler.VsShipAssemblerTags
import io.github.priestoffern.vs_ship_assembler.rendering.Renderer
import io.github.priestoffern.vs_ship_assembler.rendering.RenderingData
import io.github.priestoffern.vs_ship_assembler.rendering.SelectionZoneRenderer
Expand Down Expand Up @@ -105,18 +104,17 @@ class ShipAssemblerItem(properties: Properties): Item(properties) {
for (y in min(firstPosition!!.y, secondPosition!!.y)..max(firstPosition!!.y, secondPosition!!.y)) {
for (z in min(firstPosition!!.z, secondPosition!!.z)..max(firstPosition!!.z, secondPosition!!.z)) {

if (!level.getBlockState(BlockPos(x,y,z)).tags.anyMatch { it==VsShipAssemblerTags.FORBIDDEN_ASSEMBLE })
//if (!level.getBlockState(BlockPos(x,y,z)).tags.anyMatch { it==VsShipAssemblerTags.FORBIDDEN_ASSEMBLE })
add(BlockPos(x,y,z))
}
}
}
}

if (set.size>0) {
PhysicUtility.assembleToContraption(level,set,true,1.0)
if (PhysicUtility.assembleToContraption(level,set,true,1.0)) {
player.sendMessage(TextComponent("Assembled!").withStyle(ChatFormatting.BOLD), Util.NIL_UUID)
} else {
player.sendMessage(TextComponent("Failed to Assemble: Empty ship").withStyle(ChatFormatting.RED), Util.NIL_UUID)
player.sendMessage(TextComponent("Failed to Assemble").withStyle(ChatFormatting.RED), Util.NIL_UUID)
}

if (SelectionZone!=null) Renderer.removeRender(SelectionZone!!)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.priestoffern.vs_ship_assembler.util

import de.m_marvin.unimat.impl.Quaterniond
import de.m_marvin.univec.impl.Vec3d
import io.github.priestoffern.vs_ship_assembler.VsShipAssemblerTags
import io.github.priestoffern.vs_ship_assembler.util.GeneralUtility.toBlockPos
import net.minecraft.core.BlockPos
import net.minecraft.server.level.ServerLevel
Expand Down Expand Up @@ -54,6 +55,9 @@ object PhysicUtility {
}

fun isSolidContraptionBlock(state: BlockState?): Boolean {
if (state != null) {
return !state.tags.anyMatch { it== VsShipAssemblerTags.FORBIDDEN_ASSEMBLE }
}
return true
}

Expand Down Expand Up @@ -117,10 +121,12 @@ object PhysicUtility {
// Copy blocks and check if the center block got replaced (is default a stone block)
var centerBlockReplaced = false
for (itPos in blocks) {
val relative: BlockPos = itPos.subtract(toBlockPos(contraptionWorldPos))
val shipPos: BlockPos = contraptionBlockPos.offset(relative)
GeneralUtility.copyBlock(level, itPos, shipPos)
if (relative == BlockPos.ZERO) centerBlockReplaced = true
if (isSolidContraptionBlock(level.getBlockState(itPos))) {
val relative: BlockPos = itPos.subtract(toBlockPos(contraptionWorldPos))
val shipPos: BlockPos = contraptionBlockPos.offset(relative)
GeneralUtility.copyBlock(level, itPos, shipPos)
if (relative == BlockPos.ZERO) centerBlockReplaced = true
}
}

// If center block got not replaced, remove the stone block
Expand All @@ -131,7 +137,9 @@ object PhysicUtility {
// Remove original blocks
if (removeOriginal) {
for (itPos in blocks) {
GeneralUtility.removeBlock(level, itPos)
if (isSolidContraptionBlock(level.getBlockState(itPos))) {
GeneralUtility.removeBlock(level, itPos)
}
}
}

Expand Down

0 comments on commit 6121b38

Please sign in to comment.