Custom TNT without NMS

Discussion in 'Spigot Plugin Development' started by WAS, Apr 17, 2017.

  1. WAS

    WAS

    Is this even really possible? I've been looking at old open sourced projects and about everything I can about TNT and it seems there is no real practical methods for detecting when and how TNT is primed.

    It does pretty much mean rewriting most the methods huh?

    For example I tried detecting red-stone activation but not sure how to detect actual powered blocks when it's not returning the power until after activation.
     
  2. ExplosionPrimeEvent..? Interact event for checks..?
     
  3. WAS

    WAS

    Is fired right before an entity decides to explode. Not primed. Covered in like every topic. Interact event is easy enough, unfortunately there is far more than just that for natural ignition in MC.

    The amount of failed plugin attempts on Github and shit I've been looking at is pretty astounding how many people attempting and failed. Only ones I see working and were released used NMS and none of the mentioned methods about interaction etc from the API but direct calls.

    I've implemented a debug command a monitor and am noticing a obvious different in locations. But I've the differences don't seem to correlate to the formula from Minecraft.

    Code (Text):
    TNT Type: DEFAULT Placed By: 7b4654af-9df2-335e-a76a-d7ddc86371c4 Location: -845, 4.0, 1608.0
    [14:32:42 INFO]: ExplosionPrimeEvent: Location{world=CraftWorld{name=world},x=-844.6341545220714,y=4.0,z=1608.3470798022518,pitch=0.0,yaw=0.0}
    [14:32:42 INFO]: EntityExplodeEvent: Location{world=CraftWorld{name=world},x=-844.6341545220714,y=4.0,z=1608.3470798022518,pitch=0.0,yaw=0.0}
    For one, the coordinates from a TNTPrimed have tons of floating point to it. Trying to math...
     
    #3 WAS, Apr 17, 2017
    Last edited: Apr 17, 2017
  4. Perhaps you could use a playerinteractevent instead and check if the block right clicked is tnt. NMS might be simpler, but it is less portable.
     
  5. WAS

    WAS

    Well that's the problem. This isn't about just players interacting with TNT. This is about Custom TNT. There for it must implement itself with all current means of ignition. PlayerInteractEvent is not a problem, or the problem. It's tracking redstone ignition through wires, repeaters, powered blocks, etc, and ignition by falling entity, ignition by whatever. Lol

    I also fear NMS is not easier unless you have a full grasp of it imo. An API would always be better. Just Bukkit is lacking in these instances. For fear of lagging, but I'm sure there is better ways to be able to track it.

    Which is why I want to counter all this with location checking.
    1. User places TNT. It's location and TNT Type is logged
    2. TNT is ignited somehwere, somehow. Use Prime event to determine if a TNTPrimed is in the relative location of the placed TNT (which can be removed by the player as to not interfere with block removal by players)
    3. Set the TNTPrime entity with a metadata "tntType" which contains the type of explosion to render.
    4. When Explode event is fired, if metadata exists read that metadata for the type, and determine the explosion to render
    Currently I have made "relative" method, since the TNTPrimed entity moves from the original placed location. But it isn't seeming to help yet.

    Code (Java):

      public boolean containsRelativeLocation(Location location) {
         for ( Map.Entry<UUID, Map<Location, String>> entry : placedTNT.entrySet() ) {
           for ( Entry<Location, String> locEntry : entry.getValue().entrySet() ) {
             if ( OnCommand.toggleDebug != null && OnCommand.toggleDebug ) {
               System.out.println("Distance Compared: "+Double.compare(location.distanceSquared(locEntry.getKey()), 1.0));
             }
             if ( Double.compare(location.distanceSquared(locEntry.getKey()), 1.0) < 0 ) {
               return true;
             }
           }
         }
         return false;
       }
    Which will produce
    Code (Text):

    [15:44:20 INFO]: TNT Type: DEFAULT Placed By: 7b4654af-9df2-335e-a76a-d7ddc86371c4 Location: -876, 4.0, 1591.0
    [15:44:25 INFO]: Distance Compared: -1
    [15:44:25 INFO]: ExplosionPrimeEvent: Location{world=CraftWorld{name=world},x=-879.345391540608,y=4.0,z=1592.6322053241001,pitch=0.0,yaw=0.0}
    [15:44:25 INFO]: EntityExplodeEvent: Location{world=CraftWorld{name=world},x=-879.345391540608,y=4.0,z=1592.6322053241001,pitch=0.0,yaw=0.0}
    Probably doing the comparison wrong. Oop. Nevermind. I forgot there was a second check for getType which neeeded to be a relative method as well. :p So I got that working. In fact even get back
    Code (Text):
    [15:56:00 INFO]: EntityExplodeEvent MetaData: [email protected] | DEFAULT
    . Just no render. More debugging. :p
     
    #5 WAS, Apr 17, 2017
    Last edited: Apr 17, 2017
  6. The offset is provided by a fraction in an equation, I remeber making a patchy for someone which removed this. If you want I can dive into a bit of nms to see how to detect when a TNT gets primed?
     
    • Friendly Friendly x 1
  7. WAS

    WAS

    Yeah I just worked around it by adding a bunch of Relative methods making sure the entity is within 1 block (inside the block) of a tracked TNT location.

    If you could that would be amazing. I keep looking but I get really confused and frustrated. I think it's because of the naming methods and all the math. I have dyscalculia which has been a incredibly set-back and inhibitor in life in general. :\

    So far I have gotten my TNT to to register and provide it's effect IF it is a (what I will call) simple primed tnt. Which is a primed TNT < boundaries of placed special TNT (I hope. So far works).

    Still gotta work out all the other types... like falling tnt for cannons or set off by other TNT
     
    #7 WAS, Apr 18, 2017
    Last edited: Apr 18, 2017