From bb32ea616483f01a75ba35d8e681971d571e4e07 Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Wed, 20 Aug 2025 00:57:28 -0500 Subject: [PATCH] All entities with chat data can now open doors and path find through doors --- CHANGELOG.md | 6 ++++ .../com/owlmaddie/mixin/MixinMobEntity.java | 35 +++++++++++++++++++ .../com/owlmaddie/mixin/MixinMobEntity.java | 34 ++++++++++++++++++ .../com/owlmaddie/mixin/MixinMobEntity.java | 34 ++++++++++++++++++ .../com/owlmaddie/mixin/MixinMobEntity.java | 34 ++++++++++++++++++ .../com/owlmaddie/mixin/MixinMobEntity.java | 34 ++++++++++++++++++ 6 files changed, 177 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5ee671a..ecd9609f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to **CreatureChatâ„¢** are documented in this file. The form [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Added +- All entities with chat data can now open doors and path find through doors + + ## Unreleased ### Added diff --git a/src/main/java/com/owlmaddie/mixin/MixinMobEntity.java b/src/main/java/com/owlmaddie/mixin/MixinMobEntity.java index 70878bf7..d5385256 100644 --- a/src/main/java/com/owlmaddie/mixin/MixinMobEntity.java +++ b/src/main/java/com/owlmaddie/mixin/MixinMobEntity.java @@ -9,6 +9,7 @@ import com.owlmaddie.inventory.ChatInventory; import com.owlmaddie.inventory.MobInventoryMenu; import com.owlmaddie.network.ServerPackets; +import com.owlmaddie.goals.GoalUtils; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; @@ -25,10 +26,14 @@ import net.minecraft.world.entity.npc.Villager; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.ai.navigation.PathNavigation; +import net.minecraft.world.entity.ai.navigation.GroundPathNavigation; +import net.minecraft.world.entity.ai.goal.OpenDoorGoal; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.level.pathfinder.WalkNodeEvaluator; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -41,6 +46,7 @@ public class MixinMobEntity implements ChatInventory, HasCustomInventoryScreen { private final SimpleContainer creaturechat$inventory = new SimpleContainer(15); + private boolean creaturechat$doorGoalAdded; @Override public SimpleContainer creaturechat$getInventory() { @@ -231,4 +237,33 @@ private void onItemGiven(Player player, InteractionHand hand, CallbackInfoReturn } } } + + @Inject(method = "tick", at = @At("HEAD")) + private void creaturechat$configureDoorAccess(CallbackInfo ci) { + if (creaturechat$doorGoalAdded) { + return; + } + + Mob thisEntity = (Mob) (Object) this; + if (thisEntity.level().isClientSide()) { + return; + } + + EntityChatData chatData = ChatDataManager.getServerInstance().entityChatDataMap.get(thisEntity.getStringUUID()); + if (chatData == null || chatData.status == ChatDataManager.ChatStatus.NONE) { + return; + } + + PathNavigation navigation = thisEntity.getNavigation(); + if (!(navigation instanceof GroundPathNavigation groundNavigation)) { + return; + } + + groundNavigation.setCanOpenDoors(true); + if (groundNavigation.getNodeEvaluator() instanceof WalkNodeEvaluator walkNodeEvaluator) { + walkNodeEvaluator.setCanPassDoors(true); + } + GoalUtils.getGoalSelector(thisEntity).addGoal(1, new OpenDoorGoal(thisEntity, true)); + creaturechat$doorGoalAdded = true; + } } \ No newline at end of file diff --git a/src/vs/v1_20_5/main/java/com/owlmaddie/mixin/MixinMobEntity.java b/src/vs/v1_20_5/main/java/com/owlmaddie/mixin/MixinMobEntity.java index 808c8f27..e5f71d7f 100644 --- a/src/vs/v1_20_5/main/java/com/owlmaddie/mixin/MixinMobEntity.java +++ b/src/vs/v1_20_5/main/java/com/owlmaddie/mixin/MixinMobEntity.java @@ -9,6 +9,7 @@ import com.owlmaddie.inventory.ChatInventory; import com.owlmaddie.inventory.MobInventoryMenu; import com.owlmaddie.network.ServerPackets; +import com.owlmaddie.goals.GoalUtils; import net.minecraft.world.entity.HasCustomInventoryScreen; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.minecraft.core.HolderLookup; @@ -24,9 +25,13 @@ import net.minecraft.world.entity.npc.Villager; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.ai.navigation.PathNavigation; +import net.minecraft.world.entity.ai.navigation.GroundPathNavigation; +import net.minecraft.world.entity.ai.goal.OpenDoorGoal; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.level.pathfinder.WalkNodeEvaluator; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -40,6 +45,7 @@ public class MixinMobEntity implements ChatInventory, HasCustomInventoryScreen { private final SimpleContainer creaturechat$inventory = new SimpleContainer(15); + private boolean creaturechat$doorGoalAdded; @Override public SimpleContainer creaturechat$getInventory() { @@ -233,4 +239,32 @@ private void onItemGiven(Player player, InteractionHand hand, CallbackInfoReturn } } } + @Inject(method = "tick", at = @At("HEAD")) + private void creaturechat$configureDoorAccess(CallbackInfo ci) { + if (creaturechat$doorGoalAdded) { + return; + } + + Mob thisEntity = (Mob) (Object) this; + if (thisEntity.level().isClientSide()) { + return; + } + + EntityChatData chatData = ChatDataManager.getServerInstance().entityChatDataMap.get(thisEntity.getStringUUID()); + if (chatData == null || chatData.status == ChatDataManager.ChatStatus.NONE) { + return; + } + + PathNavigation navigation = thisEntity.getNavigation(); + if (!(navigation instanceof GroundPathNavigation groundNavigation)) { + return; + } + + groundNavigation.setCanOpenDoors(true); + if (groundNavigation.getNodeEvaluator() instanceof WalkNodeEvaluator walkNodeEvaluator) { + walkNodeEvaluator.setCanPassDoors(true); + } + GoalUtils.getGoalSelector(thisEntity).addGoal(1, new OpenDoorGoal(thisEntity, true)); + creaturechat$doorGoalAdded = true; + } } diff --git a/src/vs/v1_21_0/main/java/com/owlmaddie/mixin/MixinMobEntity.java b/src/vs/v1_21_0/main/java/com/owlmaddie/mixin/MixinMobEntity.java index e8d8c00c..57b74c93 100644 --- a/src/vs/v1_21_0/main/java/com/owlmaddie/mixin/MixinMobEntity.java +++ b/src/vs/v1_21_0/main/java/com/owlmaddie/mixin/MixinMobEntity.java @@ -9,6 +9,7 @@ import com.owlmaddie.inventory.ChatInventory; import com.owlmaddie.inventory.MobInventoryMenu; import com.owlmaddie.network.ServerPackets; +import com.owlmaddie.goals.GoalUtils; import net.minecraft.world.entity.HasCustomInventoryScreen; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.minecraft.network.chat.Component; @@ -25,9 +26,13 @@ import net.minecraft.world.entity.npc.Villager; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.ai.navigation.PathNavigation; +import net.minecraft.world.entity.ai.navigation.GroundPathNavigation; +import net.minecraft.world.entity.ai.goal.OpenDoorGoal; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.level.pathfinder.WalkNodeEvaluator; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -40,6 +45,7 @@ public class MixinMobEntity implements ChatInventory, HasCustomInventoryScreen { private final SimpleContainer creaturechat$inventory = new SimpleContainer(15); + private boolean creaturechat$doorGoalAdded; @Override public SimpleContainer creaturechat$getInventory() { @@ -236,4 +242,32 @@ private void onItemGiven(Player player, InteractionHand hand, CallbackInfoReturn } } } + @Inject(method = "tick", at = @At("HEAD")) + private void creaturechat$configureDoorAccess(CallbackInfo ci) { + if (creaturechat$doorGoalAdded) { + return; + } + + Mob thisEntity = (Mob) (Object) this; + if (thisEntity.level().isClientSide()) { + return; + } + + EntityChatData chatData = ChatDataManager.getServerInstance().entityChatDataMap.get(thisEntity.getStringUUID()); + if (chatData == null || chatData.status == ChatDataManager.ChatStatus.NONE) { + return; + } + + PathNavigation navigation = thisEntity.getNavigation(); + if (!(navigation instanceof GroundPathNavigation groundNavigation)) { + return; + } + + groundNavigation.setCanOpenDoors(true); + if (groundNavigation.getNodeEvaluator() instanceof WalkNodeEvaluator walkNodeEvaluator) { + walkNodeEvaluator.setCanPassDoors(true); + } + GoalUtils.getGoalSelector(thisEntity).addGoal(1, new OpenDoorGoal(thisEntity, true)); + creaturechat$doorGoalAdded = true; + } } \ No newline at end of file diff --git a/src/vs/v1_21_5/main/java/com/owlmaddie/mixin/MixinMobEntity.java b/src/vs/v1_21_5/main/java/com/owlmaddie/mixin/MixinMobEntity.java index b1cc82fc..cbac169a 100644 --- a/src/vs/v1_21_5/main/java/com/owlmaddie/mixin/MixinMobEntity.java +++ b/src/vs/v1_21_5/main/java/com/owlmaddie/mixin/MixinMobEntity.java @@ -9,6 +9,7 @@ import com.owlmaddie.inventory.ChatInventory; import com.owlmaddie.inventory.MobInventoryMenu; import com.owlmaddie.network.ServerPackets; +import com.owlmaddie.goals.GoalUtils; import net.minecraft.world.entity.HasCustomInventoryScreen; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.minecraft.network.chat.Component; @@ -25,9 +26,13 @@ import net.minecraft.world.entity.npc.Villager; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.ai.navigation.PathNavigation; +import net.minecraft.world.entity.ai.navigation.GroundPathNavigation; +import net.minecraft.world.entity.ai.goal.OpenDoorGoal; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.level.pathfinder.WalkNodeEvaluator; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -40,6 +45,7 @@ public class MixinMobEntity implements ChatInventory, HasCustomInventoryScreen { private final SimpleContainer creaturechat$inventory = new SimpleContainer(15); + private boolean creaturechat$doorGoalAdded; @Override public SimpleContainer creaturechat$getInventory() { @@ -237,4 +243,32 @@ private void onItemGiven(Player player, InteractionHand hand, CallbackInfoReturn } } } + @Inject(method = "tick", at = @At("HEAD")) + private void creaturechat$configureDoorAccess(CallbackInfo ci) { + if (creaturechat$doorGoalAdded) { + return; + } + + Mob thisEntity = (Mob) (Object) this; + if (thisEntity.level().isClientSide()) { + return; + } + + EntityChatData chatData = ChatDataManager.getServerInstance().entityChatDataMap.get(thisEntity.getStringUUID()); + if (chatData == null || chatData.status == ChatDataManager.ChatStatus.NONE) { + return; + } + + PathNavigation navigation = thisEntity.getNavigation(); + if (!(navigation instanceof GroundPathNavigation groundNavigation)) { + return; + } + + groundNavigation.setCanOpenDoors(true); + if (groundNavigation.getNodeEvaluator() instanceof WalkNodeEvaluator walkNodeEvaluator) { + walkNodeEvaluator.setCanPassDoors(true); + } + GoalUtils.getGoalSelector(thisEntity).addGoal(1, new OpenDoorGoal(thisEntity, true)); + creaturechat$doorGoalAdded = true; + } } \ No newline at end of file diff --git a/src/vs/v1_21_6/main/java/com/owlmaddie/mixin/MixinMobEntity.java b/src/vs/v1_21_6/main/java/com/owlmaddie/mixin/MixinMobEntity.java index 67b35140..bbd925f3 100644 --- a/src/vs/v1_21_6/main/java/com/owlmaddie/mixin/MixinMobEntity.java +++ b/src/vs/v1_21_6/main/java/com/owlmaddie/mixin/MixinMobEntity.java @@ -9,6 +9,7 @@ import com.owlmaddie.inventory.ChatInventory; import com.owlmaddie.inventory.MobInventoryMenu; import com.owlmaddie.network.ServerPackets; +import com.owlmaddie.goals.GoalUtils; import net.minecraft.world.entity.HasCustomInventoryScreen; import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; import net.minecraft.network.chat.Component; @@ -24,9 +25,13 @@ import net.minecraft.world.entity.npc.Villager; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.ai.navigation.PathNavigation; +import net.minecraft.world.entity.ai.navigation.GroundPathNavigation; +import net.minecraft.world.entity.ai.goal.OpenDoorGoal; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.level.pathfinder.WalkNodeEvaluator; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -39,6 +44,7 @@ public class MixinMobEntity implements ChatInventory, HasCustomInventoryScreen { private final SimpleContainer creaturechat$inventory = new SimpleContainer(15); + private boolean creaturechat$doorGoalAdded; @Override public SimpleContainer creaturechat$getInventory() { @@ -217,4 +223,32 @@ private void onItemGiven(Player player, InteractionHand hand, CallbackInfoReturn } } } + @Inject(method = "tick", at = @At("HEAD")) + private void creaturechat$configureDoorAccess(CallbackInfo ci) { + if (creaturechat$doorGoalAdded) { + return; + } + + Mob thisEntity = (Mob) (Object) this; + if (thisEntity.level().isClientSide()) { + return; + } + + EntityChatData chatData = ChatDataManager.getServerInstance().entityChatDataMap.get(thisEntity.getStringUUID()); + if (chatData == null || chatData.status == ChatDataManager.ChatStatus.NONE) { + return; + } + + PathNavigation navigation = thisEntity.getNavigation(); + if (!(navigation instanceof GroundPathNavigation groundNavigation)) { + return; + } + + groundNavigation.setCanOpenDoors(true); + if (groundNavigation.getNodeEvaluator() instanceof WalkNodeEvaluator walkNodeEvaluator) { + walkNodeEvaluator.setCanPassDoors(true); + } + GoalUtils.getGoalSelector(thisEntity).addGoal(1, new OpenDoorGoal(thisEntity, true)); + creaturechat$doorGoalAdded = true; + } } \ No newline at end of file