Skip to content

Commit

Permalink
Some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
RawDiamondMC committed Sep 21, 2024
1 parent 5460c5c commit 8e4560e
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import net.fabricmc.api.ModInitializer;

public final class KessokuBaseEntrypoint implements ModInitializer {
public final class KessokuBaseFabric implements ModInitializer {
@Override
public void onInitialize() {
ModUtils.getLogger().info(KessokuBase.MARKER, "KessokuLib-Base is loaded!");
Expand Down
2 changes: 1 addition & 1 deletion base/fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"icon": "icon.png",
"entrypoints": {
"main": [
"band.kessoku.lib.base.KessokuBaseEntrypoint"
"band.kessoku.lib.base.KessokuBaseFabric"
]
},
"environment": "*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import net.neoforged.fml.common.Mod;

@Mod(KessokuBase.MOD_ID)
public final class KessokuBaseEntrypoint {
public KessokuBaseEntrypoint() {
public final class KessokuBaseEntrypointNeoforge {
public KessokuBaseEntrypointNeoforge() {
ModUtils.getLogger().info(KessokuBase.MARKER, "KessokuLib-Base is loaded!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import band.kessoku.lib.base.ModUtils;
import net.fabricmc.api.ModInitializer;

public class KessokuDataEntrypoint implements ModInitializer {
public final class KessokuDataEntrypoint implements ModInitializer {
@Override
public void onInitialize() {
ModUtils.getLogger().info(KessokuData.MARKER, "KessokuLib-BlockEntity is Loaded!");
Expand Down
5 changes: 5 additions & 0 deletions data/fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
},
"license": "LGPL-3.0-only",
"icon": "icon.png",
"entrypoints": {
"main": [
"band.kessoku.lib.data.KessokuDataEntrypoint"
]
},
"environment": "*",
"depends": {
"fabricloader": ">=0.16.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,25 @@
*/
package band.kessoku.lib.events.entity;

import band.kessoku.lib.events.entity.api.EntityElytraEvent;
import band.kessoku.lib.events.entity.api.item.KessokuElytraItem;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.item.ItemStack;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

public class KessokuEntityEvents {
public final class KessokuEntityEvents {
public static final String MOD_ID = "kessoku_entity_events";
public static final Marker MARKER = MarkerFactory.getMarker("[KessokuEntityEvents]");
static void init() {
EntityElytraEvent.CUSTOM.register((entity, tickElytra) -> {
ItemStack chestStack = entity.getEquippedStack(EquipmentSlot.CHEST);

if (chestStack.getItem() instanceof KessokuElytraItem fabricElytraItem) {
return fabricElytraItem.useCustomElytra(entity, chestStack, tickElytra);
}

return false;
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@

import band.kessoku.lib.event.api.Event;
import band.kessoku.lib.events.entity.api.item.KessokuElytraItem;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.item.ItemStack;
import org.jetbrains.annotations.ApiStatus;

/**
* Events related to elytra flight for living entities. Elytra flight is also known as "fall flying".
*/
public class EntityElytraEvent {
@ApiStatus.NonExtendable
public interface EntityElytraEvent {

/**
* An event to check if elytra flight (both through normal and custom elytras) is allowed.
* All listeners need to return true to allow the entity to fly, otherwise elytra flight will be blocked/stopped.
*/
public static final Event<Allow> ALLOW = Event.of(listeners -> entity -> {
Event<Allow> ALLOW = Event.of(listeners -> entity -> {
for (Allow listener : listeners) {
if (!listener.allowElytraFlight(entity)) {
return false;
Expand All @@ -47,7 +47,7 @@ public class EntityElytraEvent {
*
* <p>Items that wish to enable custom elytra flight when worn in the chest equipment slot can simply implement {@link KessokuElytraItem} instead of registering a listener.
*/
public static final Event<Custom> CUSTOM = Event.of(listeners -> (entity, tickElytra) -> {
Event<Custom> CUSTOM = Event.of(listeners -> (entity, tickElytra) -> {
for (Custom listener : listeners) {
if (listener.useCustomElytra(entity, tickElytra)) {
return true;
Expand All @@ -57,28 +57,16 @@ public class EntityElytraEvent {
return false;
});

static {
CUSTOM.register((entity, tickElytra) -> {
ItemStack chestStack = entity.getEquippedStack(EquipmentSlot.CHEST);

if (chestStack.getItem() instanceof KessokuElytraItem fabricElytraItem) {
return fabricElytraItem.useCustomElytra(entity, chestStack, tickElytra);
}

return false;
});
}

@FunctionalInterface
public interface Allow {
interface Allow {
/**
* @return false to block elytra flight, true to allow it (unless another listener returns false)
*/
boolean allowElytraFlight(LivingEntity entity);
}

@FunctionalInterface
public interface Custom {
interface Custom {
/**
* Try to use a custom elytra for an entity.
* A custom elytra is anything that allows an entity to enter and continue elytra flight when some condition is met.
Expand All @@ -104,8 +92,4 @@ public interface Custom {
*/
boolean useCustomElytra(LivingEntity entity, boolean tickElytra);
}

private EntityElytraEvent() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import net.fabricmc.fabric.api.entity.event.v1.EntityElytraEvents;
import net.fabricmc.fabric.api.entity.event.v1.EntitySleepEvents;

public class KessokuEntityEventEntrypoint implements ModInitializer {
public final class KessokuEntityEventFabric implements ModInitializer {
@Override
public void onInitialize() {
KessokuEntityEvents.init();
EntityElytraEvents.ALLOW.register(entity -> EntityElytraEvent.ALLOW.invoker().allowElytraFlight(entity));
EntityElytraEvents.CUSTOM.register((entity, tickElytra) -> EntityElytraEvent.CUSTOM.invoker().useCustomElytra(entity, tickElytra));

Expand Down
36 changes: 36 additions & 0 deletions entity-events/fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"schemaVersion": 1,
"id": "kessoku_entity_events",
"version": "${version}",
"name": "Kessoku Entity Events API",
"description": "Provide some events about entity.",
"authors": [
"Kessoku Tea Time"
],
"contact": {
"homepage": "https://modrinth.com/mod/kessoku-lib",
"sources": "https://github.com/KessokuTeaTime/KessokuLib",
"issues": "https://github.com/KessokuTeaTime/KessokuLib/issues"
},
"license": "LGPL-3.0-only",
"icon": "icon.png",
"entrypoints": {
"main": [
"band.kessoku.lib.events.entity.KessokuEntityEventFabric"
]
},
"environment": "*",
"depends": {
"fabricloader": ">=0.16.0",
"minecraft": "1.21",
"java": ">=21",
"fabric-api": "*"
},
"custom": {
"modmenu": {
"badges": [
"library"
]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
import net.neoforged.neoforge.event.entity.player.PlayerEvent;

@Mod(KessokuEntityEvents.MOD_ID)
public class KessokuEntityEventEntrypoint {
public KessokuEntityEventEntrypoint() {
public final class KessokuEntityEventNeoforge {
public KessokuEntityEventNeoforge() {
KessokuEntityEvents.init();
NeoEventUtils.registerEvent(NeoForge.EVENT_BUS, LivingIncomingDamageEvent.class, event -> {
var entity = event.getEntity();
if (!entity.getWorld().isClient() && ServerLivingEntityEvent.ALLOW_DAMAGE.invoker().allowDamage(entity, event.getSource(), event.getAmount())) {
Expand Down

0 comments on commit 8e4560e

Please sign in to comment.