Skip to content

Commit

Permalink
Updated to Fabric 1.21, added KillAura.weapons setting
Browse files Browse the repository at this point in the history
  • Loading branch information
ya-ilya committed Jul 7, 2024
1 parent da409a3 commit 8cc2507
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 63 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ kotlinVersion=2.0.0
progresoVersion=0.3

# fabric
minecraftVersion=1.20.6
fabricVersion=0.99.4+1.20.6
minecraftVersion=1.21
fabricVersion=0.100.4+1.21
fabricLoomVersion=1.6-SNAPSHOT
yarnMappings=1.20.6+build.3
yarnMappings=1.21+build.7
loaderVersion=0.15.11

# other
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.render.RenderTickCounter;
import org.progreso.client.Client;
import org.progreso.client.events.render.Render2DEvent;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -15,7 +16,13 @@ public abstract class MixinInGameHud {
method = "render",
at = @At("TAIL")
)
public void renderHook(DrawContext context, float tickDelta, CallbackInfo callbackInfo) {
public void renderHook(
DrawContext context,
RenderTickCounter tickCounter,
CallbackInfo callbackInfo
) {
Client.getMc().getClient().getProfiler().push("progreso_2d_render");
Client.EVENT_BUS.post(new Render2DEvent(context));
Client.getMc().getClient().getProfiler().pop();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package org.progreso.client.mixins.network;

import net.minecraft.client.network.ClientPlayerInteractionManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import org.progreso.client.Client;
import org.progreso.client.events.block.DamageBlockEvent;
import org.progreso.client.events.player.AttackEntityEvent;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(ClientPlayerInteractionManager.class)
Expand All @@ -21,4 +25,15 @@ public void attackBlockHook(BlockPos pos, Direction direction, CallbackInfoRetur
callbackInfoReturnable.cancel();
}
}

@Inject(
method = "attackEntity",
at = @At("HEAD"),
cancellable = true
)
public void attackEntityHook(PlayerEntity player, Entity target, CallbackInfo callbackInfo) {
if (Client.EVENT_BUS.post(new AttackEntityEvent(target))) {
callbackInfo.cancel();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.llamalad7.mixinextras.sugar.Local;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.RenderTickCounter;
import net.minecraft.client.util.math.MatrixStack;
import org.joml.Matrix4f;
import org.objectweb.asm.Opcodes;
Expand All @@ -15,7 +16,7 @@
@Mixin(GameRenderer.class)
public abstract class MixinGameRenderer {
@Inject(
method = "renderWorld(FJ)V",
method = "renderWorld",
at = @At(
value = "FIELD",
target = "Lnet/minecraft/client/render/GameRenderer;renderHand:Z",
Expand All @@ -24,12 +25,12 @@ public abstract class MixinGameRenderer {
)
)
public void renderWorldHook(
float tickDelta,
long limitTime,
CallbackInfo ci,
@Local(ordinal = 1) Matrix4f matrix4f2
RenderTickCounter tickCounter,
CallbackInfo callbackInfo,
@Local(ordinal = 1) Matrix4f matrix4f2,
@Local(ordinal = 1) float tickDelta
) {
Client.getMc().getClient().getProfiler().push("progreso_render");
Client.getMc().getClient().getProfiler().push("progreso_3d_render");
MatrixStack matrixStack = new MatrixStack();
matrixStack.multiplyPositionMatrix(matrix4f2);
Client.EVENT_BUS.post(new Render3DEvent(matrixStack, tickDelta));
Expand Down
2 changes: 0 additions & 2 deletions progreso-client/src/main/kotlin/org/progreso/client/Client.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ class Client : ClientModInitializer {
}

class MinecraftClientWrapper(val client: MinecraftClient) {
val tickDelta get() = client.tickDelta

val world get() = client.world!!
val player get() = client.player!!
val textRenderer get() = client.textRenderer!!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.progreso.client.events.player

import net.minecraft.entity.Entity
import org.progreso.api.event.Event

data class AttackEntityEvent(val entity: Entity) : Event()
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ package org.progreso.client.gui.clickgui.element.elements
import com.mojang.blaze3d.platform.GlStateManager
import com.mojang.blaze3d.systems.RenderSystem
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.render.GameRenderer
import net.minecraft.client.render.Tessellator
import net.minecraft.client.render.VertexFormat
import net.minecraft.client.render.VertexFormats
import net.minecraft.client.render.*
import org.progreso.api.setting.settings.ColorSetting
import org.progreso.api.setting.settings.NumberSetting
import org.progreso.client.gui.clickgui.element.AbstractChildElement
Expand Down Expand Up @@ -122,53 +119,46 @@ class ColorElement(

RenderSystem.setShader(GameRenderer::getPositionColorProgram)

val buffer = Tessellator.getInstance().buffer
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR)
var buffer = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR)

buffer
.vertex(matrix, x, y, 0f)
.color(1f, 1f, 1f, 1f)
.next()

buffer
.vertex(matrix, x, y + height, 0f)
.color(1f, 1f, 1f, 1f)
.next()

buffer
.vertex(matrix, x + width, y + height, 0f)
.color(red, green, blue, alpha)
.next()

buffer
.vertex(matrix, x + width, y, 0f)
.color(red, green, blue, alpha)
.next()

Tessellator.getInstance().draw()
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR)
BufferRenderer.drawWithGlobalProgram(buffer.end())

buffer = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR)

buffer
.vertex(matrix, x, y, 0f)
.color(0f, 0f, 0f, 0f)
.next()

buffer
.vertex(matrix, x, y + height, 0f)
.color(0f, 0f, 0f, 1f)
.next()

buffer
.vertex(matrix, x + width, y + height, 0f)
.color(0f, 0f, 0f, 1f)
.next()

buffer
.vertex(matrix, x + width, y, 0f)
.color(0f, 0f, 0f, 0f)
.next()

Tessellator.getInstance().draw()
BufferRenderer.drawWithGlobalProgram(buffer.end())

context.matrices.pop()

RenderSystem.setShaderColor(1f, 1f, 1f, 1f)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import net.minecraft.entity.passive.IronGolemEntity
import net.minecraft.entity.passive.PassiveEntity
import net.minecraft.entity.passive.SnowGolemEntity
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.item.AxeItem
import net.minecraft.item.MaceItem
import net.minecraft.item.SwordItem
import org.progreso.api.module.AbstractModule
import org.progreso.client.Client.Companion.mc
Expand All @@ -18,18 +20,25 @@ import org.progreso.client.util.player.attack
@AbstractModule.AutoRegister
object KillAura : AbstractModule() {
private val distance by setting("Distance", 4, 1..6)
private val onlySword by setting("OnlySword", true)
private val target by setting("Target", Target.Distance)

private val weapons = setting("Weapons")
private val axe by weapons.setting("Axe", false)
private val sword by weapons.setting("Sword", true)
private val mace by weapons.setting("Mace", false)

private val targets = setting("Targets")
private val players by targets.setting("Players", true)
private val monsters by targets.setting("Monsters", false)
private val animals by targets.setting("Animals", false)

init {
safeEventListener<TickEvent> { _ ->
if (onlySword && mc.player.mainHandStack.item !is SwordItem) {
return@safeEventListener
when (mc.player.mainHandStack.item) {
is AxeItem -> if (!axe) return@safeEventListener
is SwordItem -> if (!sword) return@safeEventListener
is MaceItem -> if (!mace) return@safeEventListener
else -> return@safeEventListener
}

val entity = mc.world.entities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.progreso.client.modules.misc
import net.minecraft.enchantment.EnchantmentHelper
import net.minecraft.enchantment.Enchantments
import net.minecraft.item.ItemStack
import net.minecraft.registry.RegistryKeys
import net.minecraft.util.math.BlockPos
import org.progreso.api.module.AbstractModule
import org.progreso.client.Client.Companion.mc
Expand All @@ -29,7 +30,10 @@ object AutoTool : AbstractModule() {
var speed = stack.getMiningSpeedMultiplier(mc.world.getBlockState(pos))

if (speed > 1.0f) {
speed += EnchantmentHelper.getLevel(Enchantments.EFFICIENCY, stack)
speed += EnchantmentHelper.getLevel(
mc.world.registryManager.get(RegistryKeys.ENCHANTMENT).getEntry(Enchantments.EFFICIENCY).get(),
stack
)
}

return speed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import net.minecraft.entity.LivingEntity
import net.minecraft.util.Hand
import org.progreso.client.Client.Companion.mc

fun ClientPlayerInteractionManager.attack(entity: LivingEntity, checkStrength: Boolean = true) {
if (checkStrength && mc.player.getAttackCooldownProgress(mc.tickDelta) != 1.0f) {
fun ClientPlayerInteractionManager.attack(
entity: LivingEntity,
checkStrength: Boolean = true,
tickDelta: Float = 0.5f
) {
if (checkStrength && mc.player.getAttackCooldownProgress(tickDelta) != 1.0f) {
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import com.mojang.blaze3d.platform.GlStateManager
import com.mojang.blaze3d.systems.RenderSystem
import net.minecraft.client.font.*
import net.minecraft.client.gui.DrawContext
import net.minecraft.client.render.GameRenderer
import net.minecraft.client.render.Tessellator
import net.minecraft.client.render.VertexFormat
import net.minecraft.client.render.VertexFormats
import net.minecraft.client.render.*
import net.minecraft.resource.ResourceManager
import net.minecraft.util.Identifier
import org.progreso.client.Client
Expand Down Expand Up @@ -53,26 +50,25 @@ fun Render2DContext.drawCircle(
segments: Int,
radius: Double
) {
val buffer = Tessellator.getInstance().buffer
val matrix = context.matrices.peek().positionMatrix

val angleStep = Math.toRadians(angleTo - angleFrom) / segments

RenderSystem.setShader { GameRenderer.getPositionProgram() }

buffer.begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION)
buffer.vertex(matrix, centerX.toFloat(), centerY.toFloat(), 0f).next()
val buffer = Tessellator.getInstance().begin(VertexFormat.DrawMode.TRIANGLE_FAN, VertexFormats.POSITION)
buffer.vertex(matrix, centerX.toFloat(), centerY.toFloat(), 0f)

for (i in segments downTo 0) {
val theta = Math.toRadians(angleFrom) + i * angleStep
buffer.vertex(
matrix,
(centerX - cos(theta) * radius).toFloat(),
(centerY - sin(theta) * radius).toFloat(), 0f
).next()
)
}

Tessellator.getInstance().draw()
BufferRenderer.drawWithGlobalProgram(buffer.end())
}

fun createTextRenderer(
Expand All @@ -82,12 +78,12 @@ fun createTextRenderer(
namespace: String = "progreso"
): TextRenderer? {
val font =
TrueTypeFontLoader(Identifier(namespace, "$fontName.ttf"), size, 2f, TrueTypeFontLoader.Shift.NONE, "")
TrueTypeFontLoader(Identifier.of(namespace, "$fontName.ttf"), size, 2f, TrueTypeFontLoader.Shift.NONE, "")
.build()
.left()

if (font.isPresent) {
val fontStorage = FontStorage(Client.mc.client.textureManager, Identifier("progreso"))
val fontStorage = FontStorage(Client.mc.client.textureManager, Identifier.of("progreso"))
fontStorage.setFonts(
listOf(Font.FontFilterPair(font.get().load(resourceManager), FontFilterType.FilterMap.NO_FILTER)),
emptySet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package org.progreso.client.util.render

import com.mojang.blaze3d.platform.GlStateManager
import com.mojang.blaze3d.systems.RenderSystem
import net.minecraft.client.render.GameRenderer
import net.minecraft.client.render.Tessellator
import net.minecraft.client.render.VertexFormat
import net.minecraft.client.render.VertexFormats
import net.minecraft.client.render.*
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Box
Expand Down Expand Up @@ -59,12 +56,10 @@ fun Render3DContext.withColor(color: Color, block: Render3DContext.() -> Unit) {
}

fun Render3DContext.drawOutlinedBox(box: Box) {
val matrix = matrices.peek().positionMatrix
val buffer = Tessellator.getInstance().buffer

RenderSystem.setShader(GameRenderer::getPositionProgram)

buffer.begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION)
val matrix = matrices.peek().positionMatrix
val buffer = Tessellator.getInstance().begin(VertexFormat.DrawMode.DEBUG_LINES, VertexFormats.POSITION)

val vertices = listOf(
Vec3d(box.minX, box.minY, box.minZ),
Expand Down Expand Up @@ -99,19 +94,17 @@ fun Render3DContext.drawOutlinedBox(box: Box) {
vec3d.x.toFloat(),
vec3d.y.toFloat(),
vec3d.z.toFloat()
).next()
)
}

Tessellator.getInstance().draw()
BufferRenderer.drawWithGlobalProgram(buffer.end())
}

fun Render3DContext.drawSolidBox(box: Box) {
val matrix = matrices.peek().positionMatrix
val buffer = Tessellator.getInstance().buffer

RenderSystem.setShader { GameRenderer.getPositionProgram() }
RenderSystem.setShader(GameRenderer::getPositionProgram)

buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION)
val matrix = matrices.peek().positionMatrix
val buffer = Tessellator.getInstance().begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION)

val vertices = listOf(
Vec3d(box.minX, box.minY, box.minZ),
Expand Down Expand Up @@ -146,8 +139,8 @@ fun Render3DContext.drawSolidBox(box: Box) {
vec3d.x.toFloat(),
vec3d.y.toFloat(),
vec3d.z.toFloat()
).next()
)
}

Tessellator.getInstance().draw()
BufferRenderer.drawWithGlobalProgram(buffer.end())
}

0 comments on commit 8cc2507

Please sign in to comment.