Skip to content

Commit

Permalink
Basic command to create portals
Browse files Browse the repository at this point in the history
  • Loading branch information
Unreal852 committed Jul 28, 2024
1 parent d30c484 commit f7401d8
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 39 deletions.
7 changes: 6 additions & 1 deletion src/main/java/fr/unreal852/quantum/QuantumManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ package fr.unreal852.quantum
import fr.unreal852.quantum.utils.Extensions.getWorldByIdentifier
import fr.unreal852.quantum.world.QuantumWorld
import fr.unreal852.quantum.world.QuantumWorldData
import fr.unreal852.quantum.world.states.QuantumPersistentState
import fr.unreal852.quantum.world.state.QuantumPersistentState
import net.kyrptonaught.customportalapi.api.CustomPortalBuilder
import net.minecraft.server.MinecraftServer
import net.minecraft.util.Identifier
import net.minecraft.world.GameRules
Expand Down Expand Up @@ -89,6 +90,10 @@ object QuantumManager {
}
}

fun createPortal() {
CustomPortalBuilder.beginPortal()
}

// Old Portal code. =====================================
// public static PortalLink createPortal(MinecraftServer server, QuantumWorldPortalConfig portalConfig, boolean saveToDisk) {
// class_1792 item = (class_1792)class_2378.field_11142.method_10223(portalConfig.getPortalIgniteItemId());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package fr.unreal852.quantum.callback

import fr.unreal852.quantum.world.states.QuantumWorldPersistentState
import fr.unreal852.quantum.world.state.QuantumWorldPersistentState
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents.AfterRespawn
import net.minecraft.network.packet.s2c.play.PlayerPositionLookS2CPacket
import net.minecraft.network.packet.s2c.play.PositionFlag
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ object CommandRegistration {
TeleportToWorldCommand.register(dispatcher)
SetWorldSpawnCommand.register(dispatcher)
SetTeleportSignCommand.register(dispatcher)

CreatePortalCommand.register(dispatcher)
})
}
}
65 changes: 65 additions & 0 deletions src/main/java/fr/unreal852/quantum/command/CreatePortalCommand.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package fr.unreal852.quantum.command

import com.mojang.brigadier.Command
import com.mojang.brigadier.CommandDispatcher
import com.mojang.brigadier.context.CommandContext
import fr.unreal852.quantum.Quantum
import fr.unreal852.quantum.command.suggestion.BlocksSuggestionProvider
import fr.unreal852.quantum.command.suggestion.WorldsDimensionSuggestionProvider
import net.kyrptonaught.customportalapi.api.CustomPortalBuilder
import net.minecraft.command.argument.DimensionArgumentType
import net.minecraft.command.argument.IdentifierArgumentType
import net.minecraft.item.Items
import net.minecraft.server.command.CommandManager
import net.minecraft.server.command.ServerCommandSource

class CreatePortalCommand : Command<ServerCommandSource> {
override fun run(context: CommandContext<ServerCommandSource>): Int {

if (context.source == null)
return 0

try {

val portalBlock = IdentifierArgumentType.getIdentifier(context, PORTAL_BLOCK_ARG)
val destinationWorld = IdentifierArgumentType.getIdentifier(context, PORTAL_DESTINATION_ARG)

CustomPortalBuilder.beginPortal()
.frameBlock(portalBlock)
.lightWithItem(Items.DIAMOND)
.destDimID(destinationWorld)
.tintColor(255, 0, 0)
.registerPortal()

} catch (e: Exception) {
Quantum.LOGGER.error("An error occurred while creating the world.", e)
}

return 1
}

companion object {

private const val PORTAL_BLOCK_ARG = "portalFrameBlock"
private const val PORTAL_DESTINATION_ARG = "destinationWorld"

fun register(dispatcher: CommandDispatcher<ServerCommandSource>) {
dispatcher.register(CommandManager.literal("qt")
.then(CommandManager.literal("createportal")
.requires { commandSource: ServerCommandSource -> commandSource.hasPermissionLevel(4) }
.then(
CommandManager.argument(PORTAL_BLOCK_ARG, IdentifierArgumentType.identifier())
.suggests(BlocksSuggestionProvider())
.executes(CreatePortalCommand())
.then(
CommandManager.argument(PORTAL_DESTINATION_ARG, DimensionArgumentType.dimension())
.suggests(WorldsDimensionSuggestionProvider())
.executes(CreatePortalCommand())
)
)
)
)
}
}
}

29 changes: 29 additions & 0 deletions src/main/java/fr/unreal852/quantum/portal/QuantumPortalData.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package fr.unreal852.quantum.portal

import net.minecraft.util.Identifier

class QuantumPortalData {

val isEnabled: Boolean = true

lateinit var destinationId: Identifier
private set

lateinit var portalBlockId: Identifier
private set

lateinit var portalIgniteItemId: Identifier
private set

var portalColor: Int = 0
private set

constructor()

constructor(destId: Identifier, portalBlockId: Identifier, portalIgniteItemId: Identifier, color: Int) {
this.destinationId = destId
this.portalBlockId = portalBlockId
this.portalIgniteItemId = portalIgniteItemId
this.portalColor = color
}
}
2 changes: 1 addition & 1 deletion src/main/java/fr/unreal852/quantum/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package fr.unreal852.quantum.utils

import fr.unreal852.quantum.world.states.QuantumWorldPersistentState
import fr.unreal852.quantum.world.state.QuantumWorldPersistentState
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.nbt.NbtCompound
import net.minecraft.registry.RegistryKey
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.unreal852.quantum.world.states
package fr.unreal852.quantum.world.state

import fr.unreal852.quantum.Quantum
import fr.unreal852.quantum.world.QuantumWorldData
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package fr.unreal852.quantum.world.states
package fr.unreal852.quantum.world.state

import fr.unreal852.quantum.Quantum
import net.minecraft.nbt.NbtCompound
Expand Down

0 comments on commit f7401d8

Please sign in to comment.