Skip to content

Commit

Permalink
Refactor riding and jumping APIs into a separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyrofab committed Jun 16, 2024
1 parent 3ac7693 commit 02f817c
Show file tree
Hide file tree
Showing 48 changed files with 892 additions and 585 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ dependencies {
// Required dependencies
api include(project(path: ":requiem-api", configuration: "namedElements")) { transitive = false }
api include(project(path: ":requiem-core", configuration: "namedElements")) { transitive = false }
api include(project(path: ":requiem-core:vaquero", configuration: "namedElements"))
modImplementation(libs.bundles.requiredLibraries) {
exclude group: "net.fabricmc"
exclude group: "net.fabricmc.fabric-api"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ public final class ApiInternals {
private static SoulbindingRegistry soulbindingRegistry;
@AccessedThroughReflection
private static Function<@Nullable World, MovementRegistry> movementRegistryGetter;
@AccessedThroughReflection
private static ExternalJumpingMountFactory externalJumpingMountFactory;

@SuppressWarnings("unchecked")
public static <T extends LivingEntity> MobAbilityConfig.Builder<T> mobAbilityConfig$builderImpl() {
Expand Down Expand Up @@ -132,10 +130,6 @@ public static MovementRegistry getMovementRegistry(@Nullable World world) {
return movementRegistryGetter.apply(world);
}

public static ExternalJumpingMountFactory getExternalJumpingMountFactory() {
return externalJumpingMountFactory;
}

public static InventoryLimiter getInventoryLimiter() {
return inventoryLimiter;
}
Expand Down
1 change: 1 addition & 0 deletions requiem-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ group = rootProject.group

dependencies {
api project(path: ":requiem-api", configuration: "namedElements")
api(project(path: ":requiem-core:vaquero", configuration: "namedElements"))
modImplementation(libs.playerAbilityLib) {
exclude group: "net.fabricmc"
}
Expand Down
18 changes: 18 additions & 0 deletions requiem-core/vaquero/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
archivesBaseName = "vaquero"
group = rootProject.group + ".requiem"

dependencies {
modImplementation(libs.cca.base) {
exclude group: "net.fabricmc"
}
modImplementation(libs.cca.entity) {
exclude group: "net.fabricmc"
}
}

chenille {
license = 'LGPL'
configurePublishing {
withLadysnakeMaven()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program; If not, see <https://www.gnu.org/licenses>.
*/
package ladysnake.requiem.api.v1.entity;
package org.ladysnake.vaquero.api;

import dev.onyxstudios.cca.api.v3.component.Component;
import dev.onyxstudios.cca.api.v3.component.ComponentFactory;
import dev.onyxstudios.cca.api.v3.component.ComponentKey;
import dev.onyxstudios.cca.api.v3.component.ComponentRegistry;
import ladysnake.requiem.api.v1.internal.ApiInternals;
import net.minecraft.entity.JumpingMount;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import org.apiguardian.api.API;
import org.jetbrains.annotations.Nullable;
import org.ladysnake.vaquero.impl.jump.DummyJumpingMount;

import java.util.function.Function;

/**
* A fake {@link JumpingMount} that is not implemented by a rideable entity.
Expand All @@ -39,8 +43,8 @@
public interface ExternalJumpingMount extends JumpingMount, Component {
ComponentKey<ExternalJumpingMount> KEY = ComponentRegistry.getOrCreate(new Identifier("requiem", "charged_jump"), ExternalJumpingMount.class);

static <E extends LivingEntity> ComponentFactory<E, ExternalJumpingMount> simple(float baseJumpStrength, SoundEvent stepSound) {
return ApiInternals.getExternalJumpingMountFactory().simple(baseJumpStrength, stepSound);
static <E extends LivingEntity> ComponentFactory<E, ExternalJumpingMount> simple(float baseJumpStrength, SoundEvent stepSound, Function<LivingEntity, @Nullable PlayerEntity> getPlayer) {
return e -> new DummyJumpingMount(e, baseJumpStrength, stepSound, getPlayer);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Requiem
* Copyright (C) 2017-2024 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; If not, see <https://www.gnu.org/licenses>.
*/
package org.ladysnake.vaquero.api;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.RavagerEntity;
import net.minecraft.entity.mob.SkeletonEntity;
import net.minecraft.entity.mob.SpiderEntity;
import net.minecraft.entity.passive.ChickenEntity;
import net.minecraft.entity.passive.StriderEntity;
import net.minecraft.registry.tag.EntityTypeTags;
import org.apiguardian.api.API;
import org.ladysnake.vaquero.impl.VaqueroEntityTypeTags;

@API(status = API.Status.EXPERIMENTAL, since = "2.0.0")
public enum MobRidingType {
DEFAULT, MOUNT, RIDE;

public boolean canMount() {
return this != DEFAULT;
}

public boolean canSteer() {
return this == RIDE;
}

public static MobRidingType get(Entity entity, LivingEntity possessed) {
if (entity instanceof SpiderEntity) {
return possessed instanceof SkeletonEntity ? MOUNT : DEFAULT;
} else if (entity instanceof RavagerEntity) {
return possessed.getType().isIn(EntityTypeTags.RAIDERS) ? RIDE : DEFAULT;
} else if (entity instanceof ChickenEntity) {
return possessed.getType().isIn(VaqueroEntityTypeTags.ZOMBIES) && possessed.isBaby() ? RIDE : DEFAULT;
} else if (entity instanceof StriderEntity) {
return possessed.getType() == EntityType.ZOMBIFIED_PIGLIN || possessed.getType().isIn(VaqueroEntityTypeTags.PIGLINS) ? RIDE : DEFAULT;
}

return DEFAULT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Requiem
* Copyright (C) 2017-2024 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; If not, see <https://www.gnu.org/licenses>.
*/
package org.ladysnake.vaquero.api.events;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.entity.JumpingMount;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import org.jetbrains.annotations.Nullable;

public final class JumpingMountEvents {
/**
* Finds the {@link JumpingMount} associated with an entity
*/
public static final Event<FindEntityJumpingMountCallback> FIND_ENTITY_JUMP = EventFactory.createArrayBacked(FindEntityJumpingMountCallback.class, callbacks -> entity -> {
for (FindEntityJumpingMountCallback callback : callbacks) {
JumpingMount mount = callback.findJumpingMount(entity);
if (mount != null) {
return mount;
}
}
return null;
});

/**
* Finds the {@link JumpingMount} controlled by the given player
*/
public static final Event<FindPlayerJumpingMountCallback> FIND_PLAYER_JUMP = EventFactory.createArrayBacked(FindPlayerJumpingMountCallback.class, callbacks -> entity -> {
for (FindPlayerJumpingMountCallback callback : callbacks) {
JumpingMount mount = callback.findJumpingMount(entity);
if (mount != null) {
return mount;
}
}
return null;
});

@FunctionalInterface
public interface FindEntityJumpingMountCallback {
@Nullable
JumpingMount findJumpingMount(LivingEntity entity);
}

@FunctionalInterface
public interface FindPlayerJumpingMountCallback {
@Nullable
JumpingMount findJumpingMount(PlayerEntity entity);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program; If not, see <https://www.gnu.org/licenses>.
*/
package ladysnake.requiem.api.v1.event.minecraft;
package org.ladysnake.vaquero.api.events;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* API classes for Vaquero
*/
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package org.ladysnake.vaquero.api;

import net.minecraft.util.annotation.FieldsAreNonnullByDefault;
import net.minecraft.util.annotation.MethodsReturnNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Requiem
* Copyright (C) 2017-2024 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; If not, see <https://www.gnu.org/licenses>.
*/
package org.ladysnake.vaquero.impl;

import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.util.Identifier;
import org.ladysnake.vaquero.api.ExternalJumpingMount;
import org.ladysnake.vaquero.api.events.JumpingMountEvents;
import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;

public final class Vaquero implements ModInitializer {
public static Identifier id(String path) {
return new Identifier("vaquero", path);
}

@Override
public void onInitialize(ModContainer mod) {
JumpingMountEvents.FIND_ENTITY_JUMP.register(ExternalJumpingMount.KEY::getNullable);
JumpingMountEvents.FIND_PLAYER_JUMP.register(player -> {
Entity controlledVehicle = player.getControlledVehicle();
return controlledVehicle instanceof LivingEntity living ? JumpingMountEvents.FIND_ENTITY_JUMP.invoker().findJumpingMount(living) : null;
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Requiem
* Copyright (C) 2017-2024 Ladysnake
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; If not, see <https://www.gnu.org/licenses>.
*/
package org.ladysnake.vaquero.impl;

import net.minecraft.entity.EntityType;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.tag.TagKey;

public final class VaqueroEntityTypeTags {
public static final TagKey<EntityType<?>> ZOMBIES = register("zombies");
public static final TagKey<EntityType<?>> PIGLINS = register("piglins");

public static TagKey<EntityType<?>> register(String name) {
return TagKey.of(RegistryKeys.ENTITY_TYPE, Vaquero.id(name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,23 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program; If not, see <https://www.gnu.org/licenses>.
*/
package ladysnake.requiem.api.v1.event.minecraft;
package org.ladysnake.vaquero.impl.jump;

import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.entity.JumpingMount;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.passive.HorseBaseEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.sound.SoundEvent;
import org.jetbrains.annotations.Nullable;

public final class JumpingMountEvents {
/**
*
*/
public static final Event<MountCheckCallback> MOUNT_CHECK = EventFactory.createArrayBacked(MountCheckCallback.class, callbacks -> entity -> {
for (MountCheckCallback callback : callbacks) {
JumpingMount mount = callback.getJumpingMount(entity);
if (mount != null) {
return mount;
}
}
return null;
});
import java.util.function.Function;

@FunctionalInterface
public interface MountCheckCallback {
@Nullable JumpingMount getJumpingMount(LivingEntity entity);
public class DummyHorseJumpingMount extends DummyJumpingMount {
public DummyHorseJumpingMount(HorseBaseEntity mob, SoundEvent stepSound, Function<LivingEntity, @Nullable PlayerEntity> getPlayer) {
super(mob, -1, stepSound, getPlayer);
}

@Override
protected double getBaseJumpingStrength() {
return ((HorseBaseEntity) this.mob).getJumpStrength();
}
}
Loading

0 comments on commit 02f817c

Please sign in to comment.