Posted June 9, 20232 yr Hello, So far I was able to add an armor item, but I cant find a way to check if the player is crouched while wearing the "chestplate" and if they are crouched, apply an effect while crouching. Would it cause lag if it were to check every tick? Is there a better way around this? Is it not possible? Here is my code: public static final RegistryObject<ArmorItem> CLOAK_OF_SHADOWS = ITEMS.register("cloak_of_shadows", () -> new ArmorItem(ArmorMaterials.LEATHER, ArmorItem.Type.CHESTPLATE, new Item.Properties() { public void onArmorTick(Player player, ItemStack stack) { if (player.getItemBySlot(EquipmentSlot.CHEST) == stack) { if (player.isCrouching()) { // Check if player is crouching player.addEffect(new MobEffectInstance(MobEffects.INVISIBILITY, 20, 0, true, false)); player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 20, 1, true, false)); } } } })); Not even gonna lie, I think I have autism
June 9, 20232 yr 9 hours ago, Naamah said: Would it cause lag if it were to check every tick? Not really. There's not enough logic for that to matter. 9 hours ago, Naamah said: if (player.getItemBySlot(EquipmentSlot.CHEST) == stack) { You should check by item (#getItem). Stacks are almost never equal.
June 10, 20232 yr 13 hours ago, ChampionAsh5357 said: You should check by item (#getItem). Stacks are almost never equal. I'd recommend using (stack.getEquipmentSlot() == EquipmentSlot.CHEST) instead. All you need to do is check if it's the correct slot, not if the stacks are equal. Also it isn't necessary to do this every tick. Although the logic of the IF statement is pretty simple, Minecraft does a lot of stuff when adding potion effects (mainly syncing the player data). Every 5 ticks or so would be good enough, which you can do by checking if (player.tickCount % 5 == 0). Edited June 10, 20232 yr by Mikul
June 12, 20232 yr Author On 6/9/2023 at 8:48 AM, ChampionAsh5357 said: Not really. There's not enough logic for that to matter. You should check by item (#getItem). Stacks are almost never equal. I am now using the following code. Maybe I'm slow or something, but the effect still doesn't work, I even tried it with Mikul's solution. public void onArmorTick(Player player, ItemStack stack) { if (player.getItemBySlot(EquipmentSlot.CHEST).getItem() == stack.getItem() && player.isCrouching()) { player.addEffect(new MobEffectInstance(MobEffects.INVISIBILITY, 20, 0, true, false)); player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, 20, 1, true, false)); } } Not even gonna lie, I think I have autism
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.