diff --git a/shared/src/main/java/net/blay09/mods/waystones/InternalMethodsImpl.java b/shared/src/main/java/net/blay09/mods/waystones/InternalMethodsImpl.java index 5b5b5d8a..3364f8a2 100644 --- a/shared/src/main/java/net/blay09/mods/waystones/InternalMethodsImpl.java +++ b/shared/src/main/java/net/blay09/mods/waystones/InternalMethodsImpl.java @@ -5,6 +5,8 @@ import net.blay09.mods.waystones.api.*; import net.blay09.mods.waystones.block.ModBlocks; import net.blay09.mods.waystones.block.WaystoneBlock; +import net.blay09.mods.waystones.config.WaystonesConfig; +import net.blay09.mods.waystones.config.WaystonesConfigData; import net.blay09.mods.waystones.core.PlayerWaystoneManager; import net.blay09.mods.waystones.core.WarpMode; import net.blay09.mods.waystones.core.WaystoneManager; @@ -34,6 +36,10 @@ public class InternalMethodsImpl implements InternalMethods { public Either createDefaultTeleportContext(Entity entity, IWaystone waystone, WarpMode warpMode, @Nullable IWaystone fromWaystone) { return WaystonesAPI.createCustomTeleportContext(entity, waystone).ifLeft(context -> { context.setWarpMode(warpMode); + final var shouldTransportPets = WaystonesConfig.getActive().restrictions.transportPets; + if (shouldTransportPets == WaystonesConfigData.TransportPets.ENABLED || (shouldTransportPets == WaystonesConfigData.TransportPets.SAME_DIMENSION && !context.isDimensionalTeleport())) { + context.getAdditionalEntities().addAll(PlayerWaystoneManager.findPets(entity)); + } context.getLeashedEntities().addAll(PlayerWaystoneManager.findLeashedAnimals(entity)); context.setFromWaystone(fromWaystone); context.setWarpItem(PlayerWaystoneManager.findWarpItem(entity, warpMode)); diff --git a/shared/src/main/java/net/blay09/mods/waystones/config/WaystonesConfigData.java b/shared/src/main/java/net/blay09/mods/waystones/config/WaystonesConfigData.java index 6f11a4b2..caedafe2 100644 --- a/shared/src/main/java/net/blay09/mods/waystones/config/WaystonesConfigData.java +++ b/shared/src/main/java/net/blay09/mods/waystones/config/WaystonesConfigData.java @@ -10,6 +10,13 @@ @Config(Waystones.MOD_ID) public class WaystonesConfigData implements BalmConfigData { + + public enum TransportPets { + ENABLED, + SAME_DIMENSION, + DISABLED + } + public XpCost xpCost = new XpCost(); public Restrictions restrictions = new Restrictions(); public Cooldowns cooldowns = new Cooldowns(); @@ -89,6 +96,10 @@ public static class Restrictions { @Comment("If enabled, waystones generated in worldgen are unbreakable.") public boolean generatedWaystonesUnbreakable = false; + @Synced + @Comment("Set to ENABLED to have nearby pets teleport with you. Set to SAME_DIMENSION to have nearby pets teleport with you only if you're not changing dimensions. Set to DISABLED to disable.") + public TransportPets transportPets = TransportPets.SAME_DIMENSION; + @Synced @Comment("If enabled, leashed mobs will be teleported with you") public boolean transportLeashed = true; diff --git a/shared/src/main/java/net/blay09/mods/waystones/core/PlayerWaystoneManager.java b/shared/src/main/java/net/blay09/mods/waystones/core/PlayerWaystoneManager.java index 3ebc62c0..ba7de52d 100644 --- a/shared/src/main/java/net/blay09/mods/waystones/core/PlayerWaystoneManager.java +++ b/shared/src/main/java/net/blay09/mods/waystones/core/PlayerWaystoneManager.java @@ -29,10 +29,7 @@ import net.minecraft.sounds.SoundSource; import net.minecraft.tags.TagKey; import net.minecraft.util.Mth; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.Mob; -import net.minecraft.world.entity.PathfinderMob; +import net.minecraft.world.entity.*; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -602,4 +599,9 @@ public static void removeKnownWaystone(@Nullable MinecraftServer server, IWaysto } } + public static Collection findPets(Entity entity) { + return entity.level().getEntitiesOfClass(TamableAnimal.class, new AABB(entity.blockPosition()).inflate(10), + pet -> entity.getUUID().equals(pet.getOwnerUUID()) && !pet.isOrderedToSit() + ); + } } diff --git a/shared/src/main/resources/assets/waystones/lang/en_us.json b/shared/src/main/resources/assets/waystones/lang/en_us.json index 09b6d589..2a7f2547 100644 --- a/shared/src/main/resources/assets/waystones/lang/en_us.json +++ b/shared/src/main/resources/assets/waystones/lang/en_us.json @@ -141,6 +141,8 @@ "config.waystones.restrictions.restrictRenameToOwner.tooltip": "If enabled, only the owner of a waystone (the one who placed it) can rename it.", "config.waystones.restrictions.generatedWaystonesUnbreakable": "Generated Waystones Unbreakable", "config.waystones.restrictions.generatedWaystonesUnbreakable.tooltip": "If enabled, waystones generated in worldgen are unbreakable.", + "config.waystones.restrictions.transportPets": "Transport Pets", + "config.waystones.restrictions.transportPets.tooltip": "Set to ENABLED to have nearby pets teleport with you. Set to SAME_DIMENSION to have nearby pets teleport with you only if you're not changing dimensions. Set to DISABLED to disable.", "config.waystones.restrictions.transportLeashed": "Transport Leashed", "config.waystones.restrictions.transportLeashed.tooltip": "If enabled, leashed mobs will be teleported with you.", "config.waystones.restrictions.transportLeashedDimensional": "Transport Leashed Dimensional",