Skip to content

Commit

Permalink
feat: Add transportPets option to teleport nearby pets with player
Browse files Browse the repository at this point in the history
  • Loading branch information
BlayTheNinth committed Dec 14, 2023
1 parent 6a25177 commit 4f63670
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -34,6 +36,10 @@ public class InternalMethodsImpl implements InternalMethods {
public Either<IWaystoneTeleportContext, WaystoneTeleportError> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -602,4 +599,9 @@ public static void removeKnownWaystone(@Nullable MinecraftServer server, IWaysto
}
}

public static Collection<? extends Entity> findPets(Entity entity) {
return entity.level().getEntitiesOfClass(TamableAnimal.class, new AABB(entity.blockPosition()).inflate(10),
pet -> entity.getUUID().equals(pet.getOwnerUUID()) && !pet.isOrderedToSit()
);
}
}
2 changes: 2 additions & 0 deletions shared/src/main/resources/assets/waystones/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 4f63670

Please sign in to comment.