diff --git a/src/main/java/pokecube/legends/entity/WormholeEntity.java b/src/main/java/pokecube/legends/entity/WormholeEntity.java index 89b1f234bc..e101f4074a 100644 --- a/src/main/java/pokecube/legends/entity/WormholeEntity.java +++ b/src/main/java/pokecube/legends/entity/WormholeEntity.java @@ -49,6 +49,7 @@ import pokecube.api.PokecubeAPI; import pokecube.api.entity.pokemob.IPokemob; import pokecube.api.entity.pokemob.PokemobCaps; +import pokecube.core.PokecubeCore; import pokecube.core.eventhandlers.EventsHandler; import pokecube.core.utils.EntityTools; import pokecube.legends.init.EntityInit; @@ -160,15 +161,21 @@ public void deserializeNBT(final Tag nbt) public static void onTeleport(final EntityTeleportEvent event) { - final Level world = event.getEntity().level; + Entity entity = event.getEntity(); + final Level world = entity.level; if (world.isClientSide()) return; if (!(world instanceof ServerLevel)) return; + final long lastTp = entity.getPersistentData().getLong("pokecube_legends:uwh_use") + + WormholeEntity.wormholeReUseDelay; + final long now = Tracker.instance().getTick(); + + if (now < lastTp) return; + final IWormholeWorld holes = world.getCapability(WormholeSpawns.WORMHOLES_CAP).orElse(null); if (holes == null) return; - final double chance = ItemList.is(WormholeSpawns.SPACE_WORMS, event.getEntity()) - ? WormholeSpawns.teleWormholeChanceWorms + final double chance = ItemList.is(WormholeSpawns.SPACE_WORMS, entity) ? WormholeSpawns.teleWormholeChanceWorms : WormholeSpawns.teleWormholeChanceNormal; final Random rand = world.getRandom(); @@ -181,7 +188,7 @@ public static void onTeleport(final EntityTeleportEvent event) // If it is a pokemob, check if holding a location linker, if so, use // that for destination of the wormhole! - final IPokemob pokemob = PokemobCaps.getPokemobFor(event.getEntity()); + final IPokemob pokemob = PokemobCaps.getPokemobFor(entity); if (pokemob != null) { ILinkStorage link = null; @@ -193,7 +200,7 @@ public static void onTeleport(final EntityTeleportEvent event) } if (link != null) { - GlobalPos linked_pos = link.getLinkedPos(event.getEntity()); + GlobalPos linked_pos = link.getLinkedPos(entity); if (linked_pos != null) { linked_pos = GlobalPos.of(linked_pos.dimension(), linked_pos.pos().above(2)); @@ -438,12 +445,16 @@ protected void pushEntities() if (!list.isEmpty()) for (Entity entity : list) { entity = EntityTools.getCoreEntity(entity); + + // These cannot go through a wormhole. + if (ItemList.is(WormholeSpawns.SPACE_ANCHORED, entity)) continue; + final long lastTp = entity.getPersistentData().getLong("pokecube_legends:uwh_use") + WormholeEntity.wormholeReUseDelay; final long now = Tracker.instance().getTick(); final UUID uuid = entity.getUUID(); if (now < lastTp || tpd.contains(uuid)) continue; - PokecubeAPI.logDebug("Transfering {} through a wormhole!", entity); + if (PokecubeCore.getConfig().debug_misc) PokecubeAPI.logInfo("Transfering {} through a wormhole!", entity); tpd.add(uuid); entity.getPersistentData().putLong("pokecube_legends:uwh_use", now); diff --git a/src/main/java/pokecube/legends/spawns/WormholeSpawns.java b/src/main/java/pokecube/legends/spawns/WormholeSpawns.java index 04b97ddd73..d063d71b4a 100644 --- a/src/main/java/pokecube/legends/spawns/WormholeSpawns.java +++ b/src/main/java/pokecube/legends/spawns/WormholeSpawns.java @@ -67,8 +67,7 @@ public CompoundTag serializeNBT() { final CompoundTag nbt = new CompoundTag(); final ListTag list = new ListTag(); - for (final BlockPos pos : this.getWormholes()) - list.add(NbtUtils.writeBlockPos(pos)); + for (final BlockPos pos : this.getWormholes()) list.add(NbtUtils.writeBlockPos(pos)); nbt.put("wormholes", list); return nbt; } @@ -78,8 +77,7 @@ public void deserializeNBT(final CompoundTag nbt) { this.getWormholes().clear(); final ListTag list = nbt.getList("wormholes", 10); - for (final Tag tag : list) - this.getWormholes().add(NbtUtils.readBlockPos((CompoundTag) tag)); + for (final Tag tag : list) this.getWormholes().add(NbtUtils.readBlockPos((CompoundTag) tag)); } @Override @@ -108,14 +106,15 @@ public void removeWormhole(final BlockPos pos) static WormholeSpawns INSTANCE = new WormholeSpawns(); - public static double randomWormholeChance = 0.00001; + public static double randomWormholeChance = 0.00001; public static double randomWormholeDistance = 64; - public static double randomWormholeSpacing = 128; + public static double randomWormholeSpacing = 128; public static double teleWormholeChanceNormal = 0.01; - public static double teleWormholeChanceWorms = 0.75; + public static double teleWormholeChanceWorms = 0.75; public static final ResourceLocation SPACE_WORMS = new ResourceLocation(Reference.ID, "space_worm"); + public static final ResourceLocation SPACE_ANCHORED = new ResourceLocation(Reference.ID, "space_anchored"); public static void init() { @@ -182,8 +181,7 @@ public void onTickEnd(final ServerLevel world) final BlockPos p = WormholeSpawns.getWormholePos(world, v.getPos()); final Vector3 pos = new Vector3().set(p); - for (final BlockPos p2 : holes.getWormholes()) - if (p2.closerThan(pos.getPos(), wormholeSpacing)) return; + for (final BlockPos p2 : holes.getWormholes()) if (p2.closerThan(pos.getPos(), wormholeSpacing)) return; final WormholeEntity wormhole = EntityInit.WORMHOLE.get().create(world); pos.moveEntity(wormhole); diff --git a/src/main/resources/data/pokecube_legends/tags/entity_types/space_anchored.json b/src/main/resources/data/pokecube_legends/tags/entity_types/space_anchored.json new file mode 100644 index 0000000000..c37b12eb5c --- /dev/null +++ b/src/main/resources/data/pokecube_legends/tags/entity_types/space_anchored.json @@ -0,0 +1,7 @@ +{ + "replace": false, + "values": [ + "pokecube_legends:wormhole", + "minecraft:ender_dragon" + ] +} \ No newline at end of file