mirror of
https://github.com/Theaninova/new-frontiers.git
synced 2025-12-10 10:36:14 +00:00
Teleportation now works as intended
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package de.wulkanat.www.new_frontiers
|
||||
|
||||
import de.wulkanat.www.new_frontiers.init.Blocks
|
||||
import de.wulkanat.www.new_frontiers.init.Items
|
||||
import de.wulkanat.www.new_frontiers.init.registerBiomes
|
||||
import de.wulkanat.www.new_frontiers.init.registerDimensions
|
||||
import de.wulkanat.www.new_frontiers.init.*
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.client.main.Main
|
||||
import net.minecraft.item.Item
|
||||
@@ -14,22 +11,16 @@ import net.minecraftforge.fml.common.Mod
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent
|
||||
import net.minecraftforge.fml.common.event.FMLServerStartingEvent
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
|
||||
|
||||
@Mod(
|
||||
modid = NewFrontiers.MOD_ID,
|
||||
name = NewFrontiers.MOD_NAME,
|
||||
version = NewFrontiers.VERSION,
|
||||
modid = MOD_ID,
|
||||
name = MOD_NAME,
|
||||
version = VERSION,
|
||||
modLanguageAdapter = "net.shadowfacts.forgelin.KotlinAdapter"
|
||||
)
|
||||
object NewFrontiers {
|
||||
const val MOD_ID = "new_frontiers"
|
||||
const val MOD_NAME = "New Frontiers"
|
||||
const val VERSION = "1.0-SNAPSHOT"
|
||||
|
||||
@Mod.Instance
|
||||
lateinit var instance: Main
|
||||
|
||||
@Mod.EventHandler
|
||||
fun preinit(event: FMLPreInitializationEvent) {
|
||||
// TODO: register world generator
|
||||
@@ -42,6 +33,7 @@ object NewFrontiers {
|
||||
|
||||
@Mod.EventHandler
|
||||
fun init(event: FMLInitializationEvent) {
|
||||
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
@@ -49,6 +41,13 @@ object NewFrontiers {
|
||||
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
fun start(event: FMLServerStartingEvent) {
|
||||
for (command in Commands.values()) {
|
||||
event.registerServerCommand(command.value)
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = MOD_ID)
|
||||
object ObjectRegistryHandler {
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package de.wulkanat.www.new_frontiers
|
||||
|
||||
object StaticValues {
|
||||
|
||||
}
|
||||
const val MOD_ID = "new_frontiers"
|
||||
const val MOD_NAME = "New Frontiers"
|
||||
const val VERSION = "1.0-SNAPSHOT"
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package de.wulkanat.www.new_frontiers.abstract_helpers
|
||||
|
||||
import de.wulkanat.www.new_frontiers.NewFrontiers
|
||||
import de.wulkanat.www.new_frontiers.MOD_ID
|
||||
import de.wulkanat.www.new_frontiers.proxy.registerItemRenderer
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.block.BlockHorizontal
|
||||
import net.minecraft.block.SoundType
|
||||
import net.minecraft.block.material.Material
|
||||
import net.minecraft.block.properties.PropertyDirection
|
||||
@@ -41,7 +40,7 @@ abstract class NFBlock(
|
||||
blockResistance = hardness * 5.0f
|
||||
}
|
||||
|
||||
setRegistryName("${NewFrontiers.MOD_ID}:$name")
|
||||
setRegistryName("${MOD_ID}:$name")
|
||||
this.translationKey = name
|
||||
this.lightValue = lightLevel
|
||||
this.lightOpacity = lightOpacity
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package de.wulkanat.www.new_frontiers.abstract_helpers
|
||||
|
||||
import net.minecraft.command.CommandBase
|
||||
import net.minecraft.command.ICommandSender
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.util.text.ITextComponent
|
||||
import java.awt.Color
|
||||
|
||||
abstract class NFCommand(
|
||||
name: String,
|
||||
usage: String,
|
||||
val action: (ExecuteParams) -> Unit,
|
||||
val hasPermission: (HasPermissionParams) -> Boolean = { true },
|
||||
requiredPermissionLevel: Int = 0
|
||||
) : CommandBase() {
|
||||
private val commandName = name
|
||||
private val commandUsage = "/$name $usage"
|
||||
private val permissionLevel = requiredPermissionLevel
|
||||
|
||||
override fun getName(): String {
|
||||
return commandName
|
||||
}
|
||||
|
||||
override fun getRequiredPermissionLevel(): Int {
|
||||
return permissionLevel
|
||||
}
|
||||
|
||||
override fun execute(server: MinecraftServer, sender: ICommandSender, command: Array<String>) {
|
||||
action(ExecuteParams(server, sender, command))
|
||||
}
|
||||
|
||||
override fun getUsage(p0: ICommandSender): String {
|
||||
return commandUsage
|
||||
}
|
||||
|
||||
override fun checkPermission(server: MinecraftServer, sender: ICommandSender): Boolean {
|
||||
return hasPermission(HasPermissionParams(server, sender))
|
||||
}
|
||||
|
||||
class ExecuteParams(
|
||||
val server: MinecraftServer,
|
||||
val sender: ICommandSender,
|
||||
val command: Array<String>
|
||||
)
|
||||
|
||||
class HasPermissionParams(
|
||||
val server: MinecraftServer,
|
||||
val sender: ICommandSender
|
||||
)
|
||||
|
||||
companion object {
|
||||
fun textLine(text: String, color: String = "white"): ITextComponent {
|
||||
return ITextComponent.Serializer.jsonToComponent("[{\"text\": \"$text\",\"color\":\"$color\"}]") as ITextComponent
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,9 @@
|
||||
package de.wulkanat.www.new_frontiers.abstract_helpers
|
||||
|
||||
import de.wulkanat.www.new_frontiers.NewFrontiers
|
||||
import de.wulkanat.www.new_frontiers.MOD_ID
|
||||
import de.wulkanat.www.new_frontiers.proxy.registerItemRenderer
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.util.ActionResult
|
||||
import net.minecraft.util.EnumHand
|
||||
import net.minecraft.world.World
|
||||
|
||||
abstract class NFItem(
|
||||
name: String,
|
||||
@@ -16,7 +11,7 @@ abstract class NFItem(
|
||||
val hasCustomModel: Boolean = true
|
||||
) : Item() {
|
||||
init {
|
||||
setRegistryName("${NewFrontiers.MOD_ID}:$name")
|
||||
setRegistryName("${MOD_ID}:$name")
|
||||
this.translationKey = name
|
||||
this.creativeTab = creativeTab
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package de.wulkanat.www.new_frontiers.blocks
|
||||
|
||||
import de.wulkanat.www.new_frontiers.abstract_helpers.NFBlock
|
||||
import de.wulkanat.www.new_frontiers.dimensions.teleporter.NFTeleporter
|
||||
import net.minecraft.block.material.Material
|
||||
import net.minecraft.command.CommandBase
|
||||
import net.minecraft.entity.player.EntityPlayerMP
|
||||
|
||||
class BlockSpaceTeleporter : NFBlock(
|
||||
@@ -13,8 +15,7 @@ class BlockSpaceTeleporter : NFBlock(
|
||||
|
||||
onClick = {
|
||||
if (it.player is EntityPlayerMP) {
|
||||
it.player.changeDimension(40000)
|
||||
it.player.setPositionAndUpdate(0.0, 0.0, 0.0)
|
||||
it.player.changeDimension(40000, NFTeleporter(it.player.server.getWorld(40000)))
|
||||
true
|
||||
} else {
|
||||
false
|
||||
|
||||
@@ -11,7 +11,7 @@ class SpaceshipController : NFBlock(
|
||||
facingDirections = BlockHorizontal.FACING,
|
||||
|
||||
onClick = {
|
||||
it.player.openGui(NewFrontiers.instance, 0, it.world, it.pos.x, it.pos.y, it.pos.z)
|
||||
it.player.openGui(NewFrontiers, 0, it.world, it.pos.x, it.pos.y, it.pos.z)
|
||||
true
|
||||
}
|
||||
)
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package de.wulkanat.www.new_frontiers.commands
|
||||
|
||||
import de.wulkanat.www.new_frontiers.abstract_helpers.NFCommand
|
||||
import de.wulkanat.www.new_frontiers.dimensions.teleporter.NFTeleporter
|
||||
import net.minecraft.command.NumberInvalidException
|
||||
import net.minecraft.util.math.MathHelper
|
||||
import java.lang.NullPointerException
|
||||
|
||||
class CommandTPDim : NFCommand(
|
||||
name = "tpdim",
|
||||
usage = "<id> [<x> <y> <z>]",
|
||||
|
||||
action = {
|
||||
when (it.command.size) {
|
||||
1, 4 -> {
|
||||
try {
|
||||
val player = it.sender.commandSenderEntity
|
||||
player?.changeDimension(parseInt(it.command[0]), NFTeleporter(it.server.getWorld(parseInt(it.command[0]))))
|
||||
it.sender.sendMessage(textLine("Teleporting you to dimension ${it.command[0]}"))
|
||||
} catch (e: NumberInvalidException) {
|
||||
it.sender.sendMessage(textLine("Invalid dimension '${it.command[0]}'"))
|
||||
}
|
||||
}
|
||||
else -> it.sender.sendMessage(textLine("<id> [<x> <y> <z>]"))
|
||||
}
|
||||
|
||||
}
|
||||
)
|
||||
@@ -4,16 +4,13 @@ import de.wulkanat.www.new_frontiers.abstract_helpers.NFDimension
|
||||
import net.minecraft.world.biome.Biome
|
||||
import net.minecraft.world.biome.BiomeProviderSingle
|
||||
import net.minecraft.world.gen.ChunkGeneratorOverworld
|
||||
import net.minecraft.world.gen.IChunkGenerator
|
||||
|
||||
class DimensionBody(id: Int, name: String) : NFDimension(
|
||||
class DimensionBody : NFDimension(
|
||||
name = "planetary_body",
|
||||
id = 40001,
|
||||
canRespawn = true,
|
||||
surfaceDimension = true,
|
||||
biomeProvider = BiomeProviderSingle(Biome.getBiomeForId(29) as Biome)
|
||||
) {
|
||||
override fun createChunkGenerator(): IChunkGenerator {
|
||||
return ChunkGeneratorOverworld(this.world, 19203, false, name)
|
||||
}
|
||||
override fun createChunkGenerator() = ChunkGeneratorOverworld(this.world, 19203, false, name)
|
||||
}
|
||||
|
||||
@@ -13,7 +13,5 @@ class DimensionSpace : NFDimension(
|
||||
surfaceDimension = false,
|
||||
biomeProvider = BiomeProviderSingle(Biomes.DEEP_SPACE.value)
|
||||
) {
|
||||
override fun createChunkGenerator(): IChunkGenerator {
|
||||
return VoidChunkGenerator(this.world)
|
||||
}
|
||||
override fun createChunkGenerator() = VoidChunkGenerator(this.world)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package de.wulkanat.www.new_frontiers.dimensions.teleporter
|
||||
|
||||
import net.minecraft.entity.Entity
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.MathHelper
|
||||
import net.minecraft.world.Teleporter
|
||||
import net.minecraft.world.WorldServer
|
||||
|
||||
class NFTeleporter(private val worldInstance: WorldServer) : Teleporter(worldInstance) {
|
||||
override fun placeInPortal(entity: Entity, p5: Float) {
|
||||
val i = MathHelper.floor(entity.posX)
|
||||
val j = MathHelper.floor(entity.posY)
|
||||
val k = MathHelper.floor(entity.posZ)
|
||||
|
||||
// Dummy chunk loading
|
||||
worldInstance.getChunk(BlockPos(i, j, k))
|
||||
val height = worldInstance.getHeight(i, k)
|
||||
entity.setPosition(i.toDouble(), j.toDouble(), k.toDouble())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package de.wulkanat.www.new_frontiers.init
|
||||
|
||||
import de.wulkanat.www.new_frontiers.abstract_helpers.NFCommand
|
||||
import de.wulkanat.www.new_frontiers.commands.CommandTPDim
|
||||
|
||||
enum class Commands(val value: NFCommand) {
|
||||
TP_DIM(CommandTPDim())
|
||||
}
|
||||
@@ -2,10 +2,12 @@ package de.wulkanat.www.new_frontiers.init
|
||||
|
||||
import de.wulkanat.www.new_frontiers.dimensions.DimensionSpace
|
||||
import de.wulkanat.www.new_frontiers.abstract_helpers.NFDimension
|
||||
import de.wulkanat.www.new_frontiers.dimensions.DimensionBody
|
||||
import net.minecraftforge.common.DimensionManager
|
||||
|
||||
enum class DimensionTypes(val value: NFDimension) {
|
||||
SPACE(DimensionSpace());
|
||||
SPACE(DimensionSpace()),
|
||||
PLANET_BODY(DimensionBody())
|
||||
}
|
||||
|
||||
fun registerDimensions() {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package de.wulkanat.www.new_frontiers.proxy
|
||||
|
||||
import jdk.nashorn.internal.ir.Block
|
||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.util.ResourceLocation
|
||||
|
||||
Reference in New Issue
Block a user