[Feature] Generalized Elytra API to simplify Trinkets integration
This commit is contained in:
parent
104b87d874
commit
b9ee21085b
3 changed files with 43 additions and 3 deletions
|
@ -1,6 +1,9 @@
|
|||
package org.betterx.bclib.items.elytra;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.gameevent.GameEvent;
|
||||
|
||||
import net.fabricmc.fabric.api.entity.event.v1.FabricElytraItem;
|
||||
|
||||
|
@ -8,4 +11,18 @@ public interface BCLElytraItem extends FabricElytraItem {
|
|||
ResourceLocation getModelTexture();
|
||||
|
||||
double getMovementFactor();
|
||||
|
||||
default void doVanillaElytraTick(LivingEntity entity, ItemStack chestStack) {
|
||||
if (BCLElytraUtils.onBreak == null) ((FabricElytraItem) this).doVanillaElytraTick(entity, chestStack);
|
||||
|
||||
int nextRoll = entity.getFallFlyingTicks() + 1;
|
||||
|
||||
if (!entity.level.isClientSide && nextRoll % 10 == 0) {
|
||||
if ((nextRoll / 10) % 2 == 0) {
|
||||
chestStack.hurtAndBreak(1, entity, (e) -> BCLElytraUtils.onBreak.accept(e, chestStack));
|
||||
}
|
||||
|
||||
entity.gameEvent(GameEvent.ELYTRA_GLIDE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package org.betterx.bclib.items.elytra;
|
||||
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class BCLElytraUtils {
|
||||
@FunctionalInterface
|
||||
public interface SlotProvider {
|
||||
ItemStack getElytra(LivingEntity entity, Function<EquipmentSlot, ItemStack> slotGetter);
|
||||
}
|
||||
|
||||
public static SlotProvider slotProvider = null;
|
||||
public static BiConsumer<LivingEntity, ItemStack> onBreak = null;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue