commit - 5f62d807b374df4f08e70f0159c6dc1e67dacbad
commit + 18ac992f4c3b6f4e954e2c6420f01d785e9deb2a
blob - /dev/null
blob + f72a77ea936d3b43a69541b872412a2b5404427b (mode 644)
--- /dev/null
+++ src/main/java/com/cobblemon/mod/common/api/pasture/PastureLink.java
+package com.cobblemon.mod.common.api.pasture;
+
+import net.minecraft.core.BlockPos;
+import net.minecraft.resources.ResourceLocation;
+
+public final class PastureLink {
+ private PastureLink() {}
+ public BlockPos getPos() { return null; }
+ public ResourceLocation getDimension() { return null; }
+}
blob - /dev/null
blob + defa5f5eb1b74a912b8c470aa21bbe430168620e (mode 644)
--- /dev/null
+++ src/main/java/com/cobblemon/mod/common/api/pasture/PastureLinkManager.java
+package com.cobblemon.mod.common.api.pasture;
+
+import net.minecraft.server.level.ServerPlayer;
+
+public final class PastureLinkManager {
+ public static final PastureLinkManager INSTANCE = new PastureLinkManager();
+ private PastureLinkManager() {}
+ public static PastureLink getLinkByPlayer(ServerPlayer player) { return null; }
+}
blob - /dev/null
blob + a98b2eed63c15eb5a55e850eaaf2e7a948f446e2 (mode 644)
--- /dev/null
+++ src/main/java/com/cobblemon/mod/common/entity/pokemon/PokemonEntity.java
+package com.cobblemon.mod.common.entity.pokemon;
+
+import net.minecraft.world.entity.EntityType;
+import net.minecraft.world.entity.PathfinderMob;
+import net.minecraft.world.level.Level;
+
+public abstract class PokemonEntity extends PathfinderMob {
+ protected PokemonEntity(EntityType<? extends PathfinderMob> type, Level level) {
+ super(type, level);
+ }
+}
blob - 5319aa243154738410e10270af29660aef00a23e
blob + 5dafc0ede48fbe660bd393799047a007478f8558
--- src/main/java/sh/rsap/aeronauticscompat/mixin/AeronauticsCompatMixinPlugin.java
+++ src/main/java/sh/rsap/aeronauticscompat/mixin/AeronauticsCompatMixinPlugin.java
Map.entry("sh.rsap.aeronauticscompat.mixin.sable.ClientPacketListenerMixin",
new String[]{SABLE}),
Map.entry("sh.rsap.aeronauticscompat.mixin.cobblemon.ProximityPCLinkMixin",
+ new String[]{SABLE, COBBLEMON}),
+ Map.entry("sh.rsap.aeronauticscompat.mixin.cobblemon.PastureLinkManagerMixin",
+ new String[]{SABLE, COBBLEMON}),
+ Map.entry("sh.rsap.aeronauticscompat.mixin.cobblemon.PokemonEntityRidingMixin",
new String[]{SABLE, COBBLEMON})
);
@Override
blob - /dev/null
blob + 961d4ee326f3eb3c80722a5378cf62d6ab62eafa (mode 644)
--- /dev/null
+++ src/main/java/sh/rsap/aeronauticscompat/mixin/cobblemon/PastureLinkManagerMixin.java
+package sh.rsap.aeronauticscompat.mixin.cobblemon;
+
+import com.cobblemon.mod.common.api.pasture.PastureLink;
+import com.cobblemon.mod.common.api.pasture.PastureLinkManager;
+import net.minecraft.core.BlockPos;
+import net.minecraft.resources.ResourceLocation;
+import net.minecraft.server.level.ServerPlayer;
+import net.minecraft.world.level.Level;
+import net.minecraft.world.phys.Vec3;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Pseudo;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
+import sh.rsap.aeronauticscompat.compat.SableBridge;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.UUID;
+
+@Pseudo
+@Mixin(value = PastureLinkManager.class, remap = false)
+public abstract class PastureLinkManagerMixin {
+
+ private static volatile Field LINKS_FIELD;
+ private static volatile Method GET_POS_METHOD;
+ private static volatile Method GET_DIMENSION_METHOD;
+
+ @Inject(method = "getLinkByPlayer", at = @At("HEAD"), cancellable = true, remap = false)
+ private static void aeronauticscompat$crossSubLevelLinkCheck(
+ ServerPlayer player, CallbackInfoReturnable<PastureLink> cir) {
+
+ if (!SableBridge.isAvailable()) return;
+
+ try {
+ Field linksField = LINKS_FIELD;
+ if (linksField == null) {
+ linksField = PastureLinkManager.class.getDeclaredField("links");
+ linksField.setAccessible(true);
+ LINKS_FIELD = linksField;
+ }
+
+ @SuppressWarnings("unchecked")
+ Map<UUID, PastureLink> links = (Map<UUID, PastureLink>) linksField.get(null);
+ PastureLink link = links.get(player.getUUID());
+ if (link == null) {
+ cir.setReturnValue(null);
+ return;
+ }
+
+ Method getPos = GET_POS_METHOD;
+ if (getPos == null) {
+ getPos = link.getClass().getMethod("getPos");
+ GET_POS_METHOD = getPos;
+ }
+ Method getDim = GET_DIMENSION_METHOD;
+ if (getDim == null) {
+ getDim = link.getClass().getMethod("getDimension");
+ GET_DIMENSION_METHOD = getDim;
+ }
+
+ BlockPos pos = (BlockPos) getPos.invoke(link);
+ ResourceLocation dim = (ResourceLocation) getDim.invoke(link);
+
+ if (pos == null || dim == null) return;
+
+ if (!player.level().dimensionTypeRegistration().is(dim)) {
+ links.remove(player.getUUID());
+ cir.setReturnValue(null);
+ return;
+ }
+
+ Level world = player.level();
+ Vec3 pastureCenter = new Vec3(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
+ double distSq = SableBridge.distanceSquaredWithSubLevels(world, player.position(), pastureCenter);
+ if (Double.isNaN(distSq)) return;
+
+ if (distSq <= 10.0 * 10.0) {
+ cir.setReturnValue(link);
+ return;
+ }
+
+ links.remove(player.getUUID());
+ cir.setReturnValue(null);
+ } catch (Throwable ignored) {}
+ }
+}
blob - /dev/null
blob + 6c2d38197d13348c4c3b0df5f4d86b630f8c893f (mode 644)
--- /dev/null
+++ src/main/java/sh/rsap/aeronauticscompat/mixin/cobblemon/PokemonEntityRidingMixin.java
+package sh.rsap.aeronauticscompat.mixin.cobblemon;
+
+import com.cobblemon.mod.common.entity.pokemon.PokemonEntity;
+import net.minecraft.world.entity.Entity;
+import net.minecraft.world.entity.LivingEntity;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Pseudo;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+import java.lang.reflect.Method;
+
+@Pseudo
+@Mixin(value = PokemonEntity.class, remap = false)
+public abstract class PokemonEntityRidingMixin extends LivingEntity {
+
+ private static volatile Method SET_PLOT_POSITION;
+ private static volatile boolean SETUP_TRIED = false;
+
+ private PokemonEntityRidingMixin() { super(null, null); }
+
+ @Inject(method = "tick", at = @At("HEAD"), remap = false)
+ private void aeronauticscompat$unstickAtTickHead(CallbackInfo ci) {
+ aeronauticscompat$clearPlotPositionIfRidden();
+ }
+
+ @Inject(method = "travel", at = @At("HEAD"), remap = false)
+ private void aeronauticscompat$unstickAtTravelHead(CallbackInfo ci) {
+ aeronauticscompat$clearPlotPositionIfRidden();
+ }
+
+ private void aeronauticscompat$clearPlotPositionIfRidden() {
+ Entity self = (Entity)(Object)this;
+ if (self.level().isClientSide) return;
+ if (this.getControllingPassenger() == null) return;
+
+ if (!SETUP_TRIED) {
+ synchronized (PokemonEntityRidingMixin.class) {
+ if (!SETUP_TRIED) {
+ try {
+ Class<?> ext = Class.forName(
+ "dev.ryanhcode.sable.mixinterface.entity.entities_stick_sublevels.EntityStickExtension");
+ SET_PLOT_POSITION = ext.getMethod("sable$setPlotPosition",
+ net.minecraft.world.phys.Vec3.class);
+ } catch (Throwable ignored) {}
+ SETUP_TRIED = true;
+ }
+ }
+ }
+
+ Method m = SET_PLOT_POSITION;
+ if (m == null) return;
+
+ try {
+ m.invoke(self, (Object) null);
+ } catch (Throwable ignored) {}
+ }
+}
blob - 659a02f705416d640f81745c4bf74f544f1b1ddf
blob + 379f4b03199b71307a52758029ad6bd066516bc1
--- src/main/resources/aeronauticscompat.mixins.json
+++ src/main/resources/aeronauticscompat.mixins.json
"bitsnbobs.CogwheelChainBlockEntityMixin",
"pneumaticcraft.SentryTurretEntitySelectorMixin",
"pneumaticcraft.AbstractPneumaticCraftBlockMixin",
- "cobblemon.ProximityPCLinkMixin"
+ "cobblemon.ProximityPCLinkMixin",
+ "cobblemon.PastureLinkManagerMixin",
+ "cobblemon.PokemonEntityRidingMixin"
],
"client": [
"etched.EtchedStopListeningSoundMixin",