diff --git a/CHANGELOG.md b/CHANGELOG.md index b94a5582..7ad2a1c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to **CreatureChatâ„¢** are documented in this file. The form ## Unreleased ### Added +- All entities with chat data can now open doors and path find through doors - Document SPDX header and changelog requirements in AGENTS.md for contributors ### Changed diff --git a/src/main/java/com/owlmaddie/mixin/MixinMobEntity.java b/src/main/java/com/owlmaddie/mixin/MixinMobEntity.java index f7cb6066..3ad6a167 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 1fb089f4..887b2c21 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 474866f8..fa18b5f9 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 bcdfc034..ff0696a8 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 d5f0c1b6..fd23292e 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