[Feature] Trinket Support for BE-Elytra
This commit is contained in:
parent
36b75ed25f
commit
f3ceaa8c72
10 changed files with 166 additions and 9 deletions
|
@ -0,0 +1,101 @@
|
|||
package org.betterx.betterend.integration.trinkets;
|
||||
|
||||
import org.betterx.bclib.items.elytra.BCLElytraItem;
|
||||
import org.betterx.bclib.items.elytra.BCLElytraUtils;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Tuple;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.ElytraItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
import net.fabricmc.fabric.api.entity.event.v1.EntityElytraEvents;
|
||||
import net.fabricmc.fabric.api.entity.event.v1.FabricElytraItem;
|
||||
|
||||
import dev.emi.trinkets.api.SlotReference;
|
||||
import dev.emi.trinkets.api.TrinketComponent;
|
||||
import dev.emi.trinkets.api.TrinketsApi;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Elytra {
|
||||
private static boolean isElytra(ItemStack stack) {
|
||||
return stack.getItem() instanceof ElytraItem
|
||||
|| stack.getItem() instanceof FabricElytraItem;
|
||||
}
|
||||
|
||||
public static void register() {
|
||||
BCLElytraUtils.slotProvider = (entity, slotGetter) -> {
|
||||
ItemStack itemStack = slotGetter.apply(EquipmentSlot.CHEST);
|
||||
if (isElytra(itemStack)) return itemStack;
|
||||
|
||||
Optional<TrinketComponent> oTrinketComponent = TrinketsApi.getTrinketComponent(entity);
|
||||
if (oTrinketComponent.isPresent()) {
|
||||
List<Tuple<SlotReference, ItemStack>> equipped =
|
||||
oTrinketComponent.get().getEquipped(Elytra::isElytra);
|
||||
|
||||
if (!equipped.isEmpty()) return equipped.get(0).getB();
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
BCLElytraUtils.onBreak = (entity, chestStack) -> {
|
||||
Optional<TrinketComponent> oTrinketComponent = TrinketsApi.getTrinketComponent(entity);
|
||||
if (oTrinketComponent.isPresent()) {
|
||||
List<Tuple<SlotReference, ItemStack>> equipped =
|
||||
oTrinketComponent.get().getEquipped(Elytra::isElytra);
|
||||
|
||||
for (Tuple<SlotReference, ItemStack> slot : equipped) {
|
||||
ItemStack slotStack = slot.getB();
|
||||
if (slotStack == chestStack) {
|
||||
TrinketsApi.onTrinketBroken(slotStack, slot.getA(), entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
EntityElytraEvents.CUSTOM.register(Elytra::useElytraTrinket);
|
||||
}
|
||||
|
||||
private static boolean useElytraTrinket(LivingEntity entity, boolean tickElytra) {
|
||||
Optional<TrinketComponent> oTrinketComponent = TrinketsApi.getTrinketComponent(entity);
|
||||
if (oTrinketComponent.isPresent()) {
|
||||
List<Tuple<SlotReference, ItemStack>> equipped =
|
||||
oTrinketComponent.get().getEquipped(Elytra::isElytra);
|
||||
|
||||
for (Tuple<SlotReference, ItemStack> slot : equipped) {
|
||||
ItemStack stack = slot.getB();
|
||||
Item item = stack.getItem();
|
||||
|
||||
if (item instanceof ElytraItem) {
|
||||
if (ElytraItem.isFlyEnabled(stack)) {
|
||||
INSTANCE.doVanillaElytraTick(entity, stack);
|
||||
return true;
|
||||
}
|
||||
} else if (item instanceof FabricElytraItem fabricElytraItem) {
|
||||
if (fabricElytraItem.useCustomElytra(entity, stack, tickElytra)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final BCLElytraItem INSTANCE = new BCLElytraItem() {
|
||||
@Override
|
||||
public ResourceLocation getModelTexture() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMovementFactor() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package org.betterx.betterend.integration.trinkets;
|
||||
|
||||
import net.minecraft.world.item.ElytraItem;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.LivingEntityFeatureRenderEvents;
|
||||
import net.fabricmc.fabric.api.entity.event.v1.FabricElytraItem;
|
||||
|
||||
import dev.emi.trinkets.api.TrinketsApi;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ElytraClient {
|
||||
public static void register() {
|
||||
LivingEntityFeatureRenderEvents.ALLOW_CAPE_RENDER.register((player) -> TrinketsApi
|
||||
.getTrinketComponent(player)
|
||||
.map(trinketComponent -> trinketComponent.getEquipped(
|
||||
stack -> stack.getItem() instanceof ElytraItem ||
|
||||
stack.getItem() instanceof FabricElytraItem
|
||||
).size() == 0).orElse(true));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue