diff options
| author | Linnea Gräf <nea@nea.moe> | 2025-11-17 19:55:02 +0100 |
|---|---|---|
| committer | Linnea Gräf <nea@nea.moe> | 2025-11-17 19:55:02 +0100 |
| commit | c93a04a001b0f66b2724d46b04b6d1ed49a08d07 (patch) | |
| tree | 5869ca70acc482ef0362f27785c3d3f1cbb9ffae /src/main/kotlin/features/items | |
| parent | af9893b59407c69d31ebd2ed513f0396ab4d2dc9 (diff) | |
| download | Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.tar.gz Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.tar.bz2 Firmament-c93a04a001b0f66b2724d46b04b6d1ed49a08d07.zip | |
refactor: port to mojmaps
Diffstat (limited to 'src/main/kotlin/features/items')
| -rw-r--r-- | src/main/kotlin/features/items/BlockZapperOverlay.kt | 24 | ||||
| -rw-r--r-- | src/main/kotlin/features/items/BonemerangOverlay.kt | 36 | ||||
| -rw-r--r-- | src/main/kotlin/features/items/EtherwarpOverlay.kt | 76 |
3 files changed, 68 insertions, 68 deletions
diff --git a/src/main/kotlin/features/items/BlockZapperOverlay.kt b/src/main/kotlin/features/items/BlockZapperOverlay.kt index a853012..cc58f8a 100644 --- a/src/main/kotlin/features/items/BlockZapperOverlay.kt +++ b/src/main/kotlin/features/items/BlockZapperOverlay.kt @@ -2,12 +2,12 @@ package moe.nea.firmament.features.items import io.github.notenoughupdates.moulconfig.ChromaColour import java.util.LinkedList -import net.minecraft.block.Block -import net.minecraft.block.BlockState -import net.minecraft.block.Blocks -import net.minecraft.util.hit.BlockHitResult -import net.minecraft.util.hit.HitResult -import net.minecraft.util.math.BlockPos +import net.minecraft.world.level.block.Block +import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.block.Blocks +import net.minecraft.world.phys.BlockHitResult +import net.minecraft.world.phys.HitResult +import net.minecraft.core.BlockPos import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.WorldKeyboardEvent import moe.nea.firmament.events.WorldRenderLastEvent @@ -64,10 +64,10 @@ object BlockZapperOverlay { fun renderBlockZapperOverlay(event: WorldRenderLastEvent) { if (!TConfig.blockZapperOverlay) return val player = MC.player ?: return - val world = player.world ?: return + val world = player.level ?: return val heldItem = MC.stackInHand if (heldItem.skyBlockId != SkyBlockItems.BLOCK_ZAPPER) return - val hitResult = MC.instance.crosshairTarget ?: return + val hitResult = MC.instance.hitResult ?: return val zapperBlocks: HashSet<BlockPos> = HashSet() val returnablePositions = LinkedList<BlockPos>() @@ -77,7 +77,7 @@ object BlockZapperOverlay { val firstBlockState: BlockState = world.getBlockState(pos) val block = firstBlockState.block - val initialAboveBlock = world.getBlockState(pos.up()).block + val initialAboveBlock = world.getBlockState(pos.above()).block if (!bannedZapper.contains(initialAboveBlock) && !bannedZapper.contains(block)) { var i = 0 while (i < 164) { @@ -87,13 +87,13 @@ object BlockZapperOverlay { val availableNeighbors: MutableList<BlockPos> = ArrayList() for (offset in zapperOffsets) { - val newPos = pos.add(offset) + val newPos = pos.offset(offset) if (zapperBlocks.contains(newPos)) continue val state: BlockState? = world.getBlockState(newPos) if (state != null && state.block === block) { - val above = newPos.up() + val above = newPos.above() val aboveBlock = world.getBlockState(above).block if (!bannedZapper.contains(aboveBlock)) { availableNeighbors.add(newPos) @@ -118,7 +118,7 @@ object BlockZapperOverlay { } RenderInWorldContext.renderInWorld(event) { - if (MC.player?.isSneaking ?: false) { + if (MC.player?.isShiftKeyDown ?: false) { zapperBlocks.forEach { block(it, TConfig.color.getEffectiveColourRGB()) } diff --git a/src/main/kotlin/features/items/BonemerangOverlay.kt b/src/main/kotlin/features/items/BonemerangOverlay.kt index 1310154..3f16922 100644 --- a/src/main/kotlin/features/items/BonemerangOverlay.kt +++ b/src/main/kotlin/features/items/BonemerangOverlay.kt @@ -2,11 +2,11 @@ package moe.nea.firmament.features.items import me.shedaniel.math.Color import org.joml.Vector2i -import net.minecraft.entity.LivingEntity -import net.minecraft.entity.decoration.ArmorStandEntity -import net.minecraft.entity.player.PlayerEntity -import net.minecraft.util.Formatting -import net.minecraft.util.math.Box +import net.minecraft.world.entity.LivingEntity +import net.minecraft.world.entity.decoration.ArmorStand +import net.minecraft.world.entity.player.Player +import net.minecraft.ChatFormatting +import net.minecraft.world.phys.AABB import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.EntityRenderTintEvent import moe.nea.firmament.events.HudRenderEvent @@ -31,18 +31,18 @@ object BonemerangOverlay { fun getEntities(): MutableSet<LivingEntity> { val entities = mutableSetOf<LivingEntity>() - val camera = MC.camera as? PlayerEntity ?: return entities + val camera = MC.camera as? Player ?: return entities val player = MC.player ?: return entities - val world = player.world ?: return entities + val world = player.level ?: return entities - val cameraPos = camera.eyePos - val rayDirection = camera.rotationVector.normalize() - val endPos = cameraPos.add(rayDirection.multiply(15.0)) - val foundEntities = world.getOtherEntities(camera, Box(cameraPos, endPos).expand(1.0)) + val cameraPos = camera.eyePosition + val rayDirection = camera.lookAngle.normalize() + val endPos = cameraPos.add(rayDirection.scale(15.0)) + val foundEntities = world.getEntities(camera, AABB(cameraPos, endPos).inflate(1.0)) for (entity in foundEntities) { - if (entity !is LivingEntity || entity is ArmorStandEntity || entity.isInvisible) continue - val hitResult = entity.boundingBox.expand(0.35).raycast(cameraPos, endPos).orElse(null) + if (entity !is LivingEntity || entity is ArmorStand || entity.isInvisible) continue + val hitResult = entity.boundingBox.inflate(0.35).clip(cameraPos, endPos).orElse(null) if (hitResult != null) entities.add(entity) } @@ -66,7 +66,7 @@ object BonemerangOverlay { if (event.entity !in entities) return val tintOverlay by lazy { - TintedOverlayTexture().setColor(Color.ofOpaque(Formatting.BLUE.colorValue!!)) + TintedOverlayTexture().setColor(Color.ofOpaque(ChatFormatting.BLUE.color!!)) } event.renderState.overlayTexture_firmament = tintOverlay @@ -80,15 +80,15 @@ object BonemerangOverlay { val entities = getEntities() - it.context.matrices.pushMatrix() - TConfig.bonemerangOverlayHud.applyTransformations(it.context.matrices) - it.context.drawText( + it.context.pose().pushMatrix() + TConfig.bonemerangOverlayHud.applyTransformations(it.context.pose()) + it.context.drawString( MC.font, String.format( tr( "firmament.bonemerang-overlay.bonemerang-overlay.display", "Bonemerang Targets: %s" ).string, entities.size ), 0, 0, -1, true ) - it.context.matrices.popMatrix() + it.context.pose().popMatrix() } } diff --git a/src/main/kotlin/features/items/EtherwarpOverlay.kt b/src/main/kotlin/features/items/EtherwarpOverlay.kt index 5f32a96..a59fcbd 100644 --- a/src/main/kotlin/features/items/EtherwarpOverlay.kt +++ b/src/main/kotlin/features/items/EtherwarpOverlay.kt @@ -1,17 +1,17 @@ package moe.nea.firmament.features.items import io.github.notenoughupdates.moulconfig.ChromaColour -import net.minecraft.block.Blocks -import net.minecraft.registry.entry.RegistryEntry -import net.minecraft.registry.tag.BlockTags -import net.minecraft.registry.tag.TagKey -import net.minecraft.text.Text -import net.minecraft.util.hit.BlockHitResult -import net.minecraft.util.hit.HitResult -import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.Vec3d -import net.minecraft.util.shape.VoxelShapes -import net.minecraft.world.BlockView +import net.minecraft.world.level.block.Blocks +import net.minecraft.core.Holder +import net.minecraft.tags.BlockTags +import net.minecraft.tags.TagKey +import net.minecraft.network.chat.Component +import net.minecraft.world.phys.BlockHitResult +import net.minecraft.world.phys.HitResult +import net.minecraft.core.BlockPos +import net.minecraft.world.phys.Vec3 +import net.minecraft.world.phys.shapes.Shapes +import net.minecraft.world.level.BlockGetter import moe.nea.firmament.annotations.Subscribe import moe.nea.firmament.events.WorldRenderLastEvent import moe.nea.firmament.util.MC @@ -41,7 +41,7 @@ object EtherwarpOverlay { var failureText by toggle("failure-text") { false } } - enum class EtherwarpResult(val label: Text?, val color: () -> ChromaColour) { + enum class EtherwarpResult(val label: Component?, val color: () -> ChromaColour) { SUCCESS(null, TConfig::cubeColour), INTERACTION_BLOCKED( tr("firmament.etherwarp.fail.tooclosetointeractable", "Too close to interactable"), @@ -76,10 +76,10 @@ object EtherwarpOverlay { ) data class Checker<T>( - val direct: Set<T>, - val byTag: Set<TagKey<T>>, + val direct: Set<T>, + val byTag: Set<TagKey<T>>, ) { - fun matches(entry: RegistryEntry<T>): Boolean { + fun matches(entry: Holder<T>): Boolean { return entry.value() in direct || checkTags(entry, byTag) } } @@ -123,34 +123,34 @@ object EtherwarpOverlay { ) - fun <T> checkTags(holder: RegistryEntry<out T>, set: Set<TagKey<out T>>) = - holder.streamTags() + fun <T> checkTags(holder: Holder<out T>, set: Set<TagKey<out T>>) = + holder.tags() .anyMatch(set::contains) - fun isEtherwarpTransparent(world: BlockView, blockPos: BlockPos): Boolean { + fun isEtherwarpTransparent(world: BlockGetter, blockPos: BlockPos): Boolean { val blockState = world.getBlockState(blockPos) val block = blockState.block - if (etherwarpConsidersFat.matches(blockState.registryEntry)) + if (etherwarpConsidersFat.matches(blockState.blockHolder)) return false - if (block.defaultState.getCollisionShape(world, blockPos).isEmpty) + if (block.defaultBlockState().getCollisionShape(world, blockPos).isEmpty) return true - if (etherwarpHallpasses.matches(blockState.registryEntry)) + if (etherwarpHallpasses.matches(blockState.blockHolder)) return true return false } sealed interface EtherwarpBlockHit { - data class BlockHit(val blockPos: BlockPos, val accuratePos: Vec3d?) : EtherwarpBlockHit + data class BlockHit(val blockPos: BlockPos, val accuratePos: Vec3?) : EtherwarpBlockHit data object Miss : EtherwarpBlockHit } - fun raycastWithEtherwarpTransparency(world: BlockView, start: Vec3d, end: Vec3d): EtherwarpBlockHit { - return BlockView.raycast<EtherwarpBlockHit, Unit>( + fun raycastWithEtherwarpTransparency(world: BlockGetter, start: Vec3, end: Vec3): EtherwarpBlockHit { + return BlockGetter.traverseBlocks<EtherwarpBlockHit, Unit>( start, end, Unit, { _, blockPos -> if (isEtherwarpTransparent(world, blockPos)) { - return@raycast null + return@traverseBlocks null } // val defaultedState = world.getBlockState(blockPos).block.defaultState // val hitShape = defaultedState.getCollisionShape( @@ -161,8 +161,8 @@ object EtherwarpOverlay { // if (world.raycastBlock(start, end, blockPos, hitShape, defaultedState) == null) { // return@raycast null // } - val partialResult = world.raycastBlock(start, end, blockPos, VoxelShapes.fullCube(), world.getBlockState(blockPos).block.defaultState) - return@raycast EtherwarpBlockHit.BlockHit(blockPos, partialResult?.pos) + val partialResult = world.clipWithInteractionOverride(start, end, blockPos, Shapes.block(), world.getBlockState(blockPos).block.defaultBlockState()) + return@traverseBlocks EtherwarpBlockHit.BlockHit(blockPos, partialResult?.location) }, { EtherwarpBlockHit.Miss }) } @@ -176,8 +176,8 @@ object EtherwarpOverlay { fun renderEtherwarpOverlay(event: WorldRenderLastEvent) { if (!TConfig.etherwarpOverlay) return val player = MC.player ?: return - if (TConfig.onlyShowWhileSneaking && !player.isSneaking) return - val world = player.world + if (TConfig.onlyShowWhileSneaking && !player.isShiftKeyDown) return + val world = player.level val heldItem = MC.stackInHand val etherwarpTyp = run { if (heldItem.extraAttributes.contains("ethermerge")) @@ -188,12 +188,12 @@ object EtherwarpOverlay { return } val playerEyeHeight = // Sneaking: 1.27 (1.21) 1.54 (1.8.9) / Upright: 1.62 (1.8.9,1.21) - if (player.isSneaking || etherwarpTyp == EtherwarpItemKind.MERGED) + if (player.isShiftKeyDown || etherwarpTyp == EtherwarpItemKind.MERGED) (if (SBData.skyblockLocation?.isModernServer ?: false) 1.27 else 1.54) else 1.62 - val playerEyePos = player.pos.add(0.0, playerEyeHeight, 0.0) + val playerEyePos = player.position.add(0.0, playerEyeHeight, 0.0) val start = playerEyePos - val end = player.getRotationVec(0F).multiply(160.0).add(playerEyePos) + val end = player.getViewVector(0F).scale(160.0).add(playerEyePos) val hitResult = raycastWithEtherwarpTransparency( world, start, @@ -202,15 +202,15 @@ object EtherwarpOverlay { if (hitResult !is EtherwarpBlockHit.BlockHit) return val blockPos = hitResult.blockPos val success = run { - if (!isEtherwarpTransparent(world, blockPos.up())) + if (!isEtherwarpTransparent(world, blockPos.above())) EtherwarpResult.OCCUPIED - else if (!isEtherwarpTransparent(world, blockPos.up(2))) + else if (!isEtherwarpTransparent(world, blockPos.above(2))) EtherwarpResult.OCCUPIED - else if (playerEyePos.squaredDistanceTo(hitResult.accuratePos ?: blockPos.toCenterPos()) > 61 * 61) + else if (playerEyePos.distanceToSqr(hitResult.accuratePos ?: blockPos.center) > 61 * 61) EtherwarpResult.TOO_DISTANT - else if ((MC.instance.crosshairTarget as? BlockHitResult) + else if ((MC.instance.hitResult as? BlockHitResult) ?.takeIf { it.type == HitResult.Type.BLOCK } - ?.let { interactionBlocked.matches(world.getBlockState(it.blockPos).registryEntry) } + ?.let { interactionBlocked.matches(world.getBlockState(it.blockPos).blockHolder) } ?: false ) EtherwarpResult.INTERACTION_BLOCKED @@ -225,7 +225,7 @@ object EtherwarpOverlay { ) if (TConfig.wireframe) wireframeCube(blockPos, 10f) if (TConfig.failureText && success.label != null) { - withFacingThePlayer(blockPos.toCenterPos()) { + withFacingThePlayer(blockPos.center) { text(success.label) } } |
