Core logic for a Counter Detector with a cannon whitelist, TNT threat vector detection, explosion box rendering, and a Cannoning config UI.
-
Install
- Put
counterdetector-1.0.0.jarfrombuild/libs/into your Minecraft mods folder (1.8.9 Forge).
- Put
-
Cannon whitelist
- In-game, stand at one corner of your cannon area and run
/cannon pos1. - Stand at the opposite corner and run
/cannon pos2. - TNT (and other entities) inside this box are treated as “your” cannon and ignored by the threat logic.
- In-game, stand at one corner of your cannon area and run
-
Config screen
- Press C (or your keybind) to open the Cannoning config.
- Explosion Boxes – toggle cyan boxes at enemy explosion positions (visible through walls); size from Box Size slider.
- Counter Detector – toggle threat-direction logic; when active the card has a green border.
- Box Size – slider linked to
renderBoxin real time.
-
In play
- TNT inside the whitelist: ignored.
- Enemy TNT (outside): direction West/East (by tnt.posX vs player.posX) or North/South; cyan explosion boxes (S2APacketExplosion precision when available).
-
Detection range (server limit)
- The mod can only “see” TNT that the server has sent to your client. In vanilla this is the entity tracking range: about 48 blocks horizontal (X/Z) and about 96–100 blocks vertical (Y). Beyond that, TNT is not in
loadedEntityList, so we cannot detect it. This cannot be fixed by the mod alone. To detect from further: - Sound packets do not extend range: vanilla only sends TNT-primed sound within 16 blocks, and explosion within 64 (volume-based).
- To detect from further: Singleplayer – increase simulation/view distance. Multiplayer – ask the server owner to increase entity tracking range, if supported.
- The mod can only “see” TNT that the server has sent to your client. In vanilla this is the entity tracking range: about 48 blocks horizontal (X/Z) and about 96–100 blocks vertical (Y). Beyond that, TNT is not in
-
Coordinate Whitelist (
/cannon– client command only)- Registered with
ClientCommandHandler; never sent to the server. myCannonMinandmyCannonMaxstore the box;/cannon pos1and/cannon pos2set them at your feet.isEnemyTNT(EntityTNTPrimed)returns true if the TNT is outside the box (enemy);isInsideCannon(Entity)for the box test.
- Registered with
-
Threat vector (TNT)
- In client tick, TNT outside the whitelist is classified by motion:
- West/East:
|motionX| >= |motionZ|, then West iftnt.posX < player.posX, else East. - North/South:
|motionZ| > |motionX|, then North iftnt.posZ < player.posZ, else South.
-
Explosion box rendering
ExplosionBoxRenderer.renderBox(double x, double y, double z, float size)draws a box at the given position.- Uses
GlStateManager.disableDepth()so the box is visible through walls. - Explosion positions are recorded from TNT fuse (fallback) or from the explosion packet (see below).
-
Exact blast coordinates (S27PacketExplosion)
- For precise positions, hook the explosion packet (e.g. with Mixin) and call:
ExplosionPacketCapture.onExplosionPacket(x, y, z) - In 1.8.9 the packet is
S27PacketExplosion; read the double x, y, z (or a, b, c in obf).
- For precise positions, hook the explosion packet (e.g. with Mixin) and call:
-
Cannoning UI
- Press C (configurable) to open the Cannoning config.
- Explosion Boxes and Counter Detector are toggles (square cards).
- Box Size slider updates the size passed to
renderBox(...).
- Setup:
gradlew setupDecompWorkspace - Run client:
gradlew runClient - Build JAR:
gradlew build(output inbuild/libs/)
The in-mod Cannoning screen is standalone. To integrate with OneConfig’s Cannoning category and use Explosion Boxes / Counter Detector as icon-cards with a Box Size slider, add the OneConfig dependency and register a config that:
- Uses the Cannoning category (or equivalent).
- Exposes Explosion Boxes and Counter Detector as cards/pages.
- Exposes a float slider that calls
CounterDetectorConfig.setBoxSize(value).