Changed dependency
Trinkets is now an optional dependency
This commit is contained in:
parent
51d83fabaf
commit
e28e417201
8 changed files with 95 additions and 41 deletions
|
|
@ -10,7 +10,7 @@ loader_version=0.16.14
|
|||
loom_version=1.10-SNAPSHOT
|
||||
|
||||
# Mod Properties
|
||||
mod_version=1.0.1
|
||||
mod_version=1.0.2
|
||||
maven_group=konhaiii.powered_jetpacks
|
||||
archives_base_name=powered_jetpacks
|
||||
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
package konhaiii.powered_jetpacks.hud;
|
||||
|
||||
import dev.emi.trinkets.api.TrinketsApi;
|
||||
import konhaiii.powered_jetpacks.PoweredJetpacks;
|
||||
import konhaiii.powered_jetpacks.item.special.JetpackItem;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Pair;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import static net.minecraft.client.resource.language.I18n.translate;
|
||||
|
||||
|
|
@ -20,13 +23,18 @@ public class JetpackHUD implements HudRenderCallback {
|
|||
if (client.player == null) return;
|
||||
|
||||
ItemStack chestStack = client.player.getEquippedStack(EquipmentSlot.CHEST);
|
||||
ItemStack backStack = TrinketsApi.getTrinketComponent(client.player).map(component ->
|
||||
component.getEquipped(stack -> stack.getItem() instanceof JetpackItem)
|
||||
.stream()
|
||||
.findFirst()
|
||||
.map(Pair::getRight)
|
||||
.orElse(ItemStack.EMPTY)
|
||||
).orElse(ItemStack.EMPTY);
|
||||
ItemStack backStack = ItemStack.EMPTY;
|
||||
|
||||
if (PoweredJetpacks.isTrinketsLoaded) {
|
||||
try {
|
||||
Class<?> optionalClass = Class.forName("konhaiii.powered_jetpacks.compat.TrinketsServer");
|
||||
Method getBackStackMethod = optionalClass.getMethod("getBackStack", LivingEntity.class);
|
||||
backStack = (ItemStack) getBackStackMethod.invoke(null, client.player);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
|
||||
IllegalAccessException e) {
|
||||
PoweredJetpacks.LOGGER.error("Could not load Trinkets compat class.");
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack jetpackStack = isValidJetpack(chestStack) ? chestStack : (!backStack.isEmpty() ? backStack : ItemStack.EMPTY);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
package konhaiii.powered_jetpacks.mixin.client;
|
||||
|
||||
import dev.emi.trinkets.api.TrinketsApi;
|
||||
import konhaiii.powered_jetpacks.PoweredJetpacks;
|
||||
import konhaiii.powered_jetpacks.item.special.JetpackItem;
|
||||
import konhaiii.powered_jetpacks.packet.JetpackPacket;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.Pair;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Unique;
|
||||
|
|
@ -17,6 +17,9 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@Mixin(ClientPlayerEntity.class)
|
||||
public abstract class ClientPlayerEntityMixin {
|
||||
@Unique
|
||||
|
|
@ -26,13 +29,19 @@ public abstract class ClientPlayerEntityMixin {
|
|||
private void onTick(CallbackInfo ci) {
|
||||
ClientPlayerEntity player = (ClientPlayerEntity) (Object) this;
|
||||
ItemStack chestStack = player.getEquippedStack(EquipmentSlot.CHEST);
|
||||
ItemStack backStack = TrinketsApi.getTrinketComponent(player).map(component ->
|
||||
component.getEquipped(stack -> stack.getItem() instanceof JetpackItem)
|
||||
.stream()
|
||||
.findFirst()
|
||||
.map(Pair::getRight)
|
||||
.orElse(ItemStack.EMPTY)
|
||||
).orElse(ItemStack.EMPTY);
|
||||
ItemStack backStack = ItemStack.EMPTY;
|
||||
|
||||
if (PoweredJetpacks.isTrinketsLoaded) {
|
||||
try {
|
||||
Class<?> optionalClass = Class.forName("konhaiii.powered_jetpacks.compat.TrinketsServer");
|
||||
Method getBackStackMethod = optionalClass.getMethod("getBackStack", LivingEntity.class);
|
||||
backStack = (ItemStack) getBackStackMethod.invoke(null, player);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
|
||||
IllegalAccessException e) {
|
||||
PoweredJetpacks.LOGGER.error("Could not load Trinkets compat class.");
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack jetpackStack = null;
|
||||
if (isValidJetpack(chestStack)) {
|
||||
jetpackStack = chestStack;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package konhaiii.powered_jetpacks.renderers;
|
||||
|
||||
import dev.emi.trinkets.api.TrinketsApi;
|
||||
import konhaiii.powered_jetpacks.PoweredJetpacks;
|
||||
import konhaiii.powered_jetpacks.item.ModItems;
|
||||
import konhaiii.powered_jetpacks.item.special.JetpackItem;
|
||||
|
|
@ -17,9 +16,11 @@ import net.minecraft.entity.EquipmentSlot;
|
|||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Pair;
|
||||
import net.minecraft.util.math.RotationAxis;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class JetpackRenderer<T extends LivingEntity, M extends EntityModel<T>> extends FeatureRenderer<T, M> {
|
||||
private final JetpackModel<T> jetpackModel;
|
||||
private static final Identifier BASIC_JETPACK_TEXTURE = new Identifier(PoweredJetpacks.MOD_ID, "textures/jetpack/basic_jetpack.png");
|
||||
|
|
@ -34,14 +35,17 @@ public class JetpackRenderer<T extends LivingEntity, M extends EntityModel<T>> e
|
|||
@Override
|
||||
public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light, T entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) {
|
||||
ItemStack chestStack = entity.getEquippedStack(EquipmentSlot.CHEST);
|
||||
|
||||
ItemStack backStack = TrinketsApi.getTrinketComponent(entity).map(component ->
|
||||
component.getEquipped(stack -> stack.getItem() instanceof JetpackItem)
|
||||
.stream()
|
||||
.findFirst()
|
||||
.map(Pair::getRight)
|
||||
.orElse(ItemStack.EMPTY)
|
||||
).orElse(ItemStack.EMPTY);
|
||||
ItemStack backStack = ItemStack.EMPTY;
|
||||
if (PoweredJetpacks.isTrinketsLoaded) {
|
||||
try {
|
||||
Class<?> optionalClass = Class.forName("konhaiii.powered_jetpacks.compat.TrinketsClient");
|
||||
Method getBackStackMethod = optionalClass.getMethod("getBackStackLivingEntity", LivingEntity.class);
|
||||
backStack = (ItemStack) getBackStackMethod.invoke(null, entity);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
|
||||
IllegalAccessException e) {
|
||||
PoweredJetpacks.LOGGER.error("Could not load Trinkets compat class.");
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack jetpackStack = isValidJetpack(chestStack) ? chestStack : (!backStack.isEmpty() ? backStack : ItemStack.EMPTY);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import konhaiii.powered_jetpacks.sounds.ModSounds;
|
|||
import net.fabricmc.api.ModInitializer;
|
||||
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -14,10 +15,14 @@ public class PoweredJetpacks implements ModInitializer {
|
|||
public static final String MOD_ID = "powered_jetpacks";
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
|
||||
public static ModConfig config;
|
||||
public static boolean isTrinketsLoaded = false;
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
LOGGER.info("Initialize");
|
||||
if (FabricLoader.getInstance().isModLoaded("trinkets")) {
|
||||
isTrinketsLoaded = true;
|
||||
PoweredJetpacks.LOGGER.info("TRINKETS LOADED");
|
||||
}
|
||||
config = ModConfig.loadConfig();
|
||||
ModItems.initialize();
|
||||
ModSounds.initialize();
|
||||
|
|
@ -25,5 +30,6 @@ public class PoweredJetpacks implements ModInitializer {
|
|||
JetpackPacket packet = JetpackPacket.decode(buf);
|
||||
server.execute(() -> JetpackPacket.handle(player, packet));
|
||||
});
|
||||
LOGGER.info("Initialization completed.");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package konhaiii.powered_jetpacks.compat;
|
||||
|
||||
import dev.emi.trinkets.api.TrinketsApi;
|
||||
import konhaiii.powered_jetpacks.item.special.JetpackItem;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Pair;
|
||||
|
||||
public class TrinketsServer {
|
||||
|
||||
public static ItemStack getBackStack(LivingEntity player) {
|
||||
return TrinketsApi.getTrinketComponent(player).map(component ->
|
||||
component.getEquipped(stack -> stack.getItem() instanceof JetpackItem)
|
||||
.stream()
|
||||
.findFirst()
|
||||
.map(Pair::getRight)
|
||||
.orElse(ItemStack.EMPTY)
|
||||
).orElse(ItemStack.EMPTY);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,18 @@
|
|||
package konhaiii.powered_jetpacks.item.special;
|
||||
|
||||
import dev.emi.trinkets.api.TrinketItem;
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ArmorItem;
|
||||
import net.minecraft.item.Equipment;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.world.World;
|
||||
import team.reborn.energy.api.base.SimpleEnergyItem;
|
||||
|
||||
public class JetpackItem extends TrinketItem implements SimpleEnergyItem, Equipment {
|
||||
public class JetpackItem extends Item implements SimpleEnergyItem, Equipment {
|
||||
private final int maxEnergy;
|
||||
private final int inputEnergy;
|
||||
private final float flightPower;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package konhaiii.powered_jetpacks.packet;
|
||||
|
||||
import dev.emi.trinkets.api.TrinketsApi;
|
||||
import konhaiii.powered_jetpacks.PoweredJetpacks;
|
||||
import konhaiii.powered_jetpacks.item.special.JetpackItem;
|
||||
import konhaiii.powered_jetpacks.sounds.ModSounds;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
|
|
@ -12,11 +12,13 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
|||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Pair;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public record JetpackPacket(boolean shouldPlaySound) {
|
||||
private static final Identifier PACKET_ID = new Identifier(PoweredJetpacks.MOD_ID, "jetpack_packet");
|
||||
|
||||
|
|
@ -30,14 +32,19 @@ public record JetpackPacket(boolean shouldPlaySound) {
|
|||
|
||||
public static void handle(ServerPlayerEntity player, JetpackPacket packet) {
|
||||
ItemStack chestStack = player.getEquippedStack(EquipmentSlot.CHEST);
|
||||
ItemStack backStack = ItemStack.EMPTY;
|
||||
|
||||
if (PoweredJetpacks.isTrinketsLoaded) {
|
||||
try {
|
||||
Class<?> optionalClass = Class.forName("konhaiii.powered_jetpacks.compat.TrinketsServer");
|
||||
Method getBackStackMethod = optionalClass.getMethod("getBackStack", LivingEntity.class);
|
||||
backStack = (ItemStack) getBackStackMethod.invoke(null, player);
|
||||
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException |
|
||||
IllegalAccessException e) {
|
||||
PoweredJetpacks.LOGGER.error("Could not load Trinkets compat class.");
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack backStack = TrinketsApi.getTrinketComponent(player).map(component ->
|
||||
component.getEquipped(stack -> stack.getItem() instanceof JetpackItem)
|
||||
.stream()
|
||||
.findFirst()
|
||||
.map(Pair::getRight)
|
||||
.orElse(ItemStack.EMPTY)
|
||||
).orElse(ItemStack.EMPTY);
|
||||
ItemStack jetpackStack = null;
|
||||
if (isValidJetpack(chestStack)) {
|
||||
jetpackStack = chestStack;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue