Skip to content

Commit

Permalink
Squashed commit porting fixes to Gliders compat forwards (v2 craft-di…
Browse files Browse the repository at this point in the history
…e-repeat beta 1.20.1 -> master v2)

=====================
Use the correct fabric.mod.json so that resources are processed
Add a suggestion for gliders version
Gliders no longer nuke you when you land gently after dis-engaging from a hook (Seems to fix most of #9)
Add more GrappleModClientAPI Events & Utilities
Fix deploying elytras (issue #16) & gliders (issue #9 part 1)
Try to fix fall damage & debug activation for elytra
Ticker changes
Fix build.gradle for compat... again.
Fix game crash in dev env for glider compat
Fixed gradle for GlidersCompatModule
  • Loading branch information
squeeglii committed Apr 21, 2024
1 parent aba09f2 commit 97dbe95
Show file tree
Hide file tree
Showing 27 changed files with 292 additions and 83 deletions.
50 changes: 34 additions & 16 deletions Compat/Gliders/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,60 @@ plugins {
}

loom {
// This is here to ensure the environment sources just stay in
// one place. It was splitting them for some reason.
mods {
gliders {
sourceSet sourceSets.main
}
}

runs {
client {
runDir "run/client"
ideConfigGenerated true
}

server {
runDir "run/server"
ideConfigGenerated true
}
}
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.layered() {
officialMojangMappings()
repositories {

if(project.parchment_version != "")
parchment("org.parchmentmc.data:${project.parchment_version}@zip")
// Palladium stuff
maven {
url 'https://repo.repsy.io/mvn/lucraft/threetag'
}

modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Cardinal components
maven {
url 'https://maven.ladysnake.org/releases'
}
}

dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.officialMojangMappings()

modImplementation("net.fabricmc:fabric-loader")
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modImplementation("maven.modrinth:gliders:${project.gliders_modrinth_version}")
api project(path: ":Core", configuration: "namedElements")

modApi("maven.modrinth:gliders:${project.gliders_modrinth_version}")
modApi("maven.modrinth:playeranimator:${project.player_animator_modrinth_version}")

implementation project(":Core")
modApi "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cardinal_components_version}"
include "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cardinal_components_version}"
modApi "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cardinal_components_version}"
include "dev.onyxstudios.cardinal-components-api:cardinal-components-entity:${project.cardinal_components_version}"

modApi "net.threetag:PalladiumCore-fabric:${project.palladium_version}"
include "net.threetag:PalladiumCore-fabric:${project.palladium_version}"
}

remapJar {
archiveClassifier.set("compat")
}

configurations.configureEach {
resolutionStrategy {
force("net.fabricmc:fabric-loader:${project.loader_version}")
}
}
19 changes: 11 additions & 8 deletions Compat/Gliders/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@

# Fabric Properties | https://modmuss50.me/fabric.html
minecraft_version=1.19.2
parchment_version=
loader_version=0.14.22
fabric_version=0.76.1+1.19.2
minecraft_version=1.20.1
parchment_version=parchment-1.20.1:2023.09.03
loader_version=0.15.7
fabric_version=0.92.1+1.20.1

# Mod Properties
mod_version=1
mod_version=1.0
maven_group=me.cg360.mod.grapplemod.compat
archives_base_name=gliders

# Dependencies
gliders_target_range=>=1.2.2
gliders_modrinth_version=WLcGHp5D
grapplemod_target_range=>=2.0
grapplemod_target_range=>=1.99.1
gliders_target_range=>=1.1.5
gliders_modrinth_version=9Qu0MGnH
player_animator_modrinth_version=yDqYTUaf
palladium_version=1.20-2.0.0.0
cardinal_components_version=5.0.2

# Compilation Settings
show_dev_warnings=false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
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() {
if(!FabricLoader.getInstance().isModLoaded("vc_gliders"))
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 [client-only]");

try {
Class.forName("me.cg360.mod.grapplemod.compat.gliders.GlidersCompatEntrypoint")
Class.forName("me.cg360.mod.grapplemod.compat.gliders.GlidersCompatModule")
.getConstructor()
.newInstance();

hasLoaded = true;

} catch (Exception err) {
LogUtils.getLogger().error(err.getMessage());
logger.error(err.getMessage());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,37 @@
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 {

public GlidersCompatModule() {
LogUtils.getLogger().info("Enabled Gliders Compatibility Module");

//TODO: Add module contents - this needs a 1.19.2 backport of GrappleMod v2 to be
// completed before work can be done.
//todo oh god
// Limit speed on hook physics when gliding
// 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
@@ -0,0 +1,49 @@
package me.cg360.mod.grapplemod.compat.gliders.mixin;

import com.yyon.grapplinghook.GrappleMod;
import com.yyon.grapplinghook.content.physics.PhysicsControllers;
import com.yyon.grapplinghook.physics.PlayerPhysicsFrame;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.venturecraft.gliders.util.GliderUtil;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Optional;

@Mixin(GliderUtil.class)
public class GliderUtilMixin {

@Inject(method = "canDeployHere(Lnet/minecraft/world/entity/LivingEntity;)Z",
at = @At("HEAD"),
cancellable = true)
private static void handleGrapplingDeployCondition(LivingEntity livingEntity, CallbackInfoReturnable<Boolean> cir) {
if(!(livingEntity instanceof Player player)) return;


Optional<PlayerPhysicsFrame> mostRecentFrame = GrappleMod.get().getServerPhysicsObserver()
.getMostRecentFrame(player);

// No record of physics so there's nothing to check. Use vanilla checks only.
if(mostRecentFrame.isEmpty())
return;

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

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

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) {
cir.setReturnValue(true);
cir.cancel();
}
}

}
14 changes: 9 additions & 5 deletions Compat/Gliders/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
"authors": [ "CG360" ],
"contact": {},
"license": "GPL-3.0",
"icon": "assets/grapplemod/icon.png",
"environment": "*",
"mixins": [ "grapplemodcompat-vc-gliders.mixins.json" ],
"entrypoints": {
"client": [ "me.cg360.mod.grapplemod.compat.gliders.GlidersCompatEntrypoint" ]
},
"depends": {
"grapplemod": "${grapplemod_target_range}"
},
"recommends": {
"fabricloader": ">=${loader_version}",
"fabric": "*",
"minecraft": "*",
"grapplemod": "${grapplemod_target_range}",
"vc_gliders": "${gliders_target_range}"
"minecraft": ">={minecraft_version}"
},
"suggests": {
"vc-gliders": ">={gliders_target_range}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"required": true,
"minVersion": "0.8",
"package": "me.cg360.mod.grapplemod.compat.gliders.mixin",
"compatibilityLevel": "JAVA_17",
"mixins": [
"GliderUtilMixin"
],
"injectors": {
"defaultRequire": 1
}
}
4 changes: 3 additions & 1 deletion Compat/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
apply plugin: 'java'

subprojects {
apply plugin: 'java'

Expand Down Expand Up @@ -53,7 +55,7 @@ subprojects {


def targetJavaVersion = 17
tasks.withType(JavaCompile).configureEach {
project.tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
it.options.release.set(targetJavaVersion)
Expand Down
8 changes: 0 additions & 8 deletions Core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ version = "%s+%s.fabric".formatted(modVer, project.properties["minecraft_version
loom {
accessWidenerPath = file("src/main/resources/grapplemod.accesswidener")

// This is here to ensure the environment sources just stay in
// one place. It was splitting them for some reason.
mods {
grapplemod {
sourceSet sourceSets.main
}
}

runs {
client {
runDir "run/client"
Expand Down
2 changes: 1 addition & 1 deletion Core/src/main/java/com/yyon/grapplinghook/GrappleMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void onInitialize() {

this.registerDataPacks();

ServerTickEvents.START_SERVER_TICK.register(server -> this.ticker.tick());
ServerTickEvents.START_SERVER_TICK.register(this.ticker::tick);
}

private void initConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
import net.fabricmc.fabric.api.resource.ResourcePackActivationType;
import net.fabricmc.loader.api.FabricLoader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
package com.yyon.grapplinghook.client.api;

import com.yyon.grapplinghook.client.GrappleModClient;
import com.yyon.grapplinghook.client.physics.context.GrapplingHookPhysicsController;
import com.yyon.grapplinghook.content.physics.PhysicsControllers;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.LivingEntity;

public class GrappleModClientAPI {

public static ResourceLocation getPhysicsTypeFor(LivingEntity entity) {
if(entity == null)
return PhysicsControllers.NONE;

GrapplingHookPhysicsController controller = GrappleModClient.get()
.getClientControllerManager()
.getController(entity.getId());

return controller == null
? PhysicsControllers.NONE
: controller.getType();
}


public static void abortAllPhysicsOverrides(LivingEntity entity) {
if(entity == null) return;

GrapplingHookPhysicsController controller = GrappleModClient.get()
.getClientControllerManager()
.getController(entity.getId());

if(controller == null)
return;

controller.disable(true);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.yyon.grapplinghook.content.entity.grapplinghook.GrapplinghookEntity;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.Entity;

public class GrappleModClientEvents {
Expand All @@ -21,6 +22,13 @@ public class GrappleModClientEvents {
}
);

public static final Event<PhysicsApplied> PHYSICS_APPLIED = EventFactory.createArrayBacked(PhysicsApplied.class,
callbacks -> (thrower, physics) -> {
for (PhysicsApplied callback : callbacks)
callback.onPhysicsApplied(thrower, physics);
}
);

@FunctionalInterface
public interface HookAttach {
void onHookAttach(Entity thrower, GrapplinghookEntity hook);
Expand All @@ -31,4 +39,9 @@ public interface HookDetach {
void onHookDetach(Entity thrower);
}

@FunctionalInterface
public interface PhysicsApplied {
void onPhysicsApplied(Entity thrower, ResourceLocation physicsType);
}

}
Loading

0 comments on commit 97dbe95

Please sign in to comment.