Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-s168 authored Jan 14, 2024
2 parents c92300a + 9607294 commit 39ff010
Show file tree
Hide file tree
Showing 33 changed files with 780 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import org.valkyrienskies.tournament.registry.RegistrySupplier
object TournamentBlockEntities {
private val BLOCKENTITIES = DeferredRegister.create(TournamentMod.MOD_ID, Registry.BLOCK_ENTITY_TYPE_REGISTRY)

val SENSOR = TournamentBlocks.SENSOR withBE ::SensorBlockEntity byName "sensor"
val ROPE_HOOK = TournamentBlocks.ROPE_HOOK withBE ::RopeHookBlockEntity byName "rope_hook"
val SENSOR = TournamentBlocks.SENSOR withBE ::SensorBlockEntity byName "sensor"
val ROPE_HOOK = TournamentBlocks.ROPE_HOOK withBE ::RopeHookBlockEntity byName "rope_hook"
val PROPELLER = TournamentBlocks.PROP_BIG withBE ::PropellerBlockEntity byName "propeller"

// explosives:
val EXPLOSIVE = TournamentBlocks.EXPLOSIVE_INSTANT_SMALL withBE ::ExplosiveBlockEntity byName "explosive_instant_small"
val EXPLOSIVE = TournamentBlocks.EXPLOSIVE_INSTANT_SMALL withBE ::ExplosiveBlockEntity byName "explosive_instant_small"
val EXPLOSIVE_M = TournamentBlocks.EXPLOSIVE_INSTANT_MEDIUM withBE ::ExplosiveBlockEntity byName "explosive_instant_medium"
val EXPLOSIVE_L = TournamentBlocks.EXPLOSIVE_INSTANT_LARGE withBE ::ExplosiveBlockEntity byName "explosive_instant_large"
val EXPLOSIVE_STAGED_S = TournamentBlocks.EXPLOSIVE_STAGED_SMALL withBE ::ExplosiveBlockEntity byName "explosive_staged_small"
val EXPLOSIVE_L = TournamentBlocks.EXPLOSIVE_INSTANT_LARGE withBE ::ExplosiveBlockEntity byName "explosive_instant_large"
val EXPLOSIVE_STAGED_S = TournamentBlocks.EXPLOSIVE_STAGED_SMALL withBE ::ExplosiveBlockEntity byName "explosive_staged_small"

fun register() {
BLOCKENTITIES.applyAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,12 @@ import net.minecraft.core.BlockPos
import net.minecraft.core.Registry
import net.minecraft.core.particles.ParticleTypes
import net.minecraft.server.level.ServerLevel
import net.minecraft.util.valueproviders.UniformInt
import net.minecraft.world.item.BlockItem
import net.minecraft.world.item.CreativeModeTab
import net.minecraft.world.item.Item
import net.minecraft.world.item.Items
import net.minecraft.world.level.Explosion
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.Blocks
import net.minecraft.world.level.block.FireBlock
import net.minecraft.world.level.block.OreBlock
import net.minecraft.world.level.block.*
import net.minecraft.world.level.block.state.BlockBehaviour
import net.minecraft.world.level.material.Material
import org.valkyrienskies.mod.common.hooks.VSGameEvents
import org.valkyrienskies.tournament.util.extension.explodeShip
import org.valkyrienskies.tournament.blocks.*
Expand All @@ -35,12 +29,14 @@ object TournamentBlocks {
lateinit var BALLAST : RegistrySupplier<BallastBlock>
lateinit var POWERED_BALLOON : RegistrySupplier<BalloonBlock>
lateinit var BALLOON : RegistrySupplier<BalloonBlock>
lateinit var FLOATER : RegistrySupplier<Block>
lateinit var THRUSTER : RegistrySupplier<ThrusterBlock>
lateinit var THRUSTER_TINY : RegistrySupplier<ThrusterBlock>
lateinit var SPINNER : RegistrySupplier<SpinnerBlock>
lateinit var SEAT : RegistrySupplier<SeatBlock>
lateinit var ROPE_HOOK : RegistrySupplier<RopeHookBlock>
lateinit var SENSOR : RegistrySupplier<SensorBlock>
lateinit var PROP_BIG : RegistrySupplier<PropellerBlock>

lateinit var EXPLOSIVE_INSTANT_SMALL : RegistrySupplier<AbstractExplosiveBlock>
lateinit var EXPLOSIVE_INSTANT_MEDIUM : RegistrySupplier<AbstractExplosiveBlock>
Expand All @@ -50,25 +46,44 @@ object TournamentBlocks {

lateinit var EXPLOSIVE_TEST : RegistrySupplier<TestExplosiveBlock>


fun register() {
SHIP_ASSEMBLER = register("ship_assembler", ::ShipAssemblerBlock)
BALLAST = register("ballast", ::BallastBlock)
POWERED_BALLOON = register("balloon", ::PoweredBalloonBlock)
BALLOON = register("balloon_unpowered", ::BalloonBlock)
THRUSTER = register("thruster") { ThrusterBlock(
1.0,
ParticleTypes.CAMPFIRE_SIGNAL_SMOKE,
5
FLOATER = register("floater") { Block(
BlockBehaviour.Properties.of(Material.WOOD)
.sound(SoundType.WOOD)
.strength(1.0f, 2.0f)
)}
THRUSTER_TINY = register("tiny_thruster") { ThrusterBlock(
0.2,
ParticleTypes.CAMPFIRE_COSY_SMOKE,
3
) }
THRUSTER = register("thruster") {
ThrusterBlock(
{ 1.0 },
ParticleTypes.CAMPFIRE_SIGNAL_SMOKE
) {
val t = TournamentConfig.SERVER.thrusterTiersNormal
if (t !in 1..5) {
throw IllegalStateException("Thruster tier must be in range 1..5")
}
t
}
}
THRUSTER_TINY = register("tiny_thruster") {
ThrusterBlock(
{ TournamentConfig.SERVER.thrusterTinyForceMultiplier },
ParticleTypes.CAMPFIRE_COSY_SMOKE
) {
val t = TournamentConfig.SERVER.thrusterTiersTiny
if (t !in 1..5) {
throw IllegalStateException("Thruster tier must be in range 1..5")
}
t
}
}
SPINNER = register("spinner", ::SpinnerBlock)
SEAT = register("seat", ::SeatBlock)
SENSOR = register("sensor", ::SensorBlock)
PROP_BIG = register("prop_big", ::PropellerBlock)

EXPLOSIVE_INSTANT_SMALL = register("explosive_instant_small") { object : AbstractExplosiveBlock() {
override fun explode(level: ServerLevel, pos: BlockPos) {
Expand Down Expand Up @@ -147,6 +162,8 @@ object TournamentBlocks {
fun makeFlammables() {
flammableBlock(SEAT.get(), 15, 25)
flammableBlock(POWERED_BALLOON.get(), 30, 60)
flammableBlock(BALLOON.get(), 30, 60)
flammableBlock(FLOATER.get(), 30, 60)
}

fun registerItems(items: DeferredRegister<Item>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@ object TournamentConfig {
@JsonSchema(description = "Base height of a balloon")
var balloonBaseHeight = 100.0

@JsonSchema(description = "The force a thruster applies to a ship")
@JsonSchema(description = "The force a thruster applies to a ship * tier")
var thrusterSpeed = 10000.0

@JsonSchema(description = "The maximum amount of tiers a normal thruster can have (1-255)")
var thrusterTiersNormal = 4

@JsonSchema(description = "The maximum amount of tiers a normal thruster can have (1-255)")
var thrusterTiersTiny = 2

@JsonSchema(description = "The force multiplier of a tiny thruster")
var thrusterTinyForceMultiplier = 0.2

@JsonSchema(description = "The speed at which the thruster will stop applying force. (-1 means that it always applies force)")
var thrusterShutoffSpeed = 80.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package org.valkyrienskies.tournament

import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.entity.BlockEntityType
import org.valkyrienskies.core.api.ships.getAttachment
import org.valkyrienskies.core.api.ships.saveAttachment
import org.valkyrienskies.core.impl.config.VSConfigClass
import org.valkyrienskies.core.impl.hooks.VSEvents
import org.valkyrienskies.tournament.blockentity.render.PropellerBlockEntityRender
import org.valkyrienskies.tournament.ship.*
import org.valkyrienskies.tournament.util.extension.with

Expand Down Expand Up @@ -57,12 +61,23 @@ object TournamentMod {
}
}
}
}

@JvmStatic
fun initClient() {

}

interface ClientRenderers {
fun <T: BlockEntity> registerBlockEntityRenderer(t: BlockEntityType<T>, r: BlockEntityRendererProvider<T>)
}

@JvmStatic
fun initClient() {
fun initClientRenderers(clientRenderers: ClientRenderers) {
fun <T: BlockEntity> renderer(be: BlockEntityType<T>, renderer: BlockEntityRendererProvider<T>) {
clientRenderers.registerBlockEntityRenderer(be, renderer)
}

renderer(TournamentBlockEntities.PROPELLER.get()) { PropellerBlockEntityRender() }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.valkyrienskies.tournament

import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.MultiBufferSource
import net.minecraft.client.renderer.RenderType
import net.minecraft.client.resources.model.BakedModel
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.level.block.entity.BlockEntity
import org.valkyrienskies.tournament.services.TournamentPlatformHelper

object TournamentModels {

private fun getModel(rl: ResourceLocation): BakedModel {
val model = TournamentPlatformHelper
.get()
.loadBakedModel(rl)

if (model == null) {
println("[Tournament] Failed to load model $rl")
return Minecraft.getInstance().modelManager.missingModel
}

return model
}

val MODELS = mutableSetOf<ResourceLocation>()

interface Renderer {
fun render(
matrixStack: PoseStack,
blockEntity: BlockEntity,
bufferSource: MultiBufferSource,
packedLight: Int,
packedOverlay: Int
)
}

data class Model(
val resourceLocation: ResourceLocation
) {
val bakedModel: BakedModel by lazy {
getModel(resourceLocation)
}

val renderer = object : Renderer {
override fun render(
matrixStack: PoseStack,
blockEntity: BlockEntity,
bufferSource: MultiBufferSource,
packedLight: Int,
packedOverlay: Int
) {
val level = blockEntity.level ?: return

Minecraft.getInstance().blockRenderer.modelRenderer.tesselateWithoutAO(
level,
bakedModel,
blockEntity.blockState,
blockEntity.blockPos,
matrixStack,
bufferSource.getBuffer(RenderType.cutout()),
true,
level.random,
42L, // Used in ModelBlockRenderer.class in renderModel, not sure what the right number is but this seems to work
packedOverlay
)
}
}
}

private fun model(name: String): Model {
val rl = ResourceLocation(TournamentMod.MOD_ID, name)

MODELS += rl

return Model(rl)
}

val PROP_BIG = model("block/prop_big_prop")

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.valkyrienskies.tournament.blockentity

import net.minecraft.core.BlockPos
import net.minecraft.nbt.CompoundTag
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.Block
import net.minecraft.world.level.block.entity.BlockEntity
import net.minecraft.world.level.block.entity.BlockEntityTicker
import net.minecraft.world.level.block.state.BlockState
import org.valkyrienskies.tournament.TournamentBlockEntities

class PropellerBlockEntity(
pos: BlockPos,
state: BlockState,
private val redstoneFun: (state: BlockState, level: Level, pos: BlockPos) -> Int = { _, level, bp ->
println("[Tournament] PropellerBlockEntity.redstoneFun default constructor called! This should not happen!")
level.getBestNeighborSignal(bp)
}
): BlockEntity(TournamentBlockEntities.PROPELLER.get(), pos, state) {

var signal: Int = -1
var rotation: Float = 0.0f
var speed: Float = 0.0f

fun tick(level: Level) {
if (signal == -1) {
signal = redstoneFun(blockState, level, blockPos)
}
val targetSpeed = signal
if (speed < targetSpeed) {
speed += 0.1f
} else if (speed > targetSpeed) {
speed -= 0.2f
}
rotation += speed
rotation %= 360.0f
}

companion object {
val ticker = BlockEntityTicker<PropellerBlockEntity> { level, _, _, be ->
be.tick(level)
}
}

override fun getUpdateTag(): CompoundTag =
CompoundTag().also {
saveAdditional(it)
}

override fun getUpdatePacket(): ClientboundBlockEntityDataPacket? =
ClientboundBlockEntityDataPacket.create(this)

override fun saveAdditional(tag: CompoundTag) {
tag.putFloat("speed", speed)
tag.putFloat("rotation", rotation)
tag.putInt("signal", signal)

super.saveAdditional(tag)
}

override fun load(tag: CompoundTag) {
speed = tag.getFloat("speed")
rotation = tag.getFloat("rotation")
signal = tag.getInt("signal")

super.load(tag)
}

fun update() {
level?.sendBlockUpdated(blockPos, blockState, blockState, Block.UPDATE_ALL_IMMEDIATE)
}

}
Loading

0 comments on commit 39ff010

Please sign in to comment.