Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions common/src/main/java/com/lambda/mixin/items/TridentMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.lambda.mixin.items;

import com.lambda.module.modules.movement.TridentBoost;
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.minecraft.item.TridentItem;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

@Mixin(TridentItem.class)
public class TridentMixin {
// Forge doesn't support the @ModityArgs annotation, so we have to chain multiple @ModifyArg
@ModifyArg(method = "onStoppedUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;addVelocity(DDD)V"), index = 0)
private double modifyVelocity0(double velocity) { return TridentBoost.INSTANCE.isEnabled() ? velocity * TridentBoost.INSTANCE.getTridentSpeed() : velocity; }

@ModifyArg(method = "onStoppedUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;addVelocity(DDD)V"), index = 1)
private double modifyVelocity1(double velocity) { return TridentBoost.INSTANCE.isEnabled() ? velocity * TridentBoost.INSTANCE.getTridentSpeed() : velocity; }

@ModifyArg(method = "onStoppedUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;addVelocity(DDD)V"), index = 2)
private double modifyVelocity2(double velocity) { return TridentBoost.INSTANCE.isEnabled() ? velocity * TridentBoost.INSTANCE.getTridentSpeed() : velocity; }

@ModifyExpressionValue(method = {"onStoppedUsing", "use"}, at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;isTouchingWaterOrRain()Z"))
private boolean modifyIsTouchingWaterOrRain(boolean original) { return TridentBoost.INSTANCE.isEnabled() ? TridentBoost.INSTANCE.getForceUse() : original; }
}
17 changes: 17 additions & 0 deletions common/src/main/java/com/lambda/mixin/world/WorldMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.lambda.mixin.world;

import com.lambda.module.modules.movement.TridentFlight;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
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.CallbackInfoReturnable;

@Mixin(World.class)
public class WorldMixin {
@Inject(method = "hasRain", at = @At("HEAD"), cancellable = true)
private void hasRain(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
if (TridentFlight.INSTANCE.isEnabled()) cir.setReturnValue(TridentFlight.INSTANCE.getRain());
}
}
2 changes: 2 additions & 0 deletions common/src/main/kotlin/com/lambda/Lambda.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.lambda.core.Loader
import com.lambda.gui.impl.clickgui.windows.TagWindow
import com.lambda.module.tag.ModuleTag
import com.lambda.util.KeyCode
import com.mojang.authlib.GameProfile
import net.minecraft.block.Block
import net.minecraft.client.MinecraftClient
import net.minecraft.util.math.BlockPos
Expand All @@ -32,6 +33,7 @@ object Lambda {
.registerTypeAdapter(Color::class.java, ColorSerializer)
.registerTypeAdapter(BlockPos::class.java, BlockPosSerializer)
.registerTypeAdapter(Block::class.java, BlockSerializer)
.registerTypeAdapter(GameProfile::class.java, GameProfileSerializer)
.create()

fun initialize() = Loader.initialize()
Expand Down
14 changes: 7 additions & 7 deletions common/src/main/kotlin/com/lambda/config/Configurable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
* The type parameter [T] must either be a primitive type or a type with a registered type adapter in [Lambda.gson].
*
* @param name The unique identifier for the setting.
* @param defaultValue The default [List] value of type [T] for the setting.
* @param defaultValue The default [ArrayList] value of type [T] for the setting.
* @param description A brief explanation of the setting's purpose and behavior.
* @param visibility A lambda expression that determines the visibility status of the setting.
*
* ```kotlin
* // the parameter type is inferred from the defaultValue
* private val foo by setting("Foo", listOf("bar", "baz"))
* private val foo by setting("Foo", arrayListOf("bar", "baz"))
* ```
*
* @return The created [ListSetting].
Expand All @@ -167,7 +167,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
defaultValue: List<T>,
description: String = "",
noinline visibility: () -> Boolean = { true },
) = ListSetting(name, defaultValue, object : TypeToken<List<T>>() {}.type, description, visibility).also {
) = ListSetting(name, defaultValue.toMutableList(), TypeToken.getParameterized(MutableList::class.java, T::class.java).type, description, visibility).also {
settings.add(it)
}

Expand All @@ -188,12 +188,12 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
*
* @return The created [MapSetting].
*/
inline fun <reified K : Any, V : Any> setting(
inline fun <reified K : Any, reified V : Any> setting(
name: String,
defaultValue: Map<K, V>,
description: String = "",
noinline visibility: () -> Boolean = { true },
) = MapSetting(name, defaultValue, object : TypeToken<Map<K, V>>() {}.type, description, visibility).also {
) = MapSetting(name, defaultValue.toMutableMap(), TypeToken.getParameterized(Map::class.java, K::class.java, V::class.java).type, description, visibility).also {
settings.add(it)
}

Expand All @@ -219,7 +219,7 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
defaultValue: Set<T>,
description: String = "",
noinline visibility: () -> Boolean = { true },
) = SetSetting(name, defaultValue, object : TypeToken<Set<T>>() {}.type, description, visibility).also {
) = SetSetting(name, defaultValue.toMutableSet(), TypeToken.getParameterized(Set::class.java, T::class.java).type, description, visibility).also {
settings.add(it)
}

Expand Down Expand Up @@ -448,4 +448,4 @@ abstract class Configurable(configuration: Configuration) : Jsonable, Nameable {
) = BlockSetting(name, defaultValue, description, visibility).also {
settings.add(it)
}
}
}
3 changes: 2 additions & 1 deletion common/src/main/kotlin/com/lambda/config/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ abstract class Configuration : Jsonable {
this@Configuration.info(message)
}
.onFailure {
val message = "Failed to load ${configName.capitalize()} config from backup, unrecoverable error"
val message =
"Failed to load ${configName.capitalize()} config from backup, unrecoverable error"
LOG.error(message, it)
this@Configuration.logError(message)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.lambda.config.configurations

import com.lambda.config.Configuration
import com.lambda.util.FolderRegister

object FriendConfig : Configuration() {
override val configName = "friends"
override val primary = FolderRegister.config.resolve("$configName.json")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.lambda.config.Configuration
import com.lambda.config.configurations.ModuleConfig.configName
import com.lambda.config.configurations.ModuleConfig.primary
import com.lambda.util.FolderRegister
import java.io.File


/**
Expand All @@ -18,4 +17,4 @@ import java.io.File
object ModuleConfig : Configuration() {
override val configName = "modules"
override val primary = FolderRegister.config.resolve("$configName.json")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.lambda.config.serializer

import com.google.gson.*
import com.mojang.authlib.GameProfile
import java.lang.reflect.Type
import java.util.*

// Yeah yeah I know, there's already a serializer for GameProfile in the Minecraft codebase.
// But who cares, I'm doing it again.
// What you gon' do bout it, huh?
// That's what I thought.
object GameProfileSerializer : JsonSerializer<GameProfile>, JsonDeserializer<GameProfile> {
override fun serialize(
src: GameProfile?,
typeOfSrc: Type?,
context: JsonSerializationContext?,
): JsonElement =
src?.let {
JsonObject().apply {
addProperty("name", it.name)
addProperty("uuid", it.id.toString())
}
} ?: JsonNull.INSTANCE

override fun deserialize(
json: JsonElement?,
typeOfT: Type?,
context: JsonDeserializationContext?,
): GameProfile =
GameProfile(
UUID.fromString(json?.asJsonObject?.get("uuid")?.asString),
json?.asJsonObject?.get("name")?.asString
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ import java.lang.reflect.Type

class ListSetting<T : Any>(
override val name: String,
defaultValue: List<T>,
private val defaultValue: MutableList<T>,
private val type: Type,
description: String,
visibility: () -> Boolean,
) : AbstractSetting<List<T>>(
) : AbstractSetting<MutableList<T>>(
defaultValue,
description,
visibility
) {
override fun loadFromJson(serialized: JsonElement) {
value = gson.fromJson(serialized, type)
}
}

override fun toJson(): JsonElement {
value = defaultValue.toMutableList() // Hack the Delegates.observable
return gson.toJsonTree(value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ import java.lang.reflect.Type

class MapSetting<K, V>(
override val name: String,
defaultValue: Map<K, V>,
private val defaultValue: MutableMap<K, V>,
private val type: Type,
description: String,
visibility: () -> Boolean,
) : AbstractSetting<Map<K, V>>(
) : AbstractSetting<MutableMap<K, V>>(
defaultValue,
description,
visibility
) {
override fun loadFromJson(serialized: JsonElement) {
value = gson.fromJson(serialized, type)
}
}

override fun toJson(): JsonElement {
value = defaultValue.toMutableMap() // Hack the Delegates.observable
return gson.toJsonTree(value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ import java.lang.reflect.Type

class SetSetting<T : Any>(
override val name: String,
defaultValue: Set<T>,
private val defaultValue: MutableSet<T>,
private val type: Type,
description: String,
visibility: () -> Boolean,
) : AbstractSetting<Set<T>>(
) : AbstractSetting<MutableSet<T>>(
defaultValue,
description,
visibility
) {
override fun loadFromJson(serialized: JsonElement) {
value = gson.fromJson(serialized, type)
}
}

override fun toJson(): JsonElement {
value = defaultValue.toMutableSet() // Hack the Delegates.observable
return gson.toJsonTree(value)
}
}
9 changes: 6 additions & 3 deletions common/src/main/kotlin/com/lambda/core/Loader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import com.lambda.Lambda
import com.lambda.Lambda.LOG
import com.lambda.command.CommandManager
import com.lambda.config.configurations.GuiConfig
import com.lambda.friend.FriendManager
import com.lambda.graphics.renderer.gui.font.LambdaFont
import com.lambda.gui.impl.clickgui.GuiConfigurable
import com.lambda.gui.impl.clickgui.LambdaClickGui
import com.lambda.interaction.PlayerPacketManager
import com.lambda.interaction.RotationManager
import com.lambda.module.ModuleRegistry
import com.lambda.util.Communication.ascii
import com.mojang.authlib.GameProfile
import java.util.*
import kotlin.system.measureTimeMillis

object Loader {
Expand All @@ -19,7 +22,9 @@ object Loader {
CommandManager,
RotationManager,
PlayerPacketManager,
LambdaFont.Loader
LambdaFont.Loader,
GuiConfigurable,
FriendManager,
)

fun initialize() {
Expand All @@ -38,7 +43,5 @@ object Loader {
}

LOG.info("${Lambda.MOD_NAME} ${Lambda.VERSION} was successfully initialized (${initTime}ms)")

GuiConfigurable // ToDo: Find more elegant solution
}
}
39 changes: 39 additions & 0 deletions common/src/main/kotlin/com/lambda/friend/FriendManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.lambda.friend

import com.lambda.config.Configurable
import com.lambda.config.configurations.FriendConfig
import com.lambda.core.Loadable
import com.mojang.authlib.GameProfile
import net.minecraft.server.network.ServerPlayerEntity
import java.util.UUID

object FriendManager : Configurable(FriendConfig), Loadable {
override val name = "FriendManager"

private var friends by setting("friends", listOf<GameProfile>())

fun add(profile: GameProfile) = friends.add(profile)

fun remove(profile: GameProfile) = friends.remove(profile)

fun get(name: String) = friends.firstOrNull { it.name == name }
fun get(uuid: UUID) = friends.firstOrNull { it.id == uuid }

fun contains(profile: GameProfile) = friends.contains(profile)
fun contains(name: String) = friends.any { it.name == name }
fun contains(uuid: UUID) = friends.any { it.id == uuid }

fun clear() = friends.clear()

val ServerPlayerEntity.isFriend: Boolean
get() = contains(gameProfile)

fun ServerPlayerEntity.befriend() = add(gameProfile)
fun ServerPlayerEntity.unfriend() = remove(gameProfile)

override fun load(): String {
if (friends.isEmpty()) return "No friends loaded, damn bro you don't have to be antisocial online too,"
val word = if (friends.size == 1) "friend" else "friends"
return "Loaded ${friends.size} $word."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package com.lambda.gui.impl.clickgui

import com.lambda.config.Configurable
import com.lambda.config.configurations.GuiConfig
import com.lambda.core.Loadable
import com.lambda.gui.impl.clickgui.windows.TagWindow

object GuiConfigurable : Configurable(GuiConfig) {
object GuiConfigurable : Configurable(GuiConfig), Loadable {
override val name = "gui"
val windows = setting("windows", listOf(TagWindow()))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ object Packetlogger : Module(
private val networkSide by setting("Network Side", NetworkSide.ANY, "Side of the network to log packets from")
private val logTicks by setting("Log Ticks", true, "Show game ticks in the log")
private val scope by setting("Scope", Scope.ANY, "Scope of packets to log")
private val whitelist by setting("Whitelist Packets", listOf<String>(), "Packets to whitelist") { scope == Scope.WHITELIST }
private val blacklist by setting("Blacklist Packets", listOf<String>(), "Packets to blacklist") { scope == Scope.BLACKLIST }
private val whitelist by setting("Whitelist Packets", arrayListOf<String>(), "Packets to whitelist") { scope == Scope.WHITELIST }
private val blacklist by setting("Blacklist Packets", arrayListOf<String>(), "Packets to blacklist") { scope == Scope.BLACKLIST }
private val maxRecursionDepth by setting("Max Recursion Depth", 6, 1..10, 1, "Maximum recursion depth for packet serialization")
private val logConcurrent by setting("Build Data Concurrent", false, "Whether to serialize packets concurrently. Will not save packets in chronological order but wont lag the game.")

Expand Down Expand Up @@ -187,4 +187,4 @@ object Packetlogger : Module(
private fun Packet<*>.logSent() {
storageFlow.tryEmit("Sent at ${getTime(entryFormatter)}\n${dynamicString(maxRecursionDepth)}\n")
}
}
}
Loading