11package me .dustin .chatbot .entity ;
22
33import me .dustin .chatbot .ChatBot ;
4+ import me .dustin .chatbot .helper .GeneralHelper ;
5+ import me .dustin .chatbot .network .packet .ProtocolHandler ;
46import me .dustin .chatbot .process .ChatBotProcess ;
57
8+ import java .util .ArrayList ;
9+ import java .util .HashMap ;
10+ import java .util .Map ;
11+
612public class LivingEntity {
713 protected final int entityId ;
14+ protected final String type ;
815 protected double x , y , z ;
916 protected float yaw , pitch ;
1017
11- public LivingEntity (int entityId , double x , double y , double z , float yaw , float pitch ) {
18+ private static final ArrayList <String > nonLivingEntities = new ArrayList <>();
19+ private static final Map <Integer , String > entityIds = new HashMap <>();
20+
21+ public LivingEntity (int entityId , String type , double x , double y , double z , float yaw , float pitch ) {
1222 this .entityId = entityId ;
23+ this .type = type ;
1324 this .x = x ;
1425 this .y = y ;
1526 this .z = z ;
@@ -21,6 +32,10 @@ public int getEntityId() {
2132 return entityId ;
2233 }
2334
35+ public String getTypeName () {
36+ return type ;
37+ }
38+
2439 public double getX () {
2540 return x ;
2641 }
@@ -82,4 +97,72 @@ public String toString() {
8297 ", pitch=" + pitch +
8398 '}' ;
8499 }
100+
101+ public static String getTypeName (int id ) {
102+ if (!entityIds .containsKey (id ))
103+ return "unknown" ;
104+ return entityIds .get (id );
105+ }
106+
107+ public static boolean isLiving (String name ) {
108+ return !nonLivingEntities .contains (name );
109+ }
110+
111+ static {
112+ String v = ProtocolHandler .getCurrent ().getName ().replace ("." , "_" );
113+ if (v .contains ("pre" ) || v .contains ("w" ))
114+ v = "1_19" ;
115+ //fat fuckin mess to create the version id needed for the link, i.e. 1_12 from 1.12.2
116+ if (v .split ("_" ).length > 2 )
117+ v = v .split ("_" )[0 ] + "_" + v .split ("_" )[1 ];
118+ String url = "https://raw.githubusercontent.com/DustinRepo/ChatBot/master/entityIds/" + v + "_entity_ids.txt" ;
119+ GeneralHelper .HttpResponse httpResponse = GeneralHelper .httpRequest (url , null , null , "GET" );
120+ if (httpResponse .responseCode () != 404 ) {
121+ String [] ids = httpResponse .data ().split ("\n " );
122+ for (String s : ids ) {
123+ int id = Integer .parseInt (s .split ("=" )[0 ]);
124+ String name = s .split ("=" )[1 ];
125+ entityIds .put (id , name );
126+ }
127+ }
128+ nonLivingEntities .add ("entity.minecraft.area_effect_cloud" );
129+ nonLivingEntities .add ("entity.minecraft.armor_stand" );
130+ nonLivingEntities .add ("entity.minecraft.arrow" );
131+ nonLivingEntities .add ("entity.minecraft.boat" );
132+ nonLivingEntities .add ("entity.minecraft.chest_boat" );
133+ nonLivingEntities .add ("entity.minecraft.dragon_fireball" );
134+ nonLivingEntities .add ("entity.minecraft.end_crystal" );
135+ nonLivingEntities .add ("entity.minecraft.evoker_fangs" );
136+ nonLivingEntities .add ("entity.minecraft.experience_orb" );
137+ nonLivingEntities .add ("entity.minecraft.eye_of_ender" );
138+ nonLivingEntities .add ("entity.minecraft.falling_block" );
139+ nonLivingEntities .add ("entity.minecraft.firework_rocket" );
140+ nonLivingEntities .add ("entity.minecraft.glow_item_frame" );
141+ nonLivingEntities .add ("entity.minecraft.item" );
142+ nonLivingEntities .add ("entity.minecraft.item_frame" );
143+ nonLivingEntities .add ("entity.minecraft.fireball" );
144+ nonLivingEntities .add ("entity.minecraft.leash_knot" );
145+ nonLivingEntities .add ("entity.minecraft.lightning_bolt" );
146+ nonLivingEntities .add ("entity.minecraft.llama_spit" );
147+ nonLivingEntities .add ("entity.minecraft.marker" );
148+ nonLivingEntities .add ("entity.minecraft.minecart" );
149+ nonLivingEntities .add ("entity.minecraft.chest_minecart" );
150+ nonLivingEntities .add ("entity.minecraft.command_block_minecart" );
151+ nonLivingEntities .add ("entity.minecraft.furnace_minecart" );
152+ nonLivingEntities .add ("entity.minecraft.hopper_minecart" );
153+ nonLivingEntities .add ("entity.minecraft.spawner_minecart" );
154+ nonLivingEntities .add ("entity.minecraft.tnt_minecart" );
155+ nonLivingEntities .add ("entity.minecraft.painting" );
156+ nonLivingEntities .add ("entity.minecraft.tnt" );
157+ nonLivingEntities .add ("entity.minecraft.shulker_bullet" );
158+ nonLivingEntities .add ("entity.minecraft.small_fireball" );
159+ nonLivingEntities .add ("entity.minecraft.spectral_arrow" );
160+ nonLivingEntities .add ("entity.minecraft.egg" );
161+ nonLivingEntities .add ("entity.minecraft.ender_pearl" );
162+ nonLivingEntities .add ("entity.minecraft.experience_bottle" );
163+ nonLivingEntities .add ("entity.minecraft.potion" );
164+ nonLivingEntities .add ("entity.minecraft.trident" );
165+ nonLivingEntities .add ("entity.minecraft.wither_skull" );
166+ nonLivingEntities .add ("entity.minecraft.fishing_bobber" );
167+ }
85168}
0 commit comments