Rewrite TotemNotifier
This commit is contained in:
parent
d54b6cb04d
commit
4fa50ffa41
|
@ -3,6 +3,7 @@ package me.rigamortis.seppuku.impl.module.combat;
|
||||||
import me.rigamortis.seppuku.Seppuku;
|
import me.rigamortis.seppuku.Seppuku;
|
||||||
import me.rigamortis.seppuku.api.event.EventStageable;
|
import me.rigamortis.seppuku.api.event.EventStageable;
|
||||||
import me.rigamortis.seppuku.api.event.minecraft.EventRunTick;
|
import me.rigamortis.seppuku.api.event.minecraft.EventRunTick;
|
||||||
|
import me.rigamortis.seppuku.api.event.network.EventReceivePacket;
|
||||||
import me.rigamortis.seppuku.api.event.world.EventRemoveEntity;
|
import me.rigamortis.seppuku.api.event.world.EventRemoveEntity;
|
||||||
import me.rigamortis.seppuku.api.module.Module;
|
import me.rigamortis.seppuku.api.module.Module;
|
||||||
import me.rigamortis.seppuku.api.notification.Notification;
|
import me.rigamortis.seppuku.api.notification.Notification;
|
||||||
|
@ -13,6 +14,7 @@ import net.minecraft.init.Items;
|
||||||
import net.minecraft.inventory.EntityEquipmentSlot;
|
import net.minecraft.inventory.EntityEquipmentSlot;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.network.play.server.SPacketEntityStatus;
|
||||||
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
|
import team.stiff.pomelo.impl.annotated.handler.annotation.Listener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -20,46 +22,29 @@ import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author jvyden
|
* @author noil
|
||||||
* @since 6/24/20
|
* @since 12/4/22
|
||||||
*/
|
*/
|
||||||
public class TotemNotifierModule extends Module {
|
public class TotemNotifierModule extends Module {
|
||||||
public final List<Integer> entitiesWithTotems = new ArrayList<>();
|
|
||||||
final Minecraft mc = Minecraft.getMinecraft();
|
final Minecraft mc = Minecraft.getMinecraft();
|
||||||
|
|
||||||
public TotemNotifierModule() {
|
public TotemNotifierModule() {
|
||||||
super("TotemNotifier", new String[]{"tm"}, "Notifies you when others pop totems", "NONE", -1, ModuleType.COMBAT);
|
super("TotemNotifier", new String[]{"tm"}, "Notifies you when others pop totems", "NONE", -1, ModuleType.COMBAT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
entityplayermp.addStat(StatList.getObjectUseStats(Items.TOTEM_OF_UNDYING));
|
||||||
|
CriteriaTriggers.USED_TOTEM.trigger(entityplayermp, itemstack);
|
||||||
|
*/
|
||||||
|
|
||||||
@Listener
|
@Listener
|
||||||
public void runTick(EventRunTick event) {
|
public void receivePacket(EventReceivePacket event) {
|
||||||
if (event.getStage() == EventStageable.EventStage.PRE) {
|
if (event.getStage().equals(EventStageable.EventStage.PRE) && event.getPacket() instanceof SPacketEntityStatus && mc.world != null) {
|
||||||
if (mc.world == null) return;
|
final SPacketEntityStatus packetEntityStatus = (SPacketEntityStatus) event.getPacket();
|
||||||
for (Entity entity : mc.world.loadedEntityList) {
|
if (packetEntityStatus.getOpCode() == 35) { // totem pop status
|
||||||
if (entity instanceof EntityLivingBase) {
|
Seppuku.INSTANCE.getNotificationManager().addNotification("", packetEntityStatus.getEntity(mc.world).getName() + " just popped a totem.", Notification.Type.INFO, 2000);
|
||||||
final Iterable<ItemStack> 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.", Notification.Type.INFO, 2000);
|
|
||||||
entitiesWithTotems.removeIf(i -> i.equals(entity.getEntityId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Listener
|
|
||||||
public void onEntityRemove(EventRemoveEntity event) {
|
|
||||||
if (entitiesWithTotems.contains(event.getEntity().getEntityId())) {
|
|
||||||
entitiesWithTotems.removeIf(i -> i.equals(event.getEntity().getEntityId()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue