TrapEffects.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package me.km.effects.passive;
  2. import java.util.HashMap;
  3. import me.km.KajetansMod;
  4. import me.km.api.Location;
  5. import me.km.api.Module;
  6. import me.km.api.ModuleListener;
  7. import me.km.api.Utils;
  8. import me.km.effects.EffectBlockChanger;
  9. import me.km.effects.EffectUtils;
  10. import me.km.events.PlayerMoveEvent;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.init.Blocks;
  13. import net.minecraft.init.MobEffects;
  14. import net.minecraft.util.DamageSource;
  15. import net.minecraft.util.math.BlockPos;
  16. import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
  17. public class TrapEffects extends ModuleListener
  18. {
  19. private final HashMap<Location, Integer> netTraps;
  20. private final HashMap<Location, Integer> vineTraps;
  21. private final HashMap<Location, Integer> nailTraps;
  22. public TrapEffects(Module m)
  23. {
  24. super(m);
  25. netTraps = new HashMap<>();
  26. vineTraps = new HashMap<>();
  27. nailTraps = new HashMap<>();
  28. }
  29. public void addNailTraps(Location l, int id)
  30. {
  31. l = l.copy();
  32. l.round();
  33. for(int x = -1; x <= 1; x++)
  34. {
  35. for(int y = -1; y <= 1; y++)
  36. {
  37. nailTraps.put(l.copyAdd(x, 0, y), id);
  38. }
  39. }
  40. }
  41. public void addNetTrap(Location l, int id)
  42. {
  43. l = l.copy();
  44. l.round();
  45. netTraps.put(l, id);
  46. }
  47. public void addVineTrap(Location l, int id)
  48. {
  49. l = l.copy();
  50. l.round();
  51. vineTraps.put(l, id);
  52. }
  53. public void removeVineTrap(Location l)
  54. {
  55. l = l.copy();
  56. l.round();
  57. vineTraps.remove(l);
  58. }
  59. @SubscribeEvent
  60. public void executeTrap(PlayerMoveEvent e)
  61. {
  62. EntityPlayer p = e.getEntityPlayer();
  63. Location l = new Location(p);
  64. l.round();
  65. if(netTraps.containsKey(l))
  66. {
  67. Integer i = netTraps.get(l);
  68. if(!(i < 0 && i == -KajetansMod.playerbank.getDataBank().getIdByUUID(p.getUniqueID().toString())) &&
  69. i != KajetansMod.playerbank.getGuildId(p))
  70. {
  71. netTraps.remove(l);
  72. BlockPos b = l.getBlockPos();
  73. EffectBlockChanger changer = new EffectBlockChanger(l.getWorld());
  74. for(int x = -3; x <= 3; x++)
  75. {
  76. for(int y = 0; y <= 3; y++)
  77. {
  78. for(int z = -3; z <= 3; z++)
  79. {
  80. if((Math.abs(x) == 3 ? 1 : 0) + (Math.abs(y) == 3 ? 1 : 0) + (Math.abs(z) == 3 ? 1 : 0) >= 2)
  81. {
  82. continue;
  83. }
  84. if(Utils.randomInt(1, 10) >= 3)
  85. {
  86. changer.addBlock(b.add(x, y, z), Blocks.WEB);
  87. }
  88. }
  89. }
  90. }
  91. changer.run(120);
  92. }
  93. }
  94. if(vineTraps.containsKey(l))
  95. {
  96. Integer i = vineTraps.get(l);
  97. if(!(i < 0 && i == -KajetansMod.playerbank.getDataBank().getIdByUUID(p.getUniqueID().toString())) &&
  98. i != KajetansMod.playerbank.getGuildId(p))
  99. {
  100. EffectUtils.addPotionTo(p, MobEffects.POISON, 60, 2);
  101. }
  102. }
  103. if(nailTraps.containsKey(l))
  104. {
  105. Integer i = nailTraps.get(l);
  106. if(!(i < 0 && i == -KajetansMod.playerbank.getDataBank().getIdByUUID(p.getUniqueID().toString())) &&
  107. i != KajetansMod.playerbank.getGuildId(p))
  108. {
  109. nailTraps.remove(l);
  110. p.attackEntityFrom(DamageSource.GENERIC, 6);
  111. EffectUtils.addPotionTo(p, MobEffects.SLOWNESS, 200, 1);
  112. }
  113. }
  114. }
  115. }