Skip to content

Commit

Permalink
Update to 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
Iru21 committed Jun 11, 2023
1 parent f2786cc commit 894e413
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 53 deletions.
17 changes: 9 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ kotlin.code.style=official
org.gradle.jvmargs = -Xmx1G
org.gradle.warning.mode = all
# Check these on https://fabricmc.net/develop/
minecraftVersion=1.19
yarnMappings=1.19+build.2
loaderVersion=0.14.7
minecraftVersion=1.20
yarnMappings=1.20+build.1
loaderVersion=0.14.21
#Fabric api
fabricVersion=0.55.3+1.19
loomVersion = 0.12-SNAPSHOT
clothConfigVersion = 6.1.48
fabricVersion=0.83.0+1.20
loomVersion = 1.0-SNAPSHOT
# Mod Properties
modVersion = 1.1.3
modVersion = 1.2.0
mavenGroup = me.iru
archivesBaseName = waxednotwaxed
# Kotlin
systemProp.kotlinVersion = 1.6.10
fabricKotlinVersion = 1.7.1+kotlin.1.6.10
fabricKotlinVersion = 1.8.7+kotlin.1.7.22

clothConfigVersion = 11.0.99
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package me.iru.waxednotwaxed.events

import me.iru.waxednotwaxed.WaxedNotWaxed
import me.shedaniel.autoconfig.AutoConfig
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents
import net.minecraft.client.MinecraftClient
import net.minecraft.sound.SoundCategory
import net.minecraft.sound.SoundEvent
import net.minecraft.sound.SoundEvents

fun EndClientTickHandler(): ClientTickEvents.EndTick {
Expand All @@ -17,7 +15,7 @@ fun EndClientTickHandler(): ClientTickEvents.EndTick {
WaxedNotWaxed.config!!.save()
val mc = MinecraftClient.getInstance()
val p = mc.player!!
mc.world!!.playSound(p, p.blockPos, SoundEvents.UI_BUTTON_CLICK, SoundCategory.MASTER, 0.1f, 1f)
mc.world!!.playSound(p, p.blockPos, SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.1f, 1f)
}
}
}
39 changes: 16 additions & 23 deletions src/main/kotlin/me/iru/waxednotwaxed/events/HudRenderHandler.kt
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
package me.iru.waxednotwaxed.events

import com.mojang.blaze3d.systems.RenderSystem
import me.iru.waxednotwaxed.Utils
import me.iru.waxednotwaxed.WaxedNotWaxed
import me.iru.waxednotwaxed.getBlockAtCrosshair
import me.iru.waxednotwaxed.getCrosshairLocation
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback
import net.minecraft.block.OxidizableBlock
import net.minecraft.block.OxidizableSlabBlock
import net.minecraft.block.OxidizableStairsBlock
import net.minecraft.client.MinecraftClient
import net.minecraft.client.gui.DrawableHelper
import net.minecraft.client.render.GameRenderer
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.client.gui.DrawContext
import net.minecraft.util.Identifier

class HudRenderHandler : HudRenderCallback {
override fun onHudRender(matrixStack: MatrixStack?, tickDelta: Float) {
if(matrixStack == null || !WaxedNotWaxed.toggledCached) return
val lookingAt = getBlockAtCrosshair()
if (lookingAt == null) return
if (lookingAt.name.toString().lowercase().contains("waxed")) render(matrixStack, true)

override fun onHudRender(drawContext: DrawContext?, tickDelta: Float) {
if(drawContext == null || !WaxedNotWaxed.toggledCached) return
val lookingAt = Utils.getBlockAtCrosshair() ?: return
if (lookingAt.name.toString().lowercase().contains("waxed")) render(drawContext, true)
else if(lookingAt is OxidizableBlock || lookingAt is OxidizableSlabBlock || lookingAt is OxidizableStairsBlock) {
render(matrixStack, false)
render(drawContext, false)
}
}

private fun render(matrixStack: MatrixStack, waxed: Boolean) {
private fun render(drawContext: DrawContext, waxed: Boolean) {
val mc = MinecraftClient.getInstance()
val screenCenter = getCrosshairLocation()
mc.textRenderer.drawWithShadow(
matrixStack,
val screenCenter = Utils.getCrosshairLocation()
drawContext.drawTextWithShadow(
mc.textRenderer,
if(waxed) "Waxed" else "Not Waxed",
screenCenter.x + 18,
screenCenter.y + 6,
screenCenter.x.toInt() + 18,
screenCenter.y.toInt() + 6,
if(waxed) 0xf78204 else 0x09a073
)
RenderSystem.enableBlend()
RenderSystem.setShader(GameRenderer::getPositionTexShader)
RenderSystem.setShaderTexture(0, Identifier("minecraft", if(waxed) "textures/item/honeycomb.png" else "textures/item/iron_axe.png"))
DrawableHelper.drawTexture(
matrixStack,
drawContext.drawTexture(
Identifier("minecraft", if(waxed) "textures/item/honeycomb.png" else "textures/item/iron_axe.png"),
screenCenter.x.toInt() + 5,
screenCenter.y.toInt() + 5,
0.0f,
Expand Down
33 changes: 17 additions & 16 deletions src/main/kotlin/me/iru/waxednotwaxed/utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ import net.minecraft.util.hit.BlockHitResult
import net.minecraft.util.hit.HitResult
import net.minecraft.util.math.Vec2f


fun getBlockAtCrosshair(): Block? {
val client: MinecraftClient = MinecraftClient.getInstance()
val hit: HitResult? = client.crosshairTarget
if(hit != null && hit.type == HitResult.Type.BLOCK) {
val blockHit = hit as BlockHitResult
val blockPos = blockHit.blockPos
val blockState = client.world!!.getBlockState(blockPos)
return blockState.block
object Utils {
fun getBlockAtCrosshair(): Block? {
val client: MinecraftClient = MinecraftClient.getInstance()
val hit: HitResult? = client.crosshairTarget
if(hit != null && hit.type == HitResult.Type.BLOCK) {
val blockHit = hit as BlockHitResult
val blockPos = blockHit.blockPos
val blockState = client.world!!.getBlockState(blockPos)
return blockState.block
}
return null
}
return null
}

fun getCrosshairLocation(): Vec2f {
val mc = MinecraftClient.getInstance()
val x = mc.getWindow().getScaledWidth().toFloat() / 2.0f
val y = mc.getWindow().getScaledHeight().toFloat() / 2.0f
return Vec2f(x, y)
fun getCrosshairLocation(): Vec2f {
val mc = MinecraftClient.getInstance()
val x = mc.window.scaledWidth.toFloat() / 2.0f
val y = mc.window.scaledHeight.toFloat() / 2.0f
return Vec2f(x, y)
}
}
Binary file modified src/main/resources/assets/waxednotwaxed/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
]
},
"depends": {
"fabricloader": ">=0.12.12",
"fabricloader": ">=0.14.21",
"fabric": "*",
"fabric-language-kotlin": ">=1.7.1+kotlin.1.6.10",
"minecraft": ">=1.19",
"fabric-language-kotlin": ">=1.8.7+kotlin.1.7.22",
"minecraft": ">=1.20",
"java": ">=17"
}
}

0 comments on commit 894e413

Please sign in to comment.