diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AllayMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AllayMixin.java index ab8324f..05abdff 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AllayMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/AllayMixin.java @@ -52,8 +52,7 @@ public void redirectInventoryDrops( return; } - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis( - TelekinesisPolicy.MobDrops, + boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, serverPlayer, serverPlayer.getMainHandItem(), player -> instance.forEach(item -> { diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/BlockMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/BlockMixin.java index 1d4e013..37695ad 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/BlockMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/BlockMixin.java @@ -69,28 +69,21 @@ private static void manipulateDrops( if (!(level instanceof ServerLevel serverLevel)) return; Block block = blockState.getBlock(); if (EnchantmentHelper.hasSilkTouch(itemStack)) return; - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesisBlock(TelekinesisPolicy.ExpDrops, - entity, - itemStack, - player -> { - int expToAdd = 0; - if (block instanceof DropExperienceBlock expBlock) - expToAdd = ((DropExperienceBlockAccessor) expBlock).getXpRange() - .sample(level.random); - if (block instanceof RedStoneOreBlock) expToAdd = 1 + level.random.nextInt(5); - if (block instanceof SculkCatalystBlock catalystBlock) - expToAdd = ((CatalystBlockAccessor) catalystBlock).getXpRange() - .sample(level.random); - if (block instanceof SculkSensorBlock || block instanceof SculkShriekerBlock) - expToAdd = ConstantInt.of(5) - .sample(level.random); - if (block instanceof SpawnerBlock) expToAdd = level.random.nextInt(15) + level.random.nextInt(15); - if (block instanceof InfestedBlock infestedBlock) - infestedBlock.spawnAfterBreak(blockState, serverLevel, blockPos, itemStack, true); - PlayerUtils.addExpToPlayer(player, expToAdd); - } - ); + boolean hasTelekinesis = TelekinesisUtils.handleTelekinesisBlock(TelekinesisPolicy.ExpDrops, entity, itemStack, player -> { + int expToAdd = 0; + if (block instanceof DropExperienceBlock expBlock) expToAdd = ((DropExperienceBlockAccessor) expBlock).getXpRange() + .sample(level.random); + if (block instanceof RedStoneOreBlock) expToAdd = 1 + level.random.nextInt(5); + if (block instanceof SculkCatalystBlock catalystBlock) expToAdd = ((CatalystBlockAccessor) catalystBlock).getXpRange() + .sample(level.random); + if (block instanceof SculkSensorBlock || block instanceof SculkShriekerBlock) expToAdd = ConstantInt.of(5) + .sample(level.random); + if (block instanceof SpawnerBlock) expToAdd = level.random.nextInt(15) + level.random.nextInt(15); + if (block instanceof InfestedBlock infestedBlock) + infestedBlock.spawnAfterBreak(blockState, serverLevel, blockPos, itemStack, true); + PlayerUtils.addExpToPlayer(player, expToAdd); + }); if (hasTelekinesis) ci.cancel(); } -} \ No newline at end of file +} diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnchantmentsMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnchantmentsMixin.java index 5530264..7eb9455 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnchantmentsMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/EnchantmentsMixin.java @@ -31,11 +31,7 @@ private static void registerTelekinesis( if (!isTelekinesisRegistered) { MainKt.setTelekinesis(new TelekinesisEnchantment()); isTelekinesisRegistered = true; - Registry.register( - BuiltInRegistries.ENCHANTMENT, - new ResourceLocation("telekinesis", "telekinesis"), - MainKt.getTelekinesis() - ); + Registry.register(BuiltInRegistries.ENCHANTMENT, new ResourceLocation("telekinesis", "telekinesis"), MainKt.getTelekinesis()); } } } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java index 0606c71..03b1f98 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java @@ -61,12 +61,9 @@ public void redirectCommonDrops( boolean bl ) { args.>set(2, item -> { - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, - damageSource, - player -> { - if (!player.addItem(item)) livingEntity.spawnAtLocation(item); - } - ); + boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, damageSource, player -> { + if (!player.addItem(item)) livingEntity.spawnAtLocation(item); + }); if (!hasTelekinesis) livingEntity.spawnAtLocation(item); }); diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SnowgolemMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SnowgolemMixin.java index fae12f6..574a010 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SnowgolemMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SnowgolemMixin.java @@ -37,12 +37,9 @@ public void manipulateWoolDrops( ItemStack item = new ItemStack(Items.CARVED_PUMPKIN); - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ShearingDrops, - player, - serverPlayer -> { - if (!serverPlayer.addItem(item)) instance.spawnAtLocation(item, 1.7F); - } - ); + boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ShearingDrops, player, serverPlayer -> { + if (!serverPlayer.addItem(item)) instance.spawnAtLocation(item, 1.7F); + }); if (!hasTelekinesis) instance.spawnAtLocation(item, 1.7F); } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java index 766e03d..996ef00 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java @@ -28,16 +28,12 @@ protected ItemEntity redirectEquipmentDrop( final var attacker = instance.getLastAttacker(); if (!(attacker instanceof ServerPlayer serverPlayer)) return original.call(instance, stack); - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, - serverPlayer, - null, - player -> { - if (!player.addItem(stack.asItem() - .getDefaultInstance())) instance.spawnAtLocation(stack); - } - ); + boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, serverPlayer, null, player -> { + if (!player.addItem(stack.asItem() + .getDefaultInstance())) instance.spawnAtLocation(stack); + }); if (!hasTelekinesis) return original.call(instance, stack); else return null; } -} \ No newline at end of file +} diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/EntityUtils.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/EntityUtils.java index 304c214..fd3548e 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/EntityUtils.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/EntityUtils.java @@ -8,16 +8,25 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; -import java.util.List; import java.util.concurrent.atomic.AtomicReference; public class EntityUtils { - public static boolean spawnAtLocationInject(LivingEntity entity, ItemLike item) { - return spawnAtLocationInject(entity, item.asItem().getDefaultInstance()); + public static boolean spawnAtLocationInject( + LivingEntity entity, + ItemLike item + ) { + return spawnAtLocationInject( + entity, + item.asItem() + .getDefaultInstance() + ); } - public static boolean spawnAtLocationInject(LivingEntity entity, ItemStack item) { + public static boolean spawnAtLocationInject( + LivingEntity entity, + ItemStack item + ) { final var attacker = entity.getLastAttacker(); if (!(attacker instanceof ServerPlayer serverPlayer)) return true; @@ -32,7 +41,10 @@ public static boolean spawnAtLocationInject(LivingEntity entity, ItemStack item) return !hasTelekinesis; } - public static Item getDropItemInject(Item original, DamageSource source) { + public static Item getDropItemInject( + Item original, + DamageSource source + ) { final var attacker = source.getEntity(); if (!(attacker instanceof ServerPlayer)) return original; diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/PlayerUtils.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/PlayerUtils.java index 238b014..e6ad9ba 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/PlayerUtils.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/PlayerUtils.java @@ -21,9 +21,7 @@ private static int repairPlayerItems( Player player, Integer exp ) { - Map.Entry entry = EnchantmentHelper.getRandomItemWith(Enchantments.MENDING, - player, - ItemStack::isDamaged); + Map.Entry entry = EnchantmentHelper.getRandomItemWith(Enchantments.MENDING, player, ItemStack::isDamaged); if (entry != null) { ItemStack itemStack = entry.getValue(); int j = Math.min(exp * 2, itemStack.getDamageValue()); diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/TelekinesisUtils.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/TelekinesisUtils.java index f57cbdc..0be0142 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/TelekinesisUtils.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/TelekinesisUtils.java @@ -75,16 +75,14 @@ private static boolean playerMeetsConditions( boolean hasArmorTelekinesis = player.getInventory().armor.stream() .allMatch(item -> EnchantmentHelper.getItemEnchantmentLevel(MainKt.getTelekinesis(), item) > 0); boolean hasMainHandTelekinesis = (itemStack != null && EnchantmentHelper.getItemEnchantmentLevel(MainKt.getTelekinesis(), - itemStack) > 0) || EnchantmentHelper.getItemEnchantmentLevel(MainKt.getTelekinesis(), - player.getMainHandItem()) > 0; - boolean hasOffHandTelekinesis = EnchantmentHelper.getItemEnchantmentLevel(MainKt.getTelekinesis(), - player.getOffhandItem()) > 0; + itemStack + ) > 0) || EnchantmentHelper.getItemEnchantmentLevel(MainKt.getTelekinesis(), player.getMainHandItem()) > 0; + boolean hasOffHandTelekinesis = EnchantmentHelper.getItemEnchantmentLevel(MainKt.getTelekinesis(), player.getOffhandItem()) > 0; if (isEnabledByDefault) conditionsMet = true; else switch (policy) { case ExpDrops -> conditionsMet = hasArmorTelekinesis || hasMainHandTelekinesis || hasOffHandTelekinesis; - case MobDrops, ShearingDrops, VehicleDrops, FishingDrops -> - conditionsMet = hasMainHandTelekinesis || hasOffHandTelekinesis; + case MobDrops, ShearingDrops, VehicleDrops, FishingDrops -> conditionsMet = hasMainHandTelekinesis || hasOffHandTelekinesis; case BlockDrops -> conditionsMet = hasMainHandTelekinesis; } diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfig.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfig.kt index f44f9a4..1e6f973 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfig.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfig.kt @@ -59,8 +59,9 @@ lateinit var configPath: Path fun saveConfig() = configPath.writeText(Toml.encodeToString(TelekinesisConfig.serializer(), config)) fun loadConfig() { - configPath = FabricLoader.getInstance().configDir.toAbsolutePath().resolve("telekinesis.toml") - .also { if (!it.exists()) it.createFile() } + configPath = + FabricLoader.getInstance().configDir.toAbsolutePath().resolve("telekinesis.toml") + .also { if (!it.exists()) it.createFile() } if (configPath.readText().isEmpty()) { saveConfig() @@ -72,4 +73,4 @@ fun loadConfig() { } catch (e: Exception) { saveConfig() } -} \ No newline at end of file +} diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfigScreen.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfigScreen.kt index 629c929..b0b1986 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfigScreen.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisConfigScreen.kt @@ -26,12 +26,12 @@ fun YetAnotherConfigLib.Builder.appendOptionCategory() { .name(Component.translatable("menu.telekinesis.config.general.onbydefault")) .description( OptionDescription - .of(Component.translatable("menu.telekinesis.config.general.onbydefault.description")), + .of(Component.translatable("menu.telekinesis.config.general.onbydefault.description")) ) .binding(config.onByDefault, { config.onByDefault }, { config.onByDefault = it }) .controller { TickBoxControllerBuilder.create(it) - }.build(), + }.build() ) .option( Option.createBuilder() @@ -39,13 +39,13 @@ fun YetAnotherConfigLib.Builder.appendOptionCategory() { .description( OptionDescription .of( - Component.translatable("menu.telekinesis.config.general.onlywhilesneaking.description"), - ), + Component.translatable("menu.telekinesis.config.general.onlywhilesneaking.description") + ) ) .binding(config.onlyOnSneak, { config.onlyOnSneak }, { config.onlyOnSneak = it }) .controller { TickBoxControllerBuilder.create(it) - }.build(), + }.build() ) .option( Option.createBuilder() @@ -53,86 +53,86 @@ fun YetAnotherConfigLib.Builder.appendOptionCategory() { .description( OptionDescription.of( Component.translatable("menu.telekinesis.config.general.enchantment.description1"), - Component.translatable("menu.telekinesis.config.general.enchantment.description2"), - ), + Component.translatable("menu.telekinesis.config.general.enchantment.description2") + ) ) .binding(config.enchantment, { config.enchantment }, { config.enchantment = it }) .controller { TickBoxControllerBuilder.create(it) - }.build(), + }.build() ) .option( Option.createBuilder() .name(Component.translatable("menu.telekinesis.config.general.blockdrops")) .description( OptionDescription - .of(Component.translatable("menu.telekinesis.config.general.blockdrops.description")), + .of(Component.translatable("menu.telekinesis.config.general.blockdrops.description")) ) .binding(config.blockDrops, { config.blockDrops }, { config.blockDrops = it }) .controller { TickBoxControllerBuilder.create(it) - }.build(), + }.build() ) .option( Option.createBuilder() .name(Component.translatable("menu.telekinesis.config.general.expdrops")) .description( OptionDescription - .of(Component.translatable("menu.telekinesis.config.general.expdrops.description")), + .of(Component.translatable("menu.telekinesis.config.general.expdrops.description")) ) .binding(config.expDrops, { config.expDrops }, { config.expDrops = it }) .controller { TickBoxControllerBuilder.create(it) - }.build(), + }.build() ) .option( Option.createBuilder() .name(Component.translatable("menu.telekinesis.config.general.mobdrops")) .description( OptionDescription - .of(Component.translatable("menu.telekinesis.config.general.mobdrops.description")), + .of(Component.translatable("menu.telekinesis.config.general.mobdrops.description")) ) .binding(config.mobDrops, { config.mobDrops }, { config.mobDrops = it }) .controller { TickBoxControllerBuilder.create(it) - }.build(), + }.build() ) .option( Option.createBuilder() .name(Component.translatable("menu.telekinesis.config.general.vehicledrops")) .description( OptionDescription - .of(Component.translatable("menu.telekinesis.config.general.vehicledrops.description")), + .of(Component.translatable("menu.telekinesis.config.general.vehicledrops.description")) ) .binding(config.vehicleDrops, { config.vehicleDrops }, { config.vehicleDrops = it }) .controller { TickBoxControllerBuilder.create(it) - }.build(), + }.build() ) .option( Option.createBuilder() .name(Component.translatable("menu.telekinesis.config.general.shearingdrops")) .description( OptionDescription - .of(Component.translatable("menu.telekinesis.config.general.shearingdrops.description")), + .of(Component.translatable("menu.telekinesis.config.general.shearingdrops.description")) ) .binding(config.shearingDrops, { config.shearingDrops }, { config.shearingDrops = it }) .controller { TickBoxControllerBuilder.create(it) - }.build(), + }.build() ) .option( Option.createBuilder() .name(Component.translatable("menu.telekinesis.config.general.fishingdrops")) .description( OptionDescription - .of(Component.translatable("menu.telekinesis.config.general.fishingdrops.description")), + .of(Component.translatable("menu.telekinesis.config.general.fishingdrops.description")) ) .binding(config.fishingDrops, { config.fishingDrops }, { config.fishingDrops = it }) .controller { TickBoxControllerBuilder.create(it) - }.build(), + }.build() ) - .build(), + .build() ) } diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt index 309a59b..dd9f8e1 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt @@ -17,8 +17,8 @@ class TelekinesisEnchantment : Enchantment( dynamicCost(25, 25), dynamicCost(75, 25), 5, - *EquipmentSlot.entries.toTypedArray(), - ), + *EquipmentSlot.entries.toTypedArray() + ) ) { override fun getFullname(i: Int): Component = Component.translatable("enchantment.telekinesis.telekinesis.name").withStyle(Style.EMPTY.withColor(0xFFB64C)) diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisPolicy.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisPolicy.kt index 72b27cb..3c8e44c 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisPolicy.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisPolicy.kt @@ -8,12 +8,13 @@ enum class TelekinesisPolicy { ShearingDrops, FishingDrops; - fun isEnabled(): Boolean = when (this) { - BlockDrops -> config.blockDrops - ExpDrops -> config.expDrops - MobDrops -> config.mobDrops - VehicleDrops -> config.vehicleDrops - ShearingDrops -> config.shearingDrops - FishingDrops -> config.fishingDrops - } -} \ No newline at end of file + fun isEnabled(): Boolean = + when (this) { + BlockDrops -> config.blockDrops + ExpDrops -> config.expDrops + MobDrops -> config.mobDrops + VehicleDrops -> config.vehicleDrops + ShearingDrops -> config.shearingDrops + FishingDrops -> config.fishingDrops + } +}