From fde70150c86e9ebb312c54a2d48419c2fd2cc1e0 Mon Sep 17 00:00:00 2001 From: jvyden Date: Wed, 24 Jun 2020 11:03:58 -0400 Subject: [PATCH 1/3] Add TotemNotifierModule --- .../impl/management/ModuleManager.java | 3 +- .../module/combat/TotemNotifierModule.java | 61 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/main/java/me/rigamortis/seppuku/impl/module/combat/TotemNotifierModule.java diff --git a/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java b/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java index 68a9953..db57eeb 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java +++ b/src/main/java/me/rigamortis/seppuku/impl/management/ModuleManager.java @@ -146,8 +146,9 @@ public final class ModuleManager { add(new VisualRangeModule()); add(new HotBarRefillModule()); add(new QuickCraftModule()); + add(new TotemNotifierModule()); - //p2w experience + // p2w experience if (Seppuku.INSTANCE.getCapeManager().hasCape()) add(new CapeModule()); diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/combat/TotemNotifierModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/combat/TotemNotifierModule.java new file mode 100644 index 0000000..f3005cb --- /dev/null +++ b/src/main/java/me/rigamortis/seppuku/impl/module/combat/TotemNotifierModule.java @@ -0,0 +1,61 @@ +package me.rigamortis.seppuku.impl.module.combat; + +import me.rigamortis.seppuku.Seppuku; +import me.rigamortis.seppuku.api.event.EventStageable; +import me.rigamortis.seppuku.api.event.minecraft.EventRunTick; +import me.rigamortis.seppuku.api.event.world.EventRemoveEntity; +import me.rigamortis.seppuku.api.module.Module; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLivingBase; +import net.minecraft.init.Items; +import net.minecraft.inventory.EntityEquipmentSlot; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import team.stiff.pomelo.impl.annotated.handler.annotation.Listener; + +import java.util.*; + + +/** + * @author jvyden + * @date 6/24/20 + */ +public class TotemNotifierModule extends Module { + final Minecraft mc = Minecraft.getMinecraft(); + + public TotemNotifierModule() { + super("TotemNotifier", new String[]{"tm"}, "Notifies you when others pop totems.", "NONE", -1, ModuleType.COMBAT); + } + + public List EntitiesWithTotems = new ArrayList<>(); + + @Listener + public void runTick(EventRunTick event) { + if (event.getStage() == EventStageable.EventStage.PRE) { + for(Entity entity : mc.world.loadedEntityList) { + if (entity instanceof EntityLivingBase) { + final Iterable stacks = entity.getEquipmentAndArmor(); + for(ItemStack stack : stacks) { + final Item offhandItem = ((EntityLivingBase) entity).getItemStackFromSlot(EntityEquipmentSlot.OFFHAND).getItem(); + if(offhandItem == Items.TOTEM_OF_UNDYING) { + if(!EntitiesWithTotems.contains(entity.getEntityId())) { + EntitiesWithTotems.add(entity.getEntityId()); + } + } else if(offhandItem == Items.AIR) { + if(EntitiesWithTotems.contains(entity.getEntityId())) { + Seppuku.INSTANCE.getNotificationManager().addNotification("", entity.getName() + " just popped a totem."); + EntitiesWithTotems.removeIf(i -> i.equals(entity.getEntityId())); + } + } + } + } + } + } + } + public void onEntityRemove(EventRemoveEntity event) { + if(EntitiesWithTotems.contains(event.getEntity().getEntityId())) { + EntitiesWithTotems.removeIf(i -> i.equals(event.getEntity().getEntityId())); + } + } +} From 80117b262291cc48b282452df4caa54932a7c205 Mon Sep 17 00:00:00 2001 From: jvyden Date: Wed, 24 Jun 2020 11:10:28 -0400 Subject: [PATCH 2/3] clean imports --- .../seppuku/impl/module/combat/TotemNotifierModule.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/combat/TotemNotifierModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/combat/TotemNotifierModule.java index f3005cb..ae9a741 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/combat/TotemNotifierModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/combat/TotemNotifierModule.java @@ -13,13 +13,13 @@ import net.minecraft.inventory.EntityEquipmentSlot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import team.stiff.pomelo.impl.annotated.handler.annotation.Listener; - -import java.util.*; +import java.util.ArrayList; +import java.util.List; /** * @author jvyden - * @date 6/24/20 + * @since 6/24/20 */ public class TotemNotifierModule extends Module { final Minecraft mc = Minecraft.getMinecraft(); From 6208a8e29140731a72952bcf1eb3ad607950ec33 Mon Sep 17 00:00:00 2001 From: jvyden Date: Thu, 25 Jun 2020 23:15:53 -0400 Subject: [PATCH 3/3] Rename entitiesWithTotems, add listener --- .../impl/module/combat/TotemNotifierModule.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/rigamortis/seppuku/impl/module/combat/TotemNotifierModule.java b/src/main/java/me/rigamortis/seppuku/impl/module/combat/TotemNotifierModule.java index ae9a741..9837212 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/module/combat/TotemNotifierModule.java +++ b/src/main/java/me/rigamortis/seppuku/impl/module/combat/TotemNotifierModule.java @@ -28,7 +28,7 @@ public class TotemNotifierModule extends Module { super("TotemNotifier", new String[]{"tm"}, "Notifies you when others pop totems.", "NONE", -1, ModuleType.COMBAT); } - public List EntitiesWithTotems = new ArrayList<>(); + public final List entitiesWithTotems = new ArrayList<>(); @Listener public void runTick(EventRunTick event) { @@ -39,13 +39,13 @@ public class TotemNotifierModule extends Module { for(ItemStack stack : stacks) { final Item offhandItem = ((EntityLivingBase) entity).getItemStackFromSlot(EntityEquipmentSlot.OFFHAND).getItem(); if(offhandItem == Items.TOTEM_OF_UNDYING) { - if(!EntitiesWithTotems.contains(entity.getEntityId())) { - EntitiesWithTotems.add(entity.getEntityId()); + if(!entitiesWithTotems.contains(entity.getEntityId())) { + entitiesWithTotems.add(entity.getEntityId()); } } else if(offhandItem == Items.AIR) { - if(EntitiesWithTotems.contains(entity.getEntityId())) { + if(entitiesWithTotems.contains(entity.getEntityId())) { Seppuku.INSTANCE.getNotificationManager().addNotification("", entity.getName() + " just popped a totem."); - EntitiesWithTotems.removeIf(i -> i.equals(entity.getEntityId())); + entitiesWithTotems.removeIf(i -> i.equals(entity.getEntityId())); } } } @@ -53,9 +53,10 @@ public class TotemNotifierModule extends Module { } } } + @Listener public void onEntityRemove(EventRemoveEntity event) { - if(EntitiesWithTotems.contains(event.getEntity().getEntityId())) { - EntitiesWithTotems.removeIf(i -> i.equals(event.getEntity().getEntityId())); + if(entitiesWithTotems.contains(event.getEntity().getEntityId())) { + entitiesWithTotems.removeIf(i -> i.equals(event.getEntity().getEntityId())); } } }