-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #666 from Ladysnake/refacto/riding
Refactor riding and jumping APIs into a separate module
- Loading branch information
Showing
48 changed files
with
892 additions
and
585 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
requiem-core/vaquero/src/main/java/org/ladysnake/vaquero/api/MobRidingType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
requiem-core/vaquero/src/main/java/org/ladysnake/vaquero/api/events/JumpingMountEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
requiem-core/vaquero/src/main/java/org/ladysnake/vaquero/api/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
41 changes: 41 additions & 0 deletions
41
requiem-core/vaquero/src/main/java/org/ladysnake/vaquero/impl/Vaquero.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
requiem-core/vaquero/src/main/java/org/ladysnake/vaquero/impl/VaqueroEntityTypeTags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.