From 124b47fec416ead78c36271a39499c00156b61ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thea=20Sch=C3=B6bl?= Date: Mon, 23 Mar 2020 02:48:41 +0100 Subject: [PATCH] Space Teleporter can teleport now. --- .../www/new_frontiers/NewFrontiers.kt | 4 ++ .../new_frontiers/abstract_helpers/NFBiome.kt | 55 ++++++++++++++++++- .../new_frontiers/abstract_helpers/NFBlock.kt | 34 ++++++++++-- .../abstract_helpers/NFStatefulBlock.kt | 4 ++ .../blocks/BlockSpaceTeleporter.kt | 2 +- .../blocks/SpaceshipController.kt | 17 ++++++ .../new_frontiers/dimensions/DimensionBody.kt | 19 +++++++ .../dimensions/DimensionSpace.kt | 2 +- .../www/new_frontiers/init/block_init.kt | 4 +- .../models/block/spaceship_controller.json | 6 ++ .../models/item/spaceship_controller.json | 3 + 11 files changed, 140 insertions(+), 10 deletions(-) create mode 100644 src/main/kotlin/de/wulkanat/www/new_frontiers/abstract_helpers/NFStatefulBlock.kt create mode 100644 src/main/kotlin/de/wulkanat/www/new_frontiers/blocks/SpaceshipController.kt create mode 100644 src/main/kotlin/de/wulkanat/www/new_frontiers/dimensions/DimensionBody.kt create mode 100644 src/main/resources/assets/new_frontiers/models/block/spaceship_controller.json create mode 100644 src/main/resources/assets/new_frontiers/models/item/spaceship_controller.json diff --git a/src/main/kotlin/de/wulkanat/www/new_frontiers/NewFrontiers.kt b/src/main/kotlin/de/wulkanat/www/new_frontiers/NewFrontiers.kt index c5e4044..7815330 100644 --- a/src/main/kotlin/de/wulkanat/www/new_frontiers/NewFrontiers.kt +++ b/src/main/kotlin/de/wulkanat/www/new_frontiers/NewFrontiers.kt @@ -5,6 +5,7 @@ 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 net.minecraft.block.Block +import net.minecraft.client.main.Main import net.minecraft.item.Item import net.minecraft.item.ItemBlock import net.minecraftforge.client.event.ModelRegistryEvent @@ -26,6 +27,9 @@ object NewFrontiers { 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 diff --git a/src/main/kotlin/de/wulkanat/www/new_frontiers/abstract_helpers/NFBiome.kt b/src/main/kotlin/de/wulkanat/www/new_frontiers/abstract_helpers/NFBiome.kt index 1a9a060..602ca11 100644 --- a/src/main/kotlin/de/wulkanat/www/new_frontiers/abstract_helpers/NFBiome.kt +++ b/src/main/kotlin/de/wulkanat/www/new_frontiers/abstract_helpers/NFBiome.kt @@ -1,9 +1,15 @@ package de.wulkanat.www.new_frontiers.abstract_helpers import net.minecraft.block.state.IBlockState +import net.minecraft.util.math.BlockPos +import net.minecraft.world.World import net.minecraft.world.biome.Biome +import net.minecraft.world.chunk.ChunkPrimer import net.minecraftforge.common.BiomeDictionary import net.minecraftforge.common.BiomeManager +import net.minecraftforge.fml.relauncher.Side +import net.minecraftforge.fml.relauncher.SideOnly +import java.util.* abstract class NFBiome( val name: String, @@ -21,7 +27,13 @@ abstract class NFBiome( spawnableCaveCreatureList: List = arrayListOf(), spawnableCreatureList: List = arrayListOf(), spawnableMonsterList: List = arrayListOf(), - spawnableWaterCreatureList: List = arrayListOf() + spawnableWaterCreatureList: List = arrayListOf(), + + val decorate: (decorateParams: DecorateParams) -> Unit = {}, + val genTerrainBlocks: (genTerrainBlocksParams: GenTerrainBlocksParams) -> Unit = {}, + val skyColorByTemp: (currentTemperature: Float) -> Int = { 0x000000 }, + val grassColorAtPos: (pos: BlockPos) -> Int = { 0x000000 }, + val foliageColorAtPos: (pos: BlockPos) -> Int = { 0x000000 } ) : Biome(setRainAndSnow(BiomeProperties(name) .setBaseHeight(baseHeight) .setHeightVariation(heightVariation) @@ -36,8 +48,6 @@ abstract class NFBiome( this.spawnableCreatureList = spawnableCreatureList this.spawnableMonsterList = spawnableMonsterList this.spawnableWaterCreatureList = spawnableWaterCreatureList - - // TODO: decorator } companion object { @@ -50,4 +60,43 @@ abstract class NFBiome( return properties } } + + override fun decorate(world: World, rand: Random, pos: BlockPos) { + decorate(DecorateParams(world, rand, pos, this)) + } + + override fun genTerrainBlocks(world: World, rand: Random, chunkPrimer: ChunkPrimer, x: Int, z: Int, noiseVal: Double) { + genTerrainBlocks(GenTerrainBlocksParams(world, rand, chunkPrimer, x, z, noiseVal)) + } + + @SideOnly(Side.CLIENT) + override fun getSkyColorByTemp(temp: Float): Int { + return skyColorByTemp(temp) + } + + @SideOnly(Side.CLIENT) + override fun getGrassColorAtPos(pos: BlockPos): Int { + return grassColorAtPos(pos) + } + + @SideOnly(Side.CLIENT) + override fun getFoliageColorAtPos(pos: BlockPos): Int { + return foliageColorAtPos(pos) + } + + class GenTerrainBlocksParams( + val world: World, + val rand: Random, + val chunkPrimer: ChunkPrimer, + val x: Int, + val z: Int, + val noiseVal: Double + ) + + class DecorateParams( + val world: World, + val rand: Random, + val pos: BlockPos, + val biomeInstance: NFBiome + ) } diff --git a/src/main/kotlin/de/wulkanat/www/new_frontiers/abstract_helpers/NFBlock.kt b/src/main/kotlin/de/wulkanat/www/new_frontiers/abstract_helpers/NFBlock.kt index 1a46b1a..f983cba 100644 --- a/src/main/kotlin/de/wulkanat/www/new_frontiers/abstract_helpers/NFBlock.kt +++ b/src/main/kotlin/de/wulkanat/www/new_frontiers/abstract_helpers/NFBlock.kt @@ -3,7 +3,10 @@ package de.wulkanat.www.new_frontiers.abstract_helpers import de.wulkanat.www.new_frontiers.NewFrontiers 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 import net.minecraft.block.state.IBlockState import net.minecraft.creativetab.CreativeTabs import net.minecraft.entity.player.EntityPlayer @@ -19,14 +22,16 @@ abstract class NFBlock( val tickRate: Int = 10, val hasCustomModel: Boolean = true, val onClick: (ClickParameters) -> Boolean = { false }, + val facingDirections: PropertyDirection? = null, material: Material, hardness: Float = 1.0F, resistance: Float = 1.0F, lightLevel: Int = 0, lightOpacity: Int = 0, + soundType: SoundType = SoundType.METAL, name: String, creativeTab: CreativeTabs = de.wulkanat.www.new_frontiers.init.CreativeTabs.NF_BLOCKS.value - ) : Block(material) { +) : Block(material) { init { // The Java code is a lot of hot garbage, so most of this is copied from the setter functions blockResistance = resistance * 3.0f @@ -41,6 +46,27 @@ abstract class NFBlock( this.lightValue = lightLevel this.lightOpacity = lightOpacity this.creativeTab = creativeTab + + this.blockSoundType = soundType + } + + override fun onBlockAdded(world: World, pos: BlockPos, state: IBlockState) { + if (this.facingDirections != null && !world.isRemote) { + val north = world.getBlockState(pos.north()) + val south = world.getBlockState(pos.south()) + val west = world.getBlockState(pos.west()) + val east = world.getBlockState(pos.east()) + var face = state.getValue(facingDirections) as EnumFacing + + when { + face == EnumFacing.NORTH && north.isFullBlock && south.isFullBlock -> face = EnumFacing.SOUTH + face == EnumFacing.SOUTH && north.isFullBlock && south.isFullBlock -> face = EnumFacing.NORTH + face == EnumFacing.EAST && west.isFullBlock && east.isFullBlock -> face = EnumFacing.WEST + face == EnumFacing.WEST && west.isFullBlock && east.isFullBlock -> face = EnumFacing.EAST + } + + world.setBlockState(pos, state.withProperty(facingDirections, face), 2) + } } override fun isCollidable(): Boolean { @@ -51,10 +77,10 @@ abstract class NFBlock( return tickRate } - override fun onBlockActivated(world: World, pos: BlockPos, state: IBlockState, playerIn: EntityPlayer, hand: EnumHand, sode: EnumFacing, x: Float, y: Float, z: Float): Boolean { + override fun onBlockActivated(world: World, pos: BlockPos, state: IBlockState, player: EntityPlayer, hand: EnumHand, face: EnumFacing, x: Float, y: Float, z: Float): Boolean { if (world.isRemote) return true - return onClick(ClickParameters(world, pos, state, playerIn, hand, sode, x, y, z)) + return onClick(ClickParameters(world, pos, state, player, hand, face, x, y, z)) } fun registerModels() { @@ -67,7 +93,7 @@ abstract class NFBlock( val state: IBlockState, val player: EntityPlayer, val hand: EnumHand, - val sode: EnumFacing, + val face: EnumFacing, val x: Float, val y: Float, val z: Float diff --git a/src/main/kotlin/de/wulkanat/www/new_frontiers/abstract_helpers/NFStatefulBlock.kt b/src/main/kotlin/de/wulkanat/www/new_frontiers/abstract_helpers/NFStatefulBlock.kt new file mode 100644 index 0000000..6d963f3 --- /dev/null +++ b/src/main/kotlin/de/wulkanat/www/new_frontiers/abstract_helpers/NFStatefulBlock.kt @@ -0,0 +1,4 @@ +package de.wulkanat.www.new_frontiers.abstract_helpers + +interface NFStatefulBlock { +} diff --git a/src/main/kotlin/de/wulkanat/www/new_frontiers/blocks/BlockSpaceTeleporter.kt b/src/main/kotlin/de/wulkanat/www/new_frontiers/blocks/BlockSpaceTeleporter.kt index a2f68fd..49ec57f 100644 --- a/src/main/kotlin/de/wulkanat/www/new_frontiers/blocks/BlockSpaceTeleporter.kt +++ b/src/main/kotlin/de/wulkanat/www/new_frontiers/blocks/BlockSpaceTeleporter.kt @@ -13,7 +13,7 @@ class BlockSpaceTeleporter : NFBlock( onClick = { if (it.player is EntityPlayerMP) { - it.player.changeDimension(2) + it.player.changeDimension(40000) it.player.setPositionAndUpdate(0.0, 0.0, 0.0) true } else { diff --git a/src/main/kotlin/de/wulkanat/www/new_frontiers/blocks/SpaceshipController.kt b/src/main/kotlin/de/wulkanat/www/new_frontiers/blocks/SpaceshipController.kt new file mode 100644 index 0000000..cb09cba --- /dev/null +++ b/src/main/kotlin/de/wulkanat/www/new_frontiers/blocks/SpaceshipController.kt @@ -0,0 +1,17 @@ +package de.wulkanat.www.new_frontiers.blocks + +import de.wulkanat.www.new_frontiers.NewFrontiers +import de.wulkanat.www.new_frontiers.abstract_helpers.NFBlock +import net.minecraft.block.BlockHorizontal +import net.minecraft.block.material.Material + +class SpaceshipController : NFBlock( + name = "spaceship_controller", + material = Material.GROUND, + facingDirections = BlockHorizontal.FACING, + + onClick = { + it.player.openGui(NewFrontiers.instance, 0, it.world, it.pos.x, it.pos.y, it.pos.z) + true + } +) diff --git a/src/main/kotlin/de/wulkanat/www/new_frontiers/dimensions/DimensionBody.kt b/src/main/kotlin/de/wulkanat/www/new_frontiers/dimensions/DimensionBody.kt new file mode 100644 index 0000000..d52bf2e --- /dev/null +++ b/src/main/kotlin/de/wulkanat/www/new_frontiers/dimensions/DimensionBody.kt @@ -0,0 +1,19 @@ +package de.wulkanat.www.new_frontiers.dimensions + +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( + 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) + } +} diff --git a/src/main/kotlin/de/wulkanat/www/new_frontiers/dimensions/DimensionSpace.kt b/src/main/kotlin/de/wulkanat/www/new_frontiers/dimensions/DimensionSpace.kt index a859b0f..af5ecf2 100644 --- a/src/main/kotlin/de/wulkanat/www/new_frontiers/dimensions/DimensionSpace.kt +++ b/src/main/kotlin/de/wulkanat/www/new_frontiers/dimensions/DimensionSpace.kt @@ -8,7 +8,7 @@ import net.minecraft.world.gen.IChunkGenerator class DimensionSpace : NFDimension( name = "space", - id = 2, + id = 40000, canRespawn = true, surfaceDimension = false, biomeProvider = BiomeProviderSingle(Biomes.DEEP_SPACE.value) diff --git a/src/main/kotlin/de/wulkanat/www/new_frontiers/init/block_init.kt b/src/main/kotlin/de/wulkanat/www/new_frontiers/init/block_init.kt index 859619d..7a822de 100644 --- a/src/main/kotlin/de/wulkanat/www/new_frontiers/init/block_init.kt +++ b/src/main/kotlin/de/wulkanat/www/new_frontiers/init/block_init.kt @@ -3,8 +3,10 @@ package de.wulkanat.www.new_frontiers.init import de.wulkanat.www.new_frontiers.blocks.BlockFTLDrive import de.wulkanat.www.new_frontiers.abstract_helpers.NFBlock import de.wulkanat.www.new_frontiers.blocks.BlockSpaceTeleporter +import de.wulkanat.www.new_frontiers.blocks.SpaceshipController enum class Blocks(val value: NFBlock) { SPACE_TELEPORTER(BlockSpaceTeleporter()), - FTL_DRIVE(BlockFTLDrive()); + FTL_DRIVE(BlockFTLDrive()), + SPACESHIP_CONTROLLER(SpaceshipController()) } diff --git a/src/main/resources/assets/new_frontiers/models/block/spaceship_controller.json b/src/main/resources/assets/new_frontiers/models/block/spaceship_controller.json new file mode 100644 index 0000000..79c5ee9 --- /dev/null +++ b/src/main/resources/assets/new_frontiers/models/block/spaceship_controller.json @@ -0,0 +1,6 @@ +{ + "parent": "minecraft:block/cube_all", + "textures": { + "all": "new_frontiers:blocks/space_teleporter" + } +} diff --git a/src/main/resources/assets/new_frontiers/models/item/spaceship_controller.json b/src/main/resources/assets/new_frontiers/models/item/spaceship_controller.json new file mode 100644 index 0000000..bb22fcf --- /dev/null +++ b/src/main/resources/assets/new_frontiers/models/item/spaceship_controller.json @@ -0,0 +1,3 @@ +{ + "parent": "new_frontiers:block/spaceship_controller" +}