-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d437831
commit 68764a2
Showing
8 changed files
with
259 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
common/src/main/kotlin/org/valkyrienskies/mod/common/item/ConnectionCheckerItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package org.valkyrienskies.mod.common.item | ||
|
||
import net.minecraft.Util | ||
import net.minecraft.network.chat.TextComponent | ||
import net.minecraft.server.level.ServerLevel | ||
import net.minecraft.world.InteractionResult | ||
import net.minecraft.world.item.Item | ||
import net.minecraft.world.item.ItemStack | ||
import net.minecraft.world.item.context.UseOnContext | ||
import net.minecraft.world.level.block.state.BlockState | ||
import org.valkyrienskies.mod.common.dimensionId | ||
import org.valkyrienskies.mod.common.getShipManagingPos | ||
import org.valkyrienskies.mod.common.shipObjectWorld | ||
import java.util.function.DoubleSupplier | ||
|
||
class ConnectionCheckerItem( | ||
properties: Properties, private val scale: DoubleSupplier, private val minScaling: DoubleSupplier | ||
) : Item(properties) { | ||
|
||
override fun isFoil(stack: ItemStack): Boolean { | ||
return true | ||
} | ||
|
||
override fun useOn(ctx: UseOnContext): InteractionResult { | ||
val level = ctx.level as? ServerLevel ?: return super.useOn(ctx) | ||
val blockPos = ctx.clickedPos | ||
val blockState: BlockState = level.getBlockState(blockPos) | ||
val item = ctx.itemInHand | ||
|
||
if (item.item !is ConnectionCheckerItem) { | ||
return InteractionResult.FAIL | ||
} | ||
|
||
if (!level.isClientSide) { | ||
val parentShip = ctx.level.getShipManagingPos(blockPos) | ||
if (!blockState.isAir) { | ||
// Make a ship | ||
val dimensionId = level.dimensionId | ||
|
||
if (parentShip != null) { | ||
if (item.tag != null && item.tag!!.contains("firstPosX")) { | ||
val firstPosX = item.tag!!.getInt("firstPosX") | ||
val firstPosY = item.tag!!.getInt("firstPosY") | ||
val firstPosZ = item.tag!!.getInt("firstPosZ") | ||
val connected = level.shipObjectWorld.isConnectedBySolid(blockPos.x, blockPos.y, blockPos.z, firstPosX, firstPosY, firstPosZ, dimensionId) | ||
ctx.player?.sendMessage(TextComponent("Connected: $connected"), Util.NIL_UUID) | ||
item.tag!!.remove("firstPosX") | ||
item.tag!!.remove("firstPosY") | ||
item.tag!!.remove("firstPosZ") | ||
} else { | ||
item.tag = item.orCreateTag.apply { | ||
putInt("firstPosX", blockPos.x) | ||
putInt("firstPosY", blockPos.y) | ||
putInt("firstPosZ", blockPos.z) | ||
} | ||
ctx.player?.sendMessage(TextComponent("First block selected: (${blockPos.x}, ${blockPos.y}, ${blockPos.z}"), Util.NIL_UUID) | ||
} | ||
} | ||
} | ||
} | ||
|
||
return super.useOn(ctx) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
common/src/main/resources/assets/valkyrienskies/models/item/connection_checker.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:item/handheld", | ||
"textures": { | ||
"layer0": "minecraft:item/stick" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters