-
Notifications
You must be signed in to change notification settings - Fork 11
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
Showing
33 changed files
with
780 additions
and
88 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
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
82 changes: 82 additions & 0 deletions
82
common/src/main/kotlin/org/valkyrienskies/tournament/TournamentModels.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,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") | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
common/src/main/kotlin/org/valkyrienskies/tournament/blockentity/PropellerBlockEntity.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,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) | ||
} | ||
|
||
} |
Oops, something went wrong.