Skip to content

Commit

Permalink
Gliders no longer nuke you when you land gently after dis-engaging fr…
Browse files Browse the repository at this point in the history
…om a hook (Seems to fix most of #9)
  • Loading branch information
squeeglii committed Apr 21, 2024
1 parent 031bbc4 commit d1d9fc7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package me.cg360.mod.grapplemod.compat.gliders;

import com.mojang.logging.LogUtils;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;
import org.slf4j.Logger;

public class GlidersCompatEntrypoint implements ModInitializer {
public class GlidersCompatEntrypoint implements ClientModInitializer {

private static boolean hasLoaded = false;

@Override
public void onInitialize() {
public void onInitializeClient() {
Logger logger = LogUtils.getLogger();
if(!FabricLoader.getInstance().isModLoaded("vc_gliders")) {
logger.info("'vc_gliders' is not installed. Disabling compatibility");
return;
}

logger.info("'vc_gliders' is installed. Enabling compatibility");
logger.info("'vc_gliders' is installed. Enabling compatibility [client-only]");

try {
Class.forName("me.cg360.mod.grapplemod.compat.gliders.GlidersCompatModule")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package me.cg360.mod.grapplemod.compat.gliders;

import com.mojang.logging.LogUtils;
import com.yyon.grapplinghook.GrappleMod;
import com.yyon.grapplinghook.client.api.GrappleModClientAPI;
import com.yyon.grapplinghook.client.api.GrappleModClientEvents;
import com.yyon.grapplinghook.content.physics.PhysicsControllers;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.resources.ResourceLocation;
import net.venturecraft.gliders.util.GliderUtil;

public class GlidersCompatModule {

Expand All @@ -12,5 +21,17 @@ public GlidersCompatModule() {
// Fix weird acceleration (seems to be like infinity downwards)
// Add some way to deploy the glider after using a hook (ditch hook & just glide?)

ClientTickEvents.START_WORLD_TICK.register(level -> {
LocalPlayer player = Minecraft.getInstance().player;

if(player == null) return;
if(!GliderUtil.isGliderActive(player)) return;

ResourceLocation currentPhysicsType = GrappleModClientAPI.getPhysicsTypeFor(player);

if(currentPhysicsType == PhysicsControllers.AIR_FRICTION) {
GrappleModClientAPI.abortAllPhysicsOverrides(player);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class GliderUtilMixin {
private static void handleGrapplingDeployCondition(LivingEntity livingEntity, CallbackInfoReturnable<Boolean> cir) {
if(!(livingEntity instanceof Player player)) return;

GrappleMod.LOGGER.info("Handling deploy!");

Optional<PlayerPhysicsFrame> mostRecentFrame = GrappleMod.get().getServerPhysicsObserver()
.getMostRecentFrame(player);
Expand All @@ -32,27 +31,19 @@ private static void handleGrapplingDeployCondition(LivingEntity livingEntity, Ca
if(mostRecentFrame.isEmpty())
return;

GrappleMod.LOGGER.info("Frame found!");

ResourceLocation controllerType = mostRecentFrame.get().getPhysicsControllerType();

// Sanity
if(controllerType == null) return;

GrappleMod.LOGGER.info("Controller Found!");

boolean usingValidController = controllerType.equals(PhysicsControllers.AIR_FRICTION) ||
controllerType.equals(PhysicsControllers.GRAPPLING_HOOK);

// Can't be deployed with forcefield either as that just feels jank.
if(usingValidController) {
GrappleMod.LOGGER.info("Phys Trigger!");
cir.setReturnValue(true);
cir.cancel();
}


//todo: issue is linked to elytra deployment conditions not being met
}

}
2 changes: 1 addition & 1 deletion Compat/Gliders/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"environment": "*",
"mixins": [ "grapplemodcompat-vc-gliders.mixins.json" ],
"entrypoints": {
"main": [ "me.cg360.mod.grapplemod.compat.gliders.GlidersCompatEntrypoint" ]
"client": [ "me.cg360.mod.grapplemod.compat.gliders.GlidersCompatEntrypoint" ]
},
"depends": {
"fabricloader": ">=${loader_version}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,28 +80,6 @@ public void onInitializeClient() {
this.clientPhysicsControllerTracker = new ClientPhysicsControllerTracker();
this.registerPropertyOverride();
this.registerResourcePacks();

ClientTickEvents.END_CLIENT_TICK.register(world -> {
LocalPlayer localPlayer = Minecraft.getInstance().player;

if(localPlayer == null)
return;

Component isJumping = Component.literal("isJumping=%s, ".formatted(localPlayer.input.jumping));
Component isNotFlying = Component.literal("isNotFlying=%s, ".formatted(!localPlayer.getAbilities().flying));
Component isNotPassenger = Component.literal("isNotPassenger=%s, ".formatted(!localPlayer.isPassenger()));
Component isNotClimbing = Component.literal("isNotClimbing=%s".formatted(!localPlayer.onClimbable()));

Component debugInfo = Component.literal("")
.append(isJumping)
.append(isNotFlying)
.append(isNotPassenger)
.append(isNotClimbing);

GrappleMod.LOGGER.info(debugInfo);
Minecraft.getInstance().gui.setOverlayMessage(debugInfo, false);

});
}

public static GrappleModClient get() {
Expand Down

0 comments on commit d1d9fc7

Please sign in to comment.