TrapEffects.java 3.9 KB

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