Skip to content

Commit 2ca4eb1

Browse files
authored
Merge pull request #666 from Ladysnake/refacto/riding
Refactor riding and jumping APIs into a separate module
2 parents 0f5b294 + 02f817c commit 2ca4eb1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+892
-585
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ dependencies {
152152
// Required dependencies
153153
api include(project(path: ":requiem-api", configuration: "namedElements")) { transitive = false }
154154
api include(project(path: ":requiem-core", configuration: "namedElements")) { transitive = false }
155+
api include(project(path: ":requiem-core:vaquero", configuration: "namedElements"))
155156
modImplementation(libs.bundles.requiredLibraries) {
156157
exclude group: "net.fabricmc"
157158
exclude group: "net.fabricmc.fabric-api"

requiem-api/src/main/java/ladysnake/requiem/api/v1/internal/ApiInternals.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ public final class ApiInternals {
7878
private static SoulbindingRegistry soulbindingRegistry;
7979
@AccessedThroughReflection
8080
private static Function<@Nullable World, MovementRegistry> movementRegistryGetter;
81-
@AccessedThroughReflection
82-
private static ExternalJumpingMountFactory externalJumpingMountFactory;
8381

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

135-
public static ExternalJumpingMountFactory getExternalJumpingMountFactory() {
136-
return externalJumpingMountFactory;
137-
}
138-
139133
public static InventoryLimiter getInventoryLimiter() {
140134
return inventoryLimiter;
141135
}

requiem-core/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ group = rootProject.group
33

44
dependencies {
55
api project(path: ":requiem-api", configuration: "namedElements")
6+
api(project(path: ":requiem-core:vaquero", configuration: "namedElements"))
67
modImplementation(libs.playerAbilityLib) {
78
exclude group: "net.fabricmc"
89
}

requiem-core/vaquero/build.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
archivesBaseName = "vaquero"
2+
group = rootProject.group + ".requiem"
3+
4+
dependencies {
5+
modImplementation(libs.cca.base) {
6+
exclude group: "net.fabricmc"
7+
}
8+
modImplementation(libs.cca.entity) {
9+
exclude group: "net.fabricmc"
10+
}
11+
}
12+
13+
chenille {
14+
license = 'LGPL'
15+
configurePublishing {
16+
withLadysnakeMaven()
17+
}
18+
}

requiem-api/src/main/java/ladysnake/requiem/api/v1/entity/ExternalJumpingMount.java renamed to requiem-core/vaquero/src/main/java/org/ladysnake/vaquero/api/ExternalJumpingMount.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,24 @@
1515
* You should have received a copy of the GNU Lesser General Public License
1616
* along with this program; If not, see <https://www.gnu.org/licenses>.
1717
*/
18-
package ladysnake.requiem.api.v1.entity;
18+
package org.ladysnake.vaquero.api;
1919

2020
import dev.onyxstudios.cca.api.v3.component.Component;
2121
import dev.onyxstudios.cca.api.v3.component.ComponentFactory;
2222
import dev.onyxstudios.cca.api.v3.component.ComponentKey;
2323
import dev.onyxstudios.cca.api.v3.component.ComponentRegistry;
24-
import ladysnake.requiem.api.v1.internal.ApiInternals;
2524
import net.minecraft.entity.JumpingMount;
2625
import net.minecraft.entity.LivingEntity;
2726
import net.minecraft.entity.mob.MobEntity;
27+
import net.minecraft.entity.player.PlayerEntity;
2828
import net.minecraft.sound.SoundEvent;
2929
import net.minecraft.util.Identifier;
3030
import net.minecraft.util.math.Vec3d;
3131
import org.apiguardian.api.API;
32+
import org.jetbrains.annotations.Nullable;
33+
import org.ladysnake.vaquero.impl.jump.DummyJumpingMount;
34+
35+
import java.util.function.Function;
3236

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

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

4650
/**
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Requiem
3+
* Copyright (C) 2017-2024 Ladysnake
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; If not, see <https://www.gnu.org/licenses>.
17+
*/
18+
package org.ladysnake.vaquero.api;
19+
20+
import net.minecraft.entity.Entity;
21+
import net.minecraft.entity.EntityType;
22+
import net.minecraft.entity.LivingEntity;
23+
import net.minecraft.entity.mob.RavagerEntity;
24+
import net.minecraft.entity.mob.SkeletonEntity;
25+
import net.minecraft.entity.mob.SpiderEntity;
26+
import net.minecraft.entity.passive.ChickenEntity;
27+
import net.minecraft.entity.passive.StriderEntity;
28+
import net.minecraft.registry.tag.EntityTypeTags;
29+
import org.apiguardian.api.API;
30+
import org.ladysnake.vaquero.impl.VaqueroEntityTypeTags;
31+
32+
@API(status = API.Status.EXPERIMENTAL, since = "2.0.0")
33+
public enum MobRidingType {
34+
DEFAULT, MOUNT, RIDE;
35+
36+
public boolean canMount() {
37+
return this != DEFAULT;
38+
}
39+
40+
public boolean canSteer() {
41+
return this == RIDE;
42+
}
43+
44+
public static MobRidingType get(Entity entity, LivingEntity possessed) {
45+
if (entity instanceof SpiderEntity) {
46+
return possessed instanceof SkeletonEntity ? MOUNT : DEFAULT;
47+
} else if (entity instanceof RavagerEntity) {
48+
return possessed.getType().isIn(EntityTypeTags.RAIDERS) ? RIDE : DEFAULT;
49+
} else if (entity instanceof ChickenEntity) {
50+
return possessed.getType().isIn(VaqueroEntityTypeTags.ZOMBIES) && possessed.isBaby() ? RIDE : DEFAULT;
51+
} else if (entity instanceof StriderEntity) {
52+
return possessed.getType() == EntityType.ZOMBIFIED_PIGLIN || possessed.getType().isIn(VaqueroEntityTypeTags.PIGLINS) ? RIDE : DEFAULT;
53+
}
54+
55+
return DEFAULT;
56+
}
57+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Requiem
3+
* Copyright (C) 2017-2024 Ladysnake
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; If not, see <https://www.gnu.org/licenses>.
17+
*/
18+
package org.ladysnake.vaquero.api.events;
19+
20+
import net.fabricmc.fabric.api.event.Event;
21+
import net.fabricmc.fabric.api.event.EventFactory;
22+
import net.minecraft.entity.JumpingMount;
23+
import net.minecraft.entity.LivingEntity;
24+
import net.minecraft.entity.player.PlayerEntity;
25+
import org.jetbrains.annotations.Nullable;
26+
27+
public final class JumpingMountEvents {
28+
/**
29+
* Finds the {@link JumpingMount} associated with an entity
30+
*/
31+
public static final Event<FindEntityJumpingMountCallback> FIND_ENTITY_JUMP = EventFactory.createArrayBacked(FindEntityJumpingMountCallback.class, callbacks -> entity -> {
32+
for (FindEntityJumpingMountCallback callback : callbacks) {
33+
JumpingMount mount = callback.findJumpingMount(entity);
34+
if (mount != null) {
35+
return mount;
36+
}
37+
}
38+
return null;
39+
});
40+
41+
/**
42+
* Finds the {@link JumpingMount} controlled by the given player
43+
*/
44+
public static final Event<FindPlayerJumpingMountCallback> FIND_PLAYER_JUMP = EventFactory.createArrayBacked(FindPlayerJumpingMountCallback.class, callbacks -> entity -> {
45+
for (FindPlayerJumpingMountCallback callback : callbacks) {
46+
JumpingMount mount = callback.findJumpingMount(entity);
47+
if (mount != null) {
48+
return mount;
49+
}
50+
}
51+
return null;
52+
});
53+
54+
@FunctionalInterface
55+
public interface FindEntityJumpingMountCallback {
56+
@Nullable
57+
JumpingMount findJumpingMount(LivingEntity entity);
58+
}
59+
60+
@FunctionalInterface
61+
public interface FindPlayerJumpingMountCallback {
62+
@Nullable
63+
JumpingMount findJumpingMount(PlayerEntity entity);
64+
}
65+
}

requiem-api/src/main/java/ladysnake/requiem/api/v1/event/minecraft/MobTravelRidingCallback.java renamed to requiem-core/vaquero/src/main/java/org/ladysnake/vaquero/api/events/MobTravelRidingCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* You should have received a copy of the GNU Lesser General Public License
1616
* along with this program; If not, see <https://www.gnu.org/licenses>.
1717
*/
18-
package ladysnake.requiem.api.v1.event.minecraft;
18+
package org.ladysnake.vaquero.api.events;
1919

2020
import net.fabricmc.fabric.api.event.Event;
2121
import net.fabricmc.fabric.api.event.EventFactory;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* API classes for Vaquero
3+
*/
4+
@FieldsAreNonnullByDefault
5+
@MethodsReturnNonnullByDefault
6+
@ParametersAreNonnullByDefault
7+
package org.ladysnake.vaquero.api;
8+
9+
import net.minecraft.util.annotation.FieldsAreNonnullByDefault;
10+
import net.minecraft.util.annotation.MethodsReturnNonnullByDefault;
11+
12+
import javax.annotation.ParametersAreNonnullByDefault;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Requiem
3+
* Copyright (C) 2017-2024 Ladysnake
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; If not, see <https://www.gnu.org/licenses>.
17+
*/
18+
package org.ladysnake.vaquero.impl;
19+
20+
import net.minecraft.entity.Entity;
21+
import net.minecraft.entity.LivingEntity;
22+
import net.minecraft.util.Identifier;
23+
import org.ladysnake.vaquero.api.ExternalJumpingMount;
24+
import org.ladysnake.vaquero.api.events.JumpingMountEvents;
25+
import org.quiltmc.loader.api.ModContainer;
26+
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
27+
28+
public final class Vaquero implements ModInitializer {
29+
public static Identifier id(String path) {
30+
return new Identifier("vaquero", path);
31+
}
32+
33+
@Override
34+
public void onInitialize(ModContainer mod) {
35+
JumpingMountEvents.FIND_ENTITY_JUMP.register(ExternalJumpingMount.KEY::getNullable);
36+
JumpingMountEvents.FIND_PLAYER_JUMP.register(player -> {
37+
Entity controlledVehicle = player.getControlledVehicle();
38+
return controlledVehicle instanceof LivingEntity living ? JumpingMountEvents.FIND_ENTITY_JUMP.invoker().findJumpingMount(living) : null;
39+
});
40+
}
41+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Requiem
3+
* Copyright (C) 2017-2024 Ladysnake
4+
*
5+
* This program is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 3 of the License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program; If not, see <https://www.gnu.org/licenses>.
17+
*/
18+
package org.ladysnake.vaquero.impl;
19+
20+
import net.minecraft.entity.EntityType;
21+
import net.minecraft.registry.RegistryKeys;
22+
import net.minecraft.registry.tag.TagKey;
23+
24+
public final class VaqueroEntityTypeTags {
25+
public static final TagKey<EntityType<?>> ZOMBIES = register("zombies");
26+
public static final TagKey<EntityType<?>> PIGLINS = register("piglins");
27+
28+
public static TagKey<EntityType<?>> register(String name) {
29+
return TagKey.of(RegistryKeys.ENTITY_TYPE, Vaquero.id(name));
30+
}
31+
}

requiem-api/src/main/java/ladysnake/requiem/api/v1/event/minecraft/JumpingMountEvents.java renamed to requiem-core/vaquero/src/main/java/org/ladysnake/vaquero/impl/jump/DummyHorseJumpingMount.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,23 @@
1515
* You should have received a copy of the GNU Lesser General Public License
1616
* along with this program; If not, see <https://www.gnu.org/licenses>.
1717
*/
18-
package ladysnake.requiem.api.v1.event.minecraft;
18+
package org.ladysnake.vaquero.impl.jump;
1919

20-
import net.fabricmc.fabric.api.event.Event;
21-
import net.fabricmc.fabric.api.event.EventFactory;
22-
import net.minecraft.entity.JumpingMount;
2320
import net.minecraft.entity.LivingEntity;
21+
import net.minecraft.entity.passive.HorseBaseEntity;
22+
import net.minecraft.entity.player.PlayerEntity;
23+
import net.minecraft.sound.SoundEvent;
2424
import org.jetbrains.annotations.Nullable;
2525

26-
public final class JumpingMountEvents {
27-
/**
28-
*
29-
*/
30-
public static final Event<MountCheckCallback> MOUNT_CHECK = EventFactory.createArrayBacked(MountCheckCallback.class, callbacks -> entity -> {
31-
for (MountCheckCallback callback : callbacks) {
32-
JumpingMount mount = callback.getJumpingMount(entity);
33-
if (mount != null) {
34-
return mount;
35-
}
36-
}
37-
return null;
38-
});
26+
import java.util.function.Function;
3927

40-
@FunctionalInterface
41-
public interface MountCheckCallback {
42-
@Nullable JumpingMount getJumpingMount(LivingEntity entity);
28+
public class DummyHorseJumpingMount extends DummyJumpingMount {
29+
public DummyHorseJumpingMount(HorseBaseEntity mob, SoundEvent stepSound, Function<LivingEntity, @Nullable PlayerEntity> getPlayer) {
30+
super(mob, -1, stepSound, getPlayer);
4331
}
4432

33+
@Override
34+
protected double getBaseJumpingStrength() {
35+
return ((HorseBaseEntity) this.mob).getJumpStrength();
36+
}
4537
}

0 commit comments

Comments
 (0)