diff --git a/src/main/java/mc/duzo/timeless/client/TimelessClient.java b/src/main/java/mc/duzo/timeless/client/TimelessClient.java index fc477ef..80a561e 100644 --- a/src/main/java/mc/duzo/timeless/client/TimelessClient.java +++ b/src/main/java/mc/duzo/timeless/client/TimelessClient.java @@ -7,6 +7,7 @@ import mc.duzo.animation.player.holder.PlayerAnimationHolder; import mc.duzo.animation.registry.AnimationRegistry; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; import net.minecraft.util.Identifier; @@ -15,6 +16,8 @@ import mc.duzo.timeless.client.gui.JarvisGui; import mc.duzo.timeless.client.keybind.TimelessKeybinds; import mc.duzo.timeless.client.network.ClientNetwork; +import mc.duzo.timeless.client.render.entity.IronManEntityRenderer; +import mc.duzo.timeless.registry.Register; import mc.duzo.timeless.suit.Suit; import mc.duzo.timeless.suit.client.ClientSuitRegistry; import mc.duzo.timeless.suit.client.animation.SuitAnimationHolder; @@ -26,7 +29,7 @@ public class TimelessClient implements ClientModInitializer { @Override public void onInitializeClient() { - Animations.init(); + ClientRegister.init(); ClientNetwork.init(); ClientSuitRegistry.init(); TimelessKeybinds.init(); @@ -36,51 +39,65 @@ public void onInitializeClient() { }); } - public static class Animations { + public static class ClientRegister { + public static void init() { + Animations.init(); + Renderers.init(); + } - public static class Players { - public static final Supplier MARK_FIVE_CASE_OPEN = AnimationRegistry.instance().register(() -> new PlayerAnimationHolder(new Identifier(Timeless.MOD_ID, "ironman_mk5_case_open_player"), MarkFiveAnimations.CASE_OPEN_PLAYER)); - public static final Supplier MARK_FIVE_CASE_CLOSE = AnimationRegistry.instance().register(() -> new PlayerAnimationHolder(new Identifier(Timeless.MOD_ID, "ironman_mk5_case_close_player"), MarkFiveAnimations.CASE_CLOSE_PLAYER)); + public static class Animations { - public static void init() {} + public static class Players { + public static final Supplier MARK_FIVE_CASE_OPEN = AnimationRegistry.instance().register(() -> new PlayerAnimationHolder(new Identifier(Timeless.MOD_ID, "ironman_mk5_case_open_player"), MarkFiveAnimations.CASE_OPEN_PLAYER)); + public static final Supplier MARK_FIVE_CASE_CLOSE = AnimationRegistry.instance().register(() -> new PlayerAnimationHolder(new Identifier(Timeless.MOD_ID, "ironman_mk5_case_close_player"), MarkFiveAnimations.CASE_CLOSE_PLAYER)); - } - public static class Suits { - public static class MarkFive { - public static final Supplier CASE_OPEN = AnimationRegistry.instance().register(() -> new MarkFiveCaseAnimation(true)); - public static final Supplier CASE_CLOSE = AnimationRegistry.instance().register(() -> new MarkFiveCaseAnimation(false)); - public static final Supplier MASK_OPEN = AnimationRegistry.instance().register(() -> new MarkFiveMaskAnimation(true)); - public static final Supplier MASK_CLOSE = AnimationRegistry.instance().register(() -> new MarkFiveMaskAnimation(false)); + public static void init() {} - public static void init() { + } + public static class Suits { + public static class MarkFive { + public static final Supplier CASE_OPEN = AnimationRegistry.instance().register(() -> new MarkFiveCaseAnimation(true)); + public static final Supplier CASE_CLOSE = AnimationRegistry.instance().register(() -> new MarkFiveCaseAnimation(false)); + public static final Supplier MASK_OPEN = AnimationRegistry.instance().register(() -> new MarkFiveMaskAnimation(true)); + public static final Supplier MASK_CLOSE = AnimationRegistry.instance().register(() -> new MarkFiveMaskAnimation(false)); + public static void init() { + + } + } + public static class IronMan { + public static final Supplier MASK_OPEN = AnimationRegistry.instance().register(() -> new SuitAnimationHolder(new Identifier(Timeless.MOD_ID, "ironman_generic_mask_open"), GenericIronManAnimations.MASK_OPEN, new AnimationInfo(AnimationInfo.RenderType.TORSO_HEAD, null, AnimationInfo.Movement.ALLOW, AnimationInfo.Transform.TARGETED), false)); + public static final Supplier MASK_CLOSE = AnimationRegistry.instance().register(() -> new SuitAnimationHolder(new Identifier(Timeless.MOD_ID, "ironman_generic_mask_close"), GenericIronManAnimations.MASK_CLOSE, new AnimationInfo(AnimationInfo.RenderType.TORSO_HEAD, null, AnimationInfo.Movement.ALLOW, AnimationInfo.Transform.TARGETED), false)); + + public static void init() { + + } } - } - public static class IronMan { - public static final Supplier MASK_OPEN = AnimationRegistry.instance().register(() -> new SuitAnimationHolder(new Identifier(Timeless.MOD_ID, "ironman_generic_mask_open"), GenericIronManAnimations.MASK_OPEN, new AnimationInfo(AnimationInfo.RenderType.TORSO_HEAD, null, AnimationInfo.Movement.ALLOW, AnimationInfo.Transform.TARGETED), false)); - public static final Supplier MASK_CLOSE = AnimationRegistry.instance().register(() -> new SuitAnimationHolder(new Identifier(Timeless.MOD_ID, "ironman_generic_mask_close"), GenericIronManAnimations.MASK_CLOSE, new AnimationInfo(AnimationInfo.RenderType.TORSO_HEAD, null, AnimationInfo.Movement.ALLOW, AnimationInfo.Transform.TARGETED), false)); public static void init() { + IronMan.init(); + MarkFive.init(); + + AnimationEvents.FIND_ANIMATION_INFO.register(player -> { + Suit suit = Suit.findSuit(player).orElse(null); + if (suit == null) return AnimationEvents.Result.pass(); + return new AnimationEvents.Result<>(suit.toClient().getAnimationInfo(player)); + }); } } public static void init() { - IronMan.init(); - MarkFive.init(); - - AnimationEvents.FIND_ANIMATION_INFO.register(player -> { - Suit suit = Suit.findSuit(player).orElse(null); - if (suit == null) return AnimationEvents.Result.pass(); - - return new AnimationEvents.Result<>(suit.toClient().getAnimationInfo(player)); - }); + Players.init(); + Suits.init(); } } - public static void init() { - Players.init(); - Suits.init(); + public static class Renderers { + public static void init() { + EntityRendererRegistry.register(Register.Entities.IRON_MAN, IronManEntityRenderer::new); + } } } + } diff --git a/src/main/java/mc/duzo/timeless/client/gui/JarvisGui.java b/src/main/java/mc/duzo/timeless/client/gui/JarvisGui.java index a0521d2..58773ce 100644 --- a/src/main/java/mc/duzo/timeless/client/gui/JarvisGui.java +++ b/src/main/java/mc/duzo/timeless/client/gui/JarvisGui.java @@ -20,7 +20,7 @@ public class JarvisGui { private static final Identifier HUD = new Identifier(Timeless.MOD_ID, "textures/gui/jarvis/hud.png"); - private static final int ALPHA_GRAY = ColorHelper.Argb.getArgb(125, 255, 255 ,255); + private static final int ALPHA_GRAY = ColorHelper.Argb.getArgb(125, 255, 255, 255); public static void render(DrawContext context, float delta) { MinecraftClient client = MinecraftClient.getInstance(); @@ -34,6 +34,7 @@ public static void render(DrawContext context, float delta) { if (!(suit.hasPower(PowerRegistry.JARVIS))) return; if (suit.hasPower(PowerRegistry.MASK_TOGGLE) && !(MaskTogglePower.hasMask(player))) return; + // has flight boolean hasFlight = FlightPower.hasFlight(player); boolean hasHover = HoverPower.hasHover(player); diff --git a/src/main/java/mc/duzo/timeless/client/render/entity/IronManEntityRenderer.java b/src/main/java/mc/duzo/timeless/client/render/entity/IronManEntityRenderer.java new file mode 100644 index 0000000..6cd9a5f --- /dev/null +++ b/src/main/java/mc/duzo/timeless/client/render/entity/IronManEntityRenderer.java @@ -0,0 +1,50 @@ +package mc.duzo.timeless.client.render.entity; + +import net.minecraft.client.render.LightmapTextureManager; +import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.render.VertexConsumer; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.entity.EntityRenderer; +import net.minecraft.client.render.entity.EntityRendererFactory; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.RotationAxis; + +import mc.duzo.timeless.suit.client.render.SuitModel; +import mc.duzo.timeless.suit.ironman.IronManEntity; +import mc.duzo.timeless.suit.ironman.IronManSuit; + +public class IronManEntityRenderer extends EntityRenderer { + public IronManEntityRenderer(EntityRendererFactory.Context ctx) { + super(ctx); + } + + @Override + public void render(IronManEntity entity, float yaw, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) { + super.render(entity, yaw, tickDelta, matrices, vertexConsumers, light); + + IronManSuit suit = entity.getSuit(); + SuitModel model = suit.toClient().model(); + VertexConsumer consumer = vertexConsumers.getBuffer(RenderLayer.getEntityTranslucent(model.texture())); + + matrices.push(); + + matrices.translate(0, 3, 0); + matrices.multiply(RotationAxis.POSITIVE_Y.rotationDegrees(entity.getYaw())); // todo - rotation is wrong + matrices.multiply(RotationAxis.POSITIVE_X.rotationDegrees(180)); + + model.render(entity, tickDelta, matrices, consumer, light, 1, 1, 1, 1); // todo - the model appears to be global, meaning all transforms to one get applied to all. needs fixing ASAP + + if (model.emission().isPresent()) { + VertexConsumer emissionConsumer = vertexConsumers.getBuffer(RenderLayer.getEntityCutoutNoCullZOffset(model.emission().get(), true)); + model.render(entity, tickDelta, matrices, emissionConsumer, LightmapTextureManager.MAX_LIGHT_COORDINATE, 1, 1, 1, 1); + } + + matrices.pop(); + } + + @Override + public Identifier getTexture(IronManEntity entity) { + return entity.getSuit().toClient().texture(); + } +} diff --git a/src/main/java/mc/duzo/timeless/power/PowerRegistry.java b/src/main/java/mc/duzo/timeless/power/PowerRegistry.java index bb22fd4..aa29e2c 100644 --- a/src/main/java/mc/duzo/timeless/power/PowerRegistry.java +++ b/src/main/java/mc/duzo/timeless/power/PowerRegistry.java @@ -12,6 +12,9 @@ import mc.duzo.timeless.power.impl.HoverPower; import mc.duzo.timeless.power.impl.IceOverPower; import mc.duzo.timeless.power.impl.MaskTogglePower; +import mc.duzo.timeless.suit.Suit; +import mc.duzo.timeless.suit.ironman.IronManEntity; +import mc.duzo.timeless.suit.ironman.IronManSuit; import mc.duzo.timeless.suit.ironman.mk5.MarkFiveCase; public class PowerRegistry { @@ -29,6 +32,12 @@ public static T register(T entry) { public static Power JARVIS = Power.Builder.create(new Identifier(Timeless.MOD_ID, "jarvis")).build().register(); public static Power MASK_TOGGLE = new MaskTogglePower().register(); public static Power ICES_OVER = new IceOverPower().register(); + public static Power SENTRY = Power.Builder.create(new Identifier(Timeless.MOD_ID, "sentry")).run((player) -> { + if (!(Suit.findSuit(player).orElse(null) instanceof IronManSuit suit)) return; + + player.getWorld().spawnEntity(new IronManEntity(player.getServerWorld(), suit, player)); + player.getArmorItems().forEach(stack -> stack.setCount(0)); + }).build().register(); public static void init() {} } diff --git a/src/main/java/mc/duzo/timeless/registry/Register.java b/src/main/java/mc/duzo/timeless/registry/Register.java index 65dca49..63160c4 100644 --- a/src/main/java/mc/duzo/timeless/registry/Register.java +++ b/src/main/java/mc/duzo/timeless/registry/Register.java @@ -3,8 +3,14 @@ import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; +import net.fabricmc.fabric.api.object.builder.v1.entity.FabricDefaultAttributeRegistry; import net.minecraft.block.Block; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.SpawnGroup; +import net.minecraft.entity.attribute.DefaultAttributeContainer; +import net.minecraft.entity.mob.MobEntity; import net.minecraft.item.BlockItem; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; @@ -20,6 +26,7 @@ import mc.duzo.timeless.power.PowerRegistry; import mc.duzo.timeless.suit.SuitRegistry; import mc.duzo.timeless.suit.client.animation.SuitAnimationTracker; +import mc.duzo.timeless.suit.ironman.IronManEntity; import mc.duzo.timeless.suit.ironman.mk5.MarkFiveCase; import mc.duzo.timeless.suit.set.SetRegistry; @@ -77,6 +84,20 @@ public static void init() { } } + public static class Entities { + public static final EntityType IRON_MAN = register(Registries.ENTITY_TYPE, "iron_man", EntityType.Builder.create(IronManEntity::new, SpawnGroup.MISC) + .setDimensions(0.6f, 1.8f) + .build("iron_man")); + + public static void init() { + registerAttributes(IRON_MAN, MobEntity.createLivingAttributes().build()); + } + + private static void registerAttributes(EntityType type, DefaultAttributeContainer attributes) { + FabricDefaultAttributeRegistry.register(type, attributes); + } + } + public static void init() { PowerRegistry.init(); SetRegistry.init(); @@ -84,6 +105,7 @@ public static void init() { ItemGroups.init(); Sounds.init(); Trackers.init(); + Entities.init(); } public static T register(Registry registry, String name, T entry) { diff --git a/src/main/java/mc/duzo/timeless/suit/ironman/IronManEntity.java b/src/main/java/mc/duzo/timeless/suit/ironman/IronManEntity.java new file mode 100644 index 0000000..dc81044 --- /dev/null +++ b/src/main/java/mc/duzo/timeless/suit/ironman/IronManEntity.java @@ -0,0 +1,109 @@ +package mc.duzo.timeless.suit.ironman; + +import java.util.List; + +import net.minecraft.entity.EntityType; +import net.minecraft.entity.EquipmentSlot; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.data.DataTracker; +import net.minecraft.entity.data.TrackedData; +import net.minecraft.entity.data.TrackedDataHandlerRegistry; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NbtCompound; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Arm; +import net.minecraft.util.Hand; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +import mc.duzo.timeless.registry.Register; +import mc.duzo.timeless.suit.SuitRegistry; + +public class IronManEntity extends LivingEntity { // todo - PathAwareEntity for sentry mode + private static final TrackedData SUIT = DataTracker.registerData(IronManEntity.class, TrackedDataHandlerRegistry.STRING); + + public IronManEntity(EntityType entityType, World world) { + super(entityType, world); + } + public IronManEntity(World world, IronManSuit suit) { + this(Register.Entities.IRON_MAN, world); + + this.setSuit(suit); + } + public IronManEntity(World world, IronManSuit suit, BlockPos pos, float yaw, float pitch) { + this(world, suit); + + this.refreshPositionAndAngles(pos.getX(), pos.getY(), pos.getZ(), yaw, pitch); + } + public IronManEntity(World world, IronManSuit suit, ServerPlayerEntity source) { + this(world, suit, source.getBlockPos(), source.getYaw(), source.getPitch()); + } + + public IronManSuit getSuit() { + return (IronManSuit) SuitRegistry.REGISTRY.get(new Identifier(this.dataTracker.get(SUIT))); + } + private void setSuit(String string) { + this.dataTracker.set(SUIT, string); + } + private void setSuit(Identifier id) { + this.setSuit(id.toString()); + } + private void setSuit(IronManSuit suit) { + this.setSuit(suit.id()); + } + + @Override + public ActionResult interact(PlayerEntity player, Hand hand) { + boolean success = this.getSuit().getSet().wear(player); + + if (success) { + this.discard(); + } + + return success ? ActionResult.SUCCESS : ActionResult.FAIL; + } + + @Override + protected void initDataTracker() { + super.initDataTracker(); + + this.dataTracker.startTracking(SUIT, ""); + } + + @Override + public void writeCustomDataToNbt(NbtCompound nbt) { + super.writeCustomDataToNbt(nbt); + + nbt.putString("Suit", this.dataTracker.get(SUIT)); + } + + @Override + public void readCustomDataFromNbt(NbtCompound nbt) { + super.readCustomDataFromNbt(nbt); + + this.setSuit(nbt.getString("Suit")); + } + + @Override + public Iterable getArmorItems() { + return List.of(); + } + + @Override + public ItemStack getEquippedStack(EquipmentSlot slot) { + return ItemStack.EMPTY; + } + + @Override + public void equipStack(EquipmentSlot slot, ItemStack stack) { + + } + + @Override + public Arm getMainArm() { + return Arm.RIGHT; + } +} diff --git a/src/main/java/mc/duzo/timeless/suit/ironman/client/GenericIronManModel.java b/src/main/java/mc/duzo/timeless/suit/ironman/client/GenericIronManModel.java index c32e862..69831cc 100644 --- a/src/main/java/mc/duzo/timeless/suit/ironman/client/GenericIronManModel.java +++ b/src/main/java/mc/duzo/timeless/suit/ironman/client/GenericIronManModel.java @@ -9,7 +9,6 @@ import net.minecraft.client.render.entity.model.BipedEntityModel; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.RotationAxis; import net.minecraft.util.math.Vec3d; @@ -104,10 +103,12 @@ public static TexturedModelData getTexturedModelData() { public void render(LivingEntity entity, float tickDelta, MatrixStack matrices, VertexConsumer vertexConsumers, int light, float r, float g, float b, float alpha) { matrices.push(); - SuitAnimationHolder anim = this.getAnimation((AbstractClientPlayerEntity) entity).orElse(null); - if (anim == null || anim.getInfo().transform() == AnimationInfo.Transform.TARGETED) { - this.rotateParts(entity); - matrices.translate(0f, -1.5125f, 0f); + if (entity instanceof AbstractClientPlayerEntity player) { + SuitAnimationHolder anim = this.getAnimation(player).orElse(null); + if (anim == null || anim.getInfo().transform() == AnimationInfo.Transform.TARGETED) { + this.rotateParts(player); + matrices.translate(0f, -1.5125f, 0f); + } } matrices.scale(1.01f, 1.01f, 1.01f); @@ -117,8 +118,8 @@ public void render(LivingEntity entity, float tickDelta, MatrixStack matrices, V matrices.pop(); } - private void rotateParts(LivingEntity entity) { - if (!FlightPower.isFlying((PlayerEntity) entity)) return; + private void rotateParts(AbstractClientPlayerEntity entity) { + if (!FlightPower.isFlying(entity)) return; Vec3d velocity = entity.getVelocity().rotateY(((float) Math.toRadians(entity.getYaw()))); diff --git a/src/main/java/mc/duzo/timeless/suit/ironman/mk3/MarkThreeSuit.java b/src/main/java/mc/duzo/timeless/suit/ironman/mk3/MarkThreeSuit.java index 74d5773..430e599 100644 --- a/src/main/java/mc/duzo/timeless/suit/ironman/mk3/MarkThreeSuit.java +++ b/src/main/java/mc/duzo/timeless/suit/ironman/mk3/MarkThreeSuit.java @@ -23,7 +23,7 @@ public class MarkThreeSuit extends IronManSuit { public MarkThreeSuit() { super("mark_three"); - this.powers = PowerList.of(PowerRegistry.JARVIS, PowerRegistry.FLIGHT, PowerRegistry.HOVER, PowerRegistry.MASK_TOGGLE ); + this.powers = PowerList.of(PowerRegistry.SENTRY, PowerRegistry.FLIGHT, PowerRegistry.HOVER, PowerRegistry.MASK_TOGGLE, PowerRegistry.JARVIS); } @Override diff --git a/src/main/java/mc/duzo/timeless/suit/ironman/mk5/MarkFiveCase.java b/src/main/java/mc/duzo/timeless/suit/ironman/mk5/MarkFiveCase.java index 46262e4..9446702 100644 --- a/src/main/java/mc/duzo/timeless/suit/ironman/mk5/MarkFiveCase.java +++ b/src/main/java/mc/duzo/timeless/suit/ironman/mk5/MarkFiveCase.java @@ -66,7 +66,6 @@ public static boolean fromCase(ServerPlayerEntity player, boolean force) { if (!force) { if (!player.isOnGround()) return false; // not on ground if (!player.getMainHandStack().isOf(Register.Items.MARK_FIVE_CASE)) return false; // not holding - if (hasArmor(player)) return false; // wearing armor } player.getWorld().playSound(null, player.getBlockPos(), Register.Sounds.MARK5_NOISES, SoundCategory.PLAYERS, 0.25f, 1f); @@ -79,13 +78,6 @@ public static boolean fromCase(ServerPlayerEntity player, boolean force) { getSet().wear(player); return true; } - private static boolean hasArmor(ServerPlayerEntity player) { - for (ItemStack stack : player.getArmorItems()) { - if (!(stack.isEmpty())) return true; - } - - return false; - } private static SuitSet getSet() { return SetRegistry.MARK_FIVE; diff --git a/src/main/java/mc/duzo/timeless/suit/ironman/mk5/client/MarkFiveModel.java b/src/main/java/mc/duzo/timeless/suit/ironman/mk5/client/MarkFiveModel.java index 7a3a5eb..1fb488a 100644 --- a/src/main/java/mc/duzo/timeless/suit/ironman/mk5/client/MarkFiveModel.java +++ b/src/main/java/mc/duzo/timeless/suit/ironman/mk5/client/MarkFiveModel.java @@ -9,7 +9,6 @@ import net.minecraft.client.render.entity.model.BipedEntityModel; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.RotationAxis; import net.minecraft.util.math.Vec3d; @@ -260,10 +259,12 @@ public static TexturedModelData getTexturedModelData() { public void render(LivingEntity entity, float tickDelta, MatrixStack matrices, VertexConsumer vertexConsumers, int light, float r, float g, float b, float alpha) { matrices.push(); - SuitAnimationHolder anim = this.getAnimation((AbstractClientPlayerEntity) entity).orElse(null); - if (anim == null || anim.getInfo().transform() == AnimationInfo.Transform.TARGETED) { - this.rotateParts(entity); - matrices.translate(0f, -0.2f, 0f); + if (entity instanceof AbstractClientPlayerEntity player) { + SuitAnimationHolder anim = this.getAnimation(player).orElse(null); + if (anim == null || anim.getInfo().transform() == AnimationInfo.Transform.TARGETED) { + this.rotateParts(player); + matrices.translate(0f, -0.2f, 0f); + } } matrices.scale(1.0125f, 1.0125f, 1.0125f); @@ -273,8 +274,8 @@ public void render(LivingEntity entity, float tickDelta, MatrixStack matrices, V matrices.pop(); } - private void rotateParts(LivingEntity entity) { - if (!FlightPower.isFlying((PlayerEntity) entity)) return; + private void rotateParts(AbstractClientPlayerEntity entity) { + if (!FlightPower.isFlying(entity)) return; Vec3d velocity = entity.getVelocity().rotateY(((float) Math.toRadians(entity.getYaw()))); diff --git a/src/main/java/mc/duzo/timeless/suit/set/SuitSet.java b/src/main/java/mc/duzo/timeless/suit/set/SuitSet.java index d8d3df3..d6e1a88 100644 --- a/src/main/java/mc/duzo/timeless/suit/set/SuitSet.java +++ b/src/main/java/mc/duzo/timeless/suit/set/SuitSet.java @@ -28,6 +28,7 @@ public SuitSet(Suit suit, SuitItem... items) { public SuitSet(Suit suit, BiFunction func) { this(suit, func.apply(suit, ArmorItem.Type.HELMET), func.apply(suit, ArmorItem.Type.CHESTPLATE), func.apply(suit, ArmorItem.Type.LEGGINGS), func.apply(suit, ArmorItem.Type.BOOTS)); } + protected void put(SuitItem item) { if (!(this.suit.equals(item.getSuit()))) throw new IllegalArgumentException("SuitItem does not match this.suit"); @@ -48,6 +49,14 @@ public Suit suit() { return this.suit; } + public static boolean hasArmor(LivingEntity entity) { + for (ItemStack stack : entity.getArmorItems()) { + if (!(stack.isEmpty())) return true; + } + + return false; + } + public boolean isWearing(LivingEntity entity) { int target = this.values().size(); int count = 0; @@ -60,8 +69,11 @@ public boolean isWearing(LivingEntity entity) { return count == target; } - public void wear(LivingEntity entity) { + public boolean wear(LivingEntity entity) { + if (hasArmor(entity)) return false; + this.values().forEach(item -> this.wear(entity, item)); + return true; } private void wear(LivingEntity entity, SuitItem item) { entity.equipStack(item.getSlotType(), new ItemStack(item));