From 96f199ffcecf358357a7bef065b258f860f68135 Mon Sep 17 00:00:00 2001 From: Luligabi1 <33578169+Luligabi1@users.noreply.github.com> Date: Wed, 1 Nov 2023 14:15:58 -0300 Subject: [PATCH 1/4] You no longer can drop your Deep Learner while its screen is open (part of #88) --- .../handler/DeepLearnerScreenHandler.kt | 23 ++++++++++++++++--- gradle.properties | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/base/src/main/kotlin/dev/nathanpb/dml/screen/handler/DeepLearnerScreenHandler.kt b/base/src/main/kotlin/dev/nathanpb/dml/screen/handler/DeepLearnerScreenHandler.kt index e9504cdb..fe69282a 100644 --- a/base/src/main/kotlin/dev/nathanpb/dml/screen/handler/DeepLearnerScreenHandler.kt +++ b/base/src/main/kotlin/dev/nathanpb/dml/screen/handler/DeepLearnerScreenHandler.kt @@ -25,6 +25,7 @@ import dev.nathanpb.dml.data.DataModelData import dev.nathanpb.dml.data.DeepLearnerData import dev.nathanpb.dml.data.dataModel import dev.nathanpb.dml.identifier +import dev.nathanpb.dml.item.ITEM_DEEP_LEARNER import dev.nathanpb.dml.item.ItemDataModel import dev.nathanpb.dml.screen.handler.widget.WEntityShowcase import dev.nathanpb.dml.screen.handler.widget.WStylizedButton @@ -35,7 +36,6 @@ import dev.nathanpb.dml.utils.setStacks import io.github.cottonmc.cotton.gui.SyncedGuiDescription import io.github.cottonmc.cotton.gui.widget.* import io.github.cottonmc.cotton.gui.widget.data.Insets -import io.github.cottonmc.cotton.gui.widget.icon.Icon import io.github.cottonmc.cotton.gui.widget.icon.TextureIcon import net.fabricmc.api.EnvType import net.fabricmc.loader.api.FabricLoader @@ -243,7 +243,7 @@ class DeepLearnerScreenHandler ( update() } - root.add(createPlayerInventoryPanel(), 0, 5*18+6) + root.add(DeepLearnerPlayerInv(playerInventory), 0, 5*18+6) root.validate(this) update() } @@ -263,7 +263,7 @@ class DeepLearnerScreenHandler ( ): WItemSlot(inventory, 0, 2, 2, false) { init { - setFilter { stack -> + setInputFilter { stack -> stack.item is ItemDataModel && stack.dataModel.category != null } @@ -278,4 +278,21 @@ class DeepLearnerScreenHandler ( } } + + + // Prevent dropping your Deep Learner while it's up, duping it and all data models inside + class DeepLearnerPlayerInv( + playerInventory: PlayerInventory + ): WPlayerInvPanel(playerInventory) { + + init { + inventory.setOutputFilter { + !it.isOf(ITEM_DEEP_LEARNER) + } + hotbar.setOutputFilter { + !it.isOf(ITEM_DEEP_LEARNER) + } + } + + } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index b0ddc3eb..2949de51 100644 --- a/gradle.properties +++ b/gradle.properties @@ -26,7 +26,7 @@ fabric_kotlin_version=1.9.5+kotlin.1.8.22 # Other Dependencies ktdatataglib_version=1.6.7+1.20.1 -libguiVersion=8.0.0-beta.1+1.20-rc1 +libguiVersion=8.1.0+1.20.1 palVersion=1.8.0 reiVersion=12.0.625 energyVersion=2.3.0 From 28ea8e1daf0419a98056b364c44052a47ec1356c Mon Sep 17 00:00:00 2001 From: Luligabi1 <33578169+Luligabi1@users.noreply.github.com> Date: Wed, 1 Nov 2023 14:18:42 -0300 Subject: [PATCH 2/4] Use LibGUI's non-deprecated setInputFilter --- .../nathanpb/dml/screen/handler/LootFabricatorHandler.kt | 7 ++----- .../modular_armor/screen/MatterCondenserScreenHandler.kt | 4 ++-- .../dml/modular_armor/screen/ModularArmorScreenHandler.kt | 6 +----- 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/base/src/main/kotlin/dev/nathanpb/dml/screen/handler/LootFabricatorHandler.kt b/base/src/main/kotlin/dev/nathanpb/dml/screen/handler/LootFabricatorHandler.kt index 60ab7ed4..fad7bb7f 100644 --- a/base/src/main/kotlin/dev/nathanpb/dml/screen/handler/LootFabricatorHandler.kt +++ b/base/src/main/kotlin/dev/nathanpb/dml/screen/handler/LootFabricatorHandler.kt @@ -20,10 +20,8 @@ package dev.nathanpb.dml.screen.handler -import dev.nathanpb.dml.MOD_ID import dev.nathanpb.dml.identifier import dev.nathanpb.dml.recipe.LootFabricatorRecipe -import dev.nathanpb.dml.screen.handler.slot.WTooltippedItemSlot import dev.nathanpb.dml.utils.RenderUtils import io.github.cottonmc.cotton.gui.SyncedGuiDescription import io.github.cottonmc.cotton.gui.widget.WBar @@ -35,7 +33,6 @@ import net.minecraft.entity.player.PlayerEntity import net.minecraft.entity.player.PlayerInventory import net.minecraft.inventory.SimpleInventory import net.minecraft.screen.ScreenHandlerContext -import net.minecraft.text.Text class LootFabricatorHandler( syncId: Int, @@ -53,7 +50,7 @@ class LootFabricatorHandler( setRootPanel(root) val inputSlot = WItemSlot(blockInventory, 0, 1, 1, false).apply { - setFilter { stack -> + setInputFilter { stack -> world.recipeManager.values().filterIsInstance() .any { it.input.test(stack) } } @@ -70,7 +67,7 @@ class LootFabricatorHandler( (0 until 9).forEach { val x = (it % 3) val y = (it / 3) - val slot = WItemSlot.of(blockInventory, it + 1).setFilter { false } + val slot = WItemSlot.of(blockInventory, it + 1).setInputFilter { false } root.add(slot, x + 5, y + 1) } diff --git a/modular-armor/src/main/kotlin/dev/nathanpb/dml/modular_armor/screen/MatterCondenserScreenHandler.kt b/modular-armor/src/main/kotlin/dev/nathanpb/dml/modular_armor/screen/MatterCondenserScreenHandler.kt index 98b77a3d..a3872e2f 100644 --- a/modular-armor/src/main/kotlin/dev/nathanpb/dml/modular_armor/screen/MatterCondenserScreenHandler.kt +++ b/modular-armor/src/main/kotlin/dev/nathanpb/dml/modular_armor/screen/MatterCondenserScreenHandler.kt @@ -65,7 +65,7 @@ class MatterCondenserScreenHandler( val slots = WPlainPanel() val armorSlot = WTooltippedItemSlot.of(blockInventory, 0, true, Text.translatable("gui.${MOD_ID}.glitch_armor_only")).apply { - setFilter { + setInputFilter { it.item is ItemModularGlitchArmor && !ModularArmorData(it).tier().isMaxTier() } } @@ -74,7 +74,7 @@ class MatterCondenserScreenHandler( val matterSlots = (1..6).map { WItemSlot(blockInventory, it, 1, 1, false).apply { - setFilter { stack -> + setInputFilter { stack -> stack.item is ItemPristineMatter } diff --git a/modular-armor/src/main/kotlin/dev/nathanpb/dml/modular_armor/screen/ModularArmorScreenHandler.kt b/modular-armor/src/main/kotlin/dev/nathanpb/dml/modular_armor/screen/ModularArmorScreenHandler.kt index b539dc40..36f50e43 100644 --- a/modular-armor/src/main/kotlin/dev/nathanpb/dml/modular_armor/screen/ModularArmorScreenHandler.kt +++ b/modular-armor/src/main/kotlin/dev/nathanpb/dml/modular_armor/screen/ModularArmorScreenHandler.kt @@ -20,8 +20,6 @@ package dev.nathanpb.dml.modular_armor.screen -import com.sun.java.accessibility.util.SwingEventMonitor.addChangeListener -import dev.nathanpb.dml.MOD_ID import dev.nathanpb.dml.data.dataModel import dev.nathanpb.dml.identifier import dev.nathanpb.dml.item.ItemDataModel @@ -30,7 +28,6 @@ import dev.nathanpb.dml.modular_armor.core.ModularEffectRegistry import dev.nathanpb.dml.modular_armor.data.ModularArmorData import dev.nathanpb.dml.modular_armor.net.C2S_MODULAR_EFFECT_TOGGLE import dev.nathanpb.dml.screen.handler.registerScreenHandlerForItemStack -import dev.nathanpb.dml.screen.handler.slot.WTooltippedItemSlot import dev.nathanpb.dml.utils.RenderUtils import dev.nathanpb.dml.utils.takeOrNull import io.github.cottonmc.cotton.gui.SyncedGuiDescription @@ -46,7 +43,6 @@ import net.minecraft.inventory.SimpleInventory import net.minecraft.item.ItemStack import net.minecraft.network.PacketByteBuf import net.minecraft.screen.ArrayPropertyDelegate -import net.minecraft.text.Text import net.minecraft.util.Hand import net.minecraft.util.Identifier @@ -102,7 +98,7 @@ class ModularArmorScreenHandler( } val dataModelSlot = WItemSlot(blockInventory, 0, 1, 1, false).apply { - setFilter { + setInputFilter { it.isEmpty || ( (it.item as? ItemDataModel)?.category != null && data.tier().ordinal >= it.dataModel.tier().ordinal From 8cebf4243e7c248b3c3271a4016019312b3b0ce2 Mon Sep 17 00:00:00 2001 From: Luligabi1 <33578169+Luligabi1@users.noreply.github.com> Date: Thu, 2 Nov 2023 15:56:56 -0300 Subject: [PATCH 3/4] Fix #140 --- .../dev/nathanpb/dml/blockEntity/BlockEntityTrialKeystone.kt | 2 +- base/src/main/kotlin/dev/nathanpb/dml/utils/Math.kt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/base/src/main/kotlin/dev/nathanpb/dml/blockEntity/BlockEntityTrialKeystone.kt b/base/src/main/kotlin/dev/nathanpb/dml/blockEntity/BlockEntityTrialKeystone.kt index bb43e47f..c99ef2d9 100644 --- a/base/src/main/kotlin/dev/nathanpb/dml/blockEntity/BlockEntityTrialKeystone.kt +++ b/base/src/main/kotlin/dev/nathanpb/dml/blockEntity/BlockEntityTrialKeystone.kt @@ -273,7 +273,7 @@ class BlockEntityTrialKeystone(pos: BlockPos, state: BlockState) : val innerBlockPos = BlockPos(x, y, z) if ( innerBlockPos != pos - && innerBlockPos.getSquaredDistance(pos) <= config.trial.arenaRadius.squared() + && innerBlockPos.getSquaredDistance(pos) < config.trial.arenaRadius.squared() && world?.getBlockState(innerBlockPos)?.isAir != true ) { list += innerBlockPos diff --git a/base/src/main/kotlin/dev/nathanpb/dml/utils/Math.kt b/base/src/main/kotlin/dev/nathanpb/dml/utils/Math.kt index a6ceb09d..24ff9e4e 100644 --- a/base/src/main/kotlin/dev/nathanpb/dml/utils/Math.kt +++ b/base/src/main/kotlin/dev/nathanpb/dml/utils/Math.kt @@ -24,6 +24,7 @@ import kotlin.random.Random fun Double.lerp(min: Double, max: Double) = (1 - this) * min + this * max fun Int.lerp(min: Double, max: Double) = (1 - this) * min + this * max +fun Double.squared() = this * this fun Int.squared() = this * this // https://stackoverflow.com/a/35701777/9893963 From 65abbe64c453e2e7e7e5ac7d6b4fc6fcf2cd4e0f Mon Sep 17 00:00:00 2001 From: Luligabi1 <33578169+Luligabi1@users.noreply.github.com> Date: Thu, 2 Nov 2023 23:37:21 -0300 Subject: [PATCH 4/4] Add trial grief whitelist block tag (part of #141) --- base/src/main/kotlin/dev/nathanpb/dml/misc/Tags.kt | 10 ++++++++++ .../dev/nathanpb/dml/trial/TrialGriefPrevention.kt | 10 +++------- .../tags/blocks/trial_grief_whitelist.json | 7 +++++++ 3 files changed, 20 insertions(+), 7 deletions(-) create mode 100644 base/src/main/kotlin/dev/nathanpb/dml/misc/Tags.kt create mode 100644 base/src/main/resources/data/dml-refabricated/tags/blocks/trial_grief_whitelist.json diff --git a/base/src/main/kotlin/dev/nathanpb/dml/misc/Tags.kt b/base/src/main/kotlin/dev/nathanpb/dml/misc/Tags.kt new file mode 100644 index 00000000..4a8dfb0e --- /dev/null +++ b/base/src/main/kotlin/dev/nathanpb/dml/misc/Tags.kt @@ -0,0 +1,10 @@ +package dev.nathanpb.dml.misc + +import dev.nathanpb.dml.identifier +import net.minecraft.block.Block +import net.minecraft.registry.RegistryKeys + +import net.minecraft.registry.tag.TagKey + + +val TRIAL_GRIEF_WHITELIST: TagKey = TagKey.of(RegistryKeys.BLOCK, identifier("trial_grief_whitelist")) \ No newline at end of file diff --git a/base/src/main/kotlin/dev/nathanpb/dml/trial/TrialGriefPrevention.kt b/base/src/main/kotlin/dev/nathanpb/dml/trial/TrialGriefPrevention.kt index 529b63cb..26e92cd1 100644 --- a/base/src/main/kotlin/dev/nathanpb/dml/trial/TrialGriefPrevention.kt +++ b/base/src/main/kotlin/dev/nathanpb/dml/trial/TrialGriefPrevention.kt @@ -20,13 +20,13 @@ package dev.nathanpb.dml.trial import dev.nathanpb.dml.config +import dev.nathanpb.dml.misc.TRIAL_GRIEF_WHITELIST import dev.nathanpb.dml.utils.runningTrials import dev.nathanpb.dml.utils.squared import dev.nathanpb.dml.utils.toBlockPos import dev.nathanpb.dml.utils.toVec3i import net.fabricmc.fabric.api.event.player.AttackBlockCallback import net.fabricmc.fabric.api.event.player.UseBlockCallback -import net.minecraft.block.Blocks import net.minecraft.entity.Entity import net.minecraft.entity.damage.DamageSource import net.minecraft.entity.mob.EndermanEntity @@ -39,7 +39,6 @@ import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Direction import net.minecraft.util.math.Vec3d import net.minecraft.world.World -import net.minecraft.world.explosion.Explosion import net.minecraft.world.explosion.ExplosionBehavior class TrialGriefPrevention : AttackBlockCallback, UseBlockCallback { @@ -65,11 +64,8 @@ class TrialGriefPrevention : AttackBlockCallback, UseBlockCallback { !world.isClient && config.trial.interactGriefPrevention && isBlockProtected(world, pos) - && world.getBlockState(pos)?.run { - block !== Blocks.CHEST - && block !== Blocks.TRAPPED_CHEST - && "grave" !in Registries.BLOCK.getId(block).path - } != false + && !world.getBlockState(pos).isIn(TRIAL_GRIEF_WHITELIST) + && "grave" !in Registries.BLOCK.getId(world.getBlockState(pos).block).path ) { ActionResult.FAIL } else ActionResult.PASS diff --git a/base/src/main/resources/data/dml-refabricated/tags/blocks/trial_grief_whitelist.json b/base/src/main/resources/data/dml-refabricated/tags/blocks/trial_grief_whitelist.json new file mode 100644 index 00000000..b5ab71de --- /dev/null +++ b/base/src/main/resources/data/dml-refabricated/tags/blocks/trial_grief_whitelist.json @@ -0,0 +1,7 @@ +{ + "values": [ + "#c:chests", + {"id": "yigd:grave", "required": false}, + {"id": "gravestones:gravestone", "required": false} + ] +}