Skip to content

Commit

Permalink
progress - maybe beta tomorrow?
Browse files Browse the repository at this point in the history
  • Loading branch information
btwonion committed Jun 13, 2024
1 parent f949bae commit 2994efd
Show file tree
Hide file tree
Showing 27 changed files with 263 additions and 366 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
!run/mods/
**/build/
.kotlin
**/generated
**/.cache
4 changes: 2 additions & 2 deletions telekinesis-fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ plugins {
signing
}

val featureVersion = "2.4.1"
val featureVersion = "3.0.0"
val mcVersion = property("mcVersion")!!.toString()
val mcVersionRange = property("mcVersionRange")!!.toString()
version = "$featureVersion-$mcVersion"
Expand Down Expand Up @@ -83,7 +83,7 @@ dependencies {

include(implementation(annotationProcessor("com.github.bawnorton.mixinsquared:mixinsquared-fabric:0.1.1")!!)!!)

include(implementation("com.akuleshov7:ktoml-core-jvm:0.5.1")!!)
include(modImplementation("dev.nyon:konfig:2.0.1-1.20.4")!!)
}

val javaVersion = property("javaVer")!!.toString()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dev.nyon.telekinesis.mixins;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.entity.vehicle.AbstractMinecartContainer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import static dev.nyon.telekinesis.utils.MixinHelper.threadLocal;

@Mixin(AbstractMinecartContainer.class)
public class AbstractMinecartContainerMixin {

@WrapOperation(
method = "destroy(Lnet/minecraft/world/damagesource/DamageSource;)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/vehicle/AbstractMinecart;destroy(Lnet/minecraft/world/damagesource/DamageSource;)V"
)
)
private void checkForPlayer(
AbstractMinecartContainer instance,
DamageSource source,
Operation<Void> original
) {
if (!(source.getEntity() instanceof ServerPlayer player)) {
original.call(instance, source);
return;
}

ServerPlayer previous = threadLocal.get();
threadLocal.set(player);
try {
original.call(instance, source);
} finally {
threadLocal.set(previous);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@
import java.util.ArrayList;
import java.util.List;

import static dev.nyon.telekinesis.utils.MixinHelper.threadLocal;

@Mixin(Block.class)
public abstract class BlockMixin {

@Unique
private static final ThreadLocal<ServerPlayer> threadLocal = new ThreadLocal<>();

@ModifyExpressionValue(
method = "dropResources(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/entity/BlockEntity;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/world/item/ItemStack;)V",
at = @At(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@
/*? if >1.20.2 {*/
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.item.Item;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
/*?}*/
/*?}*/

@Mixin(ChestBoat.class)
public class ChestBoatMixin {

/*? if >1.20.2 {*/
@Unique
private static final ThreadLocal<ServerPlayer> threadLocal = new ThreadLocal<>();

@WrapOperation(
method = "destroy(Lnet/minecraft/world/damagesource/DamageSource;)V",
at = @At(
Expand All @@ -34,8 +29,9 @@ private void checkForPlayer(
Operation<Void> original,
DamageSource source
) {
MixinHelper.prepareVehicleServerPlayer(instance, item, original, source, threadLocal);
MixinHelper.prepareVehicleServerPlayer(instance, item, original, source);
}

/*?}*/

// TODO: boat inventory does still not work!!! as well as furnaces!!
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,19 @@
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import dev.nyon.telekinesis.utils.MixinHelper;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.vehicle.MinecartTNT;
import org.spongepowered.asm.mixin.Mixin;

/*? if >1.20.2 {*/
import com.llamalad7.mixinextras.injector.ModifyExpressionValue;
import net.minecraft.world.damagesource.DamageSource;
import net.minecraft.world.item.Item;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
/*?}*/

@Mixin(MinecartTNT.class)
public class MinecartTNTMixin {

/*? if >1.20.2 {*/
@Unique
private static final ThreadLocal<ServerPlayer> threadLocal = new ThreadLocal<>();

@WrapOperation(
method = "destroy(Lnet/minecraft/world/damagesource/DamageSource;)V",
at = @At(
Expand All @@ -35,7 +29,7 @@ private void checkForPlayer(
Operation<Void> original,
DamageSource source
) {
MixinHelper.prepareVehicleServerPlayer(instance, dropItem, original, source, threadLocal);
MixinHelper.prepareVehicleServerPlayer(instance, dropItem, original, source);
}
/*?}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;

import static dev.nyon.telekinesis.utils.MixinHelper.threadLocal;

@Mixin(Sheep.class)
public abstract class SheepMixin {

@Unique
private static final ThreadLocal<ServerPlayer> threadLocal = new ThreadLocal<>();

@WrapOperation(
method = "mobInteract",
at = @At(
Expand All @@ -35,7 +33,7 @@ private void prepareThreadLocalForShearing(
Player _player,
InteractionHand hand
) {
MixinHelper.prepareShearableServerPlayer(instance, source, original, _player, threadLocal);
MixinHelper.prepareShearableServerPlayer(instance, source, original, _player);
}

@ModifyExpressionValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

import static dev.nyon.telekinesis.utils.MixinHelper.threadLocal;

@Mixin(SnowGolem.class)
public class SnowGolemMixin {

@Unique
private static final ThreadLocal<ServerPlayer> threadLocal = new ThreadLocal<>();

@WrapOperation(
method = "mobInteract",
at = @At(
Expand All @@ -34,7 +33,7 @@ private void prepareThreadLocalForShearing(
Operation<Void> original,
Player _player
) {
MixinHelper.prepareShearableServerPlayer(instance, source, original, _player, threadLocal);
MixinHelper.prepareShearableServerPlayer(instance, source, original, _player);
}

@ModifyArg(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

import java.util.ArrayList;

import static dev.nyon.telekinesis.utils.MixinHelper.threadLocal;

@Mixin(SpawnerBlock.class)
public class SpawnerBlockMixin {
@Unique
private static final ThreadLocal<ServerPlayer> threadLocal = new ThreadLocal<>();

@ModifyArgs(
method = "spawnAfterBreak",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
package dev.nyon.telekinesis.mixins;

import com.llamalad7.mixinextras.injector.v2.WrapWithCondition;
import dev.nyon.telekinesis.DropEvent;
import dev.nyon.telekinesis.TelekinesisPolicy;
import dev.nyon.telekinesis.utils.MixinHelper;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SweetBerryBushBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import org.apache.commons.lang3.mutable.MutableInt;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Mixin(SweetBerryBushBlock.class)
public class SweetBerryBushBlockMixin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;

import static dev.nyon.telekinesis.utils.MixinHelper.threadLocal;

@Pseudo
@Mixin(targets = "net.minecraft.world.entity.vehicle.VehicleEntity")
public class VehicleEntityMixin {

@Unique
private static final ThreadLocal<ServerPlayer> threadLocal = new ThreadLocal<>();

@WrapOperation(
method = "destroy(Lnet/minecraft/world/damagesource/DamageSource;)V",
at = @At(
Expand All @@ -34,7 +32,7 @@ private void checkForPlayer(
Operation<Void> original,
DamageSource source
) {
MixinHelper.prepareVehicleServerPlayer(instance, dropItem, original, source, threadLocal);
MixinHelper.prepareVehicleServerPlayer(instance, dropItem, original, source);
}

@WrapWithCondition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import java.util.Objects;

public class MixinHelper {
public static final ThreadLocal<ServerPlayer> threadLocal = new ThreadLocal<>();

public static boolean wrapWithConditionPlayerItemSingle(
ServerPlayer player,
ItemStack item
Expand Down Expand Up @@ -109,8 +111,7 @@ public static void prepareVehicleServerPlayer(
VehicleEntity instance,
Item item,
Operation<Void> original,
DamageSource source,
ThreadLocal<ServerPlayer> threadLocal
DamageSource source
) {
if (!(source.getEntity() instanceof ServerPlayer player)) {
original.call(instance, item);
Expand All @@ -130,8 +131,7 @@ public static void prepareShearableServerPlayer(
Shearable instance,
SoundSource source,
Operation<Void> original,
Player _player,
ThreadLocal<ServerPlayer> threadLocal
Player _player
) {
if (!(_player instanceof ServerPlayer player)) {
original.call(instance, source);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package dev.nyon.telekinesis

import dev.nyon.telekinesis.config.config
import net.fabricmc.fabric.api.event.Event
import net.fabricmc.fabric.api.event.EventFactory
import net.minecraft.server.level.ServerPlayer
import net.minecraft.world.item.ItemStack
import net.minecraft.world.item.enchantment.EnchantmentHelper
import org.apache.commons.lang3.mutable.MutableInt

object DropEvent {
Expand All @@ -14,6 +16,18 @@ object DropEvent {
}
}
}

@Suppress("unused")
private val listener = event.register { items, exp, player, tool ->
if (config.needSneak && !player.isCrouching) return@register
if (config.needEnchantment && !EnchantmentHelper.hasTag(tool, tagKey)) return@register

if (config.itemsAllowed) items.removeIf(player::addItem)
if (config.expAllowed) {
player.giveExperiencePoints(exp.value)
exp.setValue(0)
}
}
}

fun interface DropEventConsumer {
Expand Down
10 changes: 9 additions & 1 deletion telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

package dev.nyon.telekinesis

import dev.nyon.konfig.config.config
import dev.nyon.konfig.config.loadConfig
import dev.nyon.telekinesis.config.Config
import net.fabricmc.loader.api.FabricLoader
import dev.nyon.telekinesis.config.config as internalConfig

/*? if <=1.20.6 {*//*
lateinit var telekinesis: TelekinesisEnchantment
*//*?}*/

fun init() {
loadConfig()
config(FabricLoader.getInstance().configDir.resolve("telekinesis.json"), 1, Config()) { _, _ -> null }
internalConfig = loadConfig()
DropEvent
}
Loading

0 comments on commit 2994efd

Please sign in to comment.