8181import static org .samo_lego .taterzens .common .util .TextUtil .errorText ;
8282import static org .samo_lego .taterzens .common .util .TextUtil .successText ;
8383
84+ import static org .apache .logging .log4j .LogManager .getLogger ;
85+
8486/**
8587 * The NPC itself.
8688 */
@@ -152,7 +154,8 @@ public TaterzenNPC(Level world) {
152154 * {@link TaterzensAPI#createTaterzen(ServerPlayer, String)}
153155 * instead, as this one doesn't set the position and custom name.
154156 *
155- * @param entityType Taterzen entity type
157+ * @param npcData.entityList.put
158+ Taterzen entity type
156159 * @param world Taterzen's world
157160 */
158161 public TaterzenNPC (EntityType <? extends PathfinderMob > entityType , Level world ) {
@@ -182,7 +185,160 @@ public TaterzenNPC(EntityType<? extends PathfinderMob> entityType, Level world)
182185 this .npcData .deathSounds = new ArrayList <>(config .defaults .deathSounds );
183186 }
184187
188+ // This is where the magic happens for changing entity type...
189+ CompoundTag npcTag = new CompoundTag ();
190+ if (npcTag .contains ("Entity" )) {
191+ // Update it to the current settting
192+ getLogger ("Taterzens" ).info ("[Taterzens]: We have a valid Entity setting and are putting it in the Tag - Map - {}, - Tag -" , npcData .playerEntity .get ("Entity" ), npcTag .getString ("Entity" ));
193+ //
194+ npcTag .putString ("Entity" , npcData .playerEntity .get ("Entity" ));
195+ // It's actually this we need to update since we have it stored, and the playerEntity hashmap is what we're using
196+ npcData .playerEntity .put ("Entity" , npcTag .getString ("Entity" ));
197+ } else { // Initial NPC creation we go to PLAYER
198+ getLogger ("Taterzens" ).info ("[Taterzens]: No valid Entity set, so it's PLAYER time." );
199+
200+ npcTag .putString ("Entity" , "PLAYER" );
201+ npcData .playerEntity .put ("Entity" , "PLAYER" );
202+ }
203+
204+ // We only want to do this ONCE, and it gets fussy if placed anywhere else.
205+ // So, we check to see if the list is empty and then fill it if it is
206+ if (this .npcData .entityList .isEmpty ()) {
207+
208+ npcData .entityList .put ("ALLAY" , EntityType .ALLAY );
209+ npcData .entityList .put ("AREA_EFFECT_CLOUD" , EntityType .AREA_EFFECT_CLOUD );
210+ npcData .entityList .put ("ARMOR_STAND" , EntityType .ARMOR_STAND );
211+ npcData .entityList .put ("ARROW" , EntityType .ARROW );
212+ npcData .entityList .put ("AXOLOTL" , EntityType .AXOLOTL );
213+ npcData .entityList .put ("BAT" , EntityType .BAT );
214+ npcData .entityList .put ("BEE" , EntityType .BEE );
215+ npcData .entityList .put ("BLAZE" , EntityType .BLAZE );
216+ npcData .entityList .put ("BLOCK_DISPLAY" , EntityType .BLOCK_DISPLAY );
217+ npcData .entityList .put ("BOAT" , EntityType .BOAT );
218+ npcData .entityList .put ("BREEZE" , EntityType .BREEZE );
219+ npcData .entityList .put ("CAMEL" , EntityType .CAMEL );
220+ npcData .entityList .put ("CAT" , EntityType .CAT );
221+ npcData .entityList .put ("CAVE_SPIDER" , EntityType .CAVE_SPIDER );
222+ npcData .entityList .put ("CHEST_BOAT" , EntityType .CHEST_BOAT );
223+ npcData .entityList .put ("CHEST_MINECART" , EntityType .CHEST_MINECART );
224+ npcData .entityList .put ("CHICKEN" , EntityType .CHICKEN );
225+ npcData .entityList .put ("COD" , EntityType .COD );
226+ npcData .entityList .put ("COMMAND_BLOCK_MINECART" , EntityType .COMMAND_BLOCK_MINECART );
227+ npcData .entityList .put ("COW" , EntityType .COW );
228+ npcData .entityList .put ("CREEPER" , EntityType .CREEPER );
229+ npcData .entityList .put ("DOLPHIN" , EntityType .DOLPHIN );
230+ npcData .entityList .put ("DONKEY" , EntityType .DONKEY );
231+ npcData .entityList .put ("DRAGON_FIREBALL" , EntityType .DRAGON_FIREBALL );
232+ npcData .entityList .put ("DROWNED" , EntityType .DROWNED );
233+ npcData .entityList .put ("EGG" , EntityType .EGG );
234+ npcData .entityList .put ("ELDER_GUARDIAN" , EntityType .ELDER_GUARDIAN );
235+ npcData .entityList .put ("END_CRYSTAL" , EntityType .END_CRYSTAL );
236+ npcData .entityList .put ("ENDER_DRAGON" , EntityType .ENDER_DRAGON );
237+ npcData .entityList .put ("ENDER_PEARL" , EntityType .ENDER_PEARL );
238+ npcData .entityList .put ("ENDERMAN" , EntityType .ENDERMAN );
239+ npcData .entityList .put ("ENDERMITE" , EntityType .ENDERMITE );
240+ npcData .entityList .put ("EVOKER" , EntityType .EVOKER );
241+ npcData .entityList .put ("EVOKER_FANGS" , EntityType .EVOKER_FANGS );
242+ npcData .entityList .put ("EXPERIENCE_BOTTLE" , EntityType .EXPERIENCE_BOTTLE );
243+ npcData .entityList .put ("EXPERIENCE_ORB" , EntityType .EXPERIENCE_ORB );
244+ npcData .entityList .put ("EYE_OF_ENDER" , EntityType .EYE_OF_ENDER );
245+ npcData .entityList .put ("FALLING_BLOCK" , EntityType .FALLING_BLOCK );
246+ npcData .entityList .put ("FIREBALL" , EntityType .FIREBALL );
247+ npcData .entityList .put ("FIREWORK_ROCKET" , EntityType .FIREWORK_ROCKET );
248+ npcData .entityList .put ("FISHING_BOBBER" , EntityType .FISHING_BOBBER );
249+ npcData .entityList .put ("FOX" , EntityType .FOX );
250+ npcData .entityList .put ("FROG" , EntityType .FROG );
251+ npcData .entityList .put ("FURNACE_MINECART" , EntityType .FURNACE_MINECART );
252+ npcData .entityList .put ("GHAST" , EntityType .GHAST );
253+ npcData .entityList .put ("GIANT" , EntityType .GIANT );
254+ npcData .entityList .put ("GLOW_ITEM_FRAME" , EntityType .GLOW_ITEM_FRAME );
255+ npcData .entityList .put ("GLOW_SQUID" , EntityType .GLOW_SQUID );
256+ npcData .entityList .put ("GOAT" , EntityType .GOAT );
257+ npcData .entityList .put ("GUARDIAN" , EntityType .GUARDIAN );
258+ npcData .entityList .put ("HOGLIN" , EntityType .HOGLIN );
259+ npcData .entityList .put ("HOPPER_MINECART" , EntityType .HOPPER_MINECART );
260+ npcData .entityList .put ("HORSE" , EntityType .HORSE );
261+ npcData .entityList .put ("HUSK" , EntityType .HUSK );
262+ npcData .entityList .put ("ILLUSIONER" , EntityType .ILLUSIONER );
263+ npcData .entityList .put ("INTERACTION" , EntityType .INTERACTION );
264+ npcData .entityList .put ("IRON_GOLEM" , EntityType .IRON_GOLEM );
265+ npcData .entityList .put ("ITEM" , EntityType .ITEM );
266+ npcData .entityList .put ("ITEM_DISPLAY" , EntityType .ITEM_DISPLAY );
267+ npcData .entityList .put ("ITEM_FRAME" , EntityType .ITEM_FRAME );
268+ npcData .entityList .put ("LEASH_KNOT" , EntityType .LEASH_KNOT );
269+ npcData .entityList .put ("LIGHTNING_BOLT" , EntityType .LIGHTNING_BOLT );
270+ npcData .entityList .put ("LLAMA" , EntityType .LLAMA );
271+ npcData .entityList .put ("LLAMA_SPIT" , EntityType .LLAMA_SPIT );
272+ npcData .entityList .put ("MAGMA_CUBE" , EntityType .MAGMA_CUBE );
273+ npcData .entityList .put ("MARKER" , EntityType .MARKER );
274+ npcData .entityList .put ("MINECART" , EntityType .MINECART );
275+ npcData .entityList .put ("MOOSHROOM" , EntityType .MOOSHROOM );
276+ npcData .entityList .put ("MULE" , EntityType .MULE );
277+ npcData .entityList .put ("OCELOT" , EntityType .OCELOT );
278+ npcData .entityList .put ("PAINTING" , EntityType .PAINTING );
279+ npcData .entityList .put ("PANDA" , EntityType .PANDA );
280+ npcData .entityList .put ("PARROT" , EntityType .PARROT );
281+ npcData .entityList .put ("PHANTOM" , EntityType .PHANTOM );
282+ npcData .entityList .put ("PIG" , EntityType .PIG );
283+ npcData .entityList .put ("PIGLIN" , EntityType .PIGLIN );
284+ npcData .entityList .put ("PIGLIN_BRUTE" , EntityType .PIGLIN_BRUTE );
285+ npcData .entityList .put ("PILLAGER" , EntityType .PILLAGER );
286+ npcData .entityList .put ("PLAYER" , EntityType .PLAYER );
287+ npcData .entityList .put ("POLAR_BEAR" , EntityType .POLAR_BEAR );
288+ npcData .entityList .put ("POTION" , EntityType .POTION );
289+ npcData .entityList .put ("PUFFERFISH" , EntityType .PUFFERFISH );
290+ npcData .entityList .put ("RABBIT" , EntityType .RABBIT );
291+ npcData .entityList .put ("RAVAGER" , EntityType .RAVAGER );
292+ npcData .entityList .put ("SALMON" , EntityType .SALMON );
293+ npcData .entityList .put ("SHEEP" , EntityType .SHEEP );
294+ npcData .entityList .put ("SHULKER" , EntityType .SHULKER );
295+ npcData .entityList .put ("SHULKER_BULLET" , EntityType .SHULKER_BULLET );
296+ npcData .entityList .put ("SILVERFISH" , EntityType .SILVERFISH );
297+ npcData .entityList .put ("SKELETON" , EntityType .SKELETON );
298+ npcData .entityList .put ("SKELETON_HORSE" , EntityType .SKELETON_HORSE );
299+ npcData .entityList .put ("SLIME" , EntityType .SLIME );
300+ npcData .entityList .put ("SMALL_FIREBALL" , EntityType .SMALL_FIREBALL );
301+ npcData .entityList .put ("SNIFFER" , EntityType .SNIFFER );
302+ npcData .entityList .put ("SNOW_GOLEM" , EntityType .SNOW_GOLEM );
303+ npcData .entityList .put ("SNOWBALL" , EntityType .SNOWBALL );
304+ npcData .entityList .put ("SPAWNER_MINECART" , EntityType .SPAWNER_MINECART );
305+ npcData .entityList .put ("SPECTRAL_ARROW" , EntityType .SPECTRAL_ARROW );
306+ npcData .entityList .put ("SPIDER" , EntityType .SPIDER );
307+ npcData .entityList .put ("SQUID" , EntityType .SQUID );
308+ npcData .entityList .put ("STRAY" , EntityType .STRAY );
309+ npcData .entityList .put ("STRIDER" , EntityType .STRIDER );
310+ npcData .entityList .put ("TADPOLE" , EntityType .TADPOLE );
311+ npcData .entityList .put ("TEXT_DISPLAY" , EntityType .TEXT_DISPLAY );
312+ npcData .entityList .put ("TNT" , EntityType .TNT );
313+ npcData .entityList .put ("TNT_MINECART" , EntityType .TNT_MINECART );
314+ npcData .entityList .put ("TRADER_LLAMA" , EntityType .TRADER_LLAMA );
315+ npcData .entityList .put ("TRIDENT" , EntityType .TRIDENT );
316+ npcData .entityList .put ("TROPICAL_FISH" , EntityType .TROPICAL_FISH );
317+ npcData .entityList .put ("TURTLE" , EntityType .TURTLE );
318+ npcData .entityList .put ("VEX" , EntityType .VEX );
319+ npcData .entityList .put ("VILLAGER" , EntityType .VILLAGER );
320+ npcData .entityList .put ("VINDICATOR" , EntityType .VINDICATOR );
321+ npcData .entityList .put ("WANDERING_TRADER" , EntityType .WANDERING_TRADER );
322+ npcData .entityList .put ("WARDEN" , EntityType .WARDEN );
323+ npcData .entityList .put ("WIND_CHARGE" , EntityType .WIND_CHARGE );
324+ npcData .entityList .put ("WITCH" , EntityType .WITCH );
325+ npcData .entityList .put ("WITHER" , EntityType .WITHER );
326+ npcData .entityList .put ("WITHER_SKELETON" , EntityType .WITHER_SKELETON );
327+ npcData .entityList .put ("WITHER_SKULL" , EntityType .WITHER_SKULL );
328+ npcData .entityList .put ("WOLF" , EntityType .WOLF );
329+ npcData .entityList .put ("ZOGLIN" , EntityType .ZOGLIN );
330+ npcData .entityList .put ("ZOMBIE" , EntityType .ZOMBIE );
331+ npcData .entityList .put ("ZOMBIE_HORSE" , EntityType .ZOMBIE_HORSE );
332+ npcData .entityList .put ("ZOMBIE_VILLAGER" , EntityType .ZOMBIE_VILLAGER );
333+ npcData .entityList .put ("ZOMBIFIED_PIGLIN" , EntityType .ZOMBIFIED_PIGLIN );
334+ }
335+
336+ }
337+
338+ public void modEntity (String entType ) {
339+ this .npcData .playerEntity .put ("Entity" , entType );
185340 }
341+
186342
187343 /**
188344 * Creates default taterzen attributes.
@@ -822,6 +978,30 @@ public void readAdditionalSaveData(CompoundTag tag) {
822978 this .setAllowSwimming (npcTag .getBoolean ("AllowSwimming" ));
823979 // --------------------------------------------------------------
824980
981+
982+ // This magic is where we check on loading in whether the NPC has a different TYPE to what is expected
983+ // Normally, it will default to PLAYER, but we want the TYPE changes to be persistent
984+ // The logger is pushing details to the minecraft log so you can see it actually parsing things
985+
986+ getLogger ("Taterzens" ).info ("[Taterzens]: Out of interest, the Tag Entity is {}." , npcTag .get ("Entity" ));
987+
988+ if (npcTag .contains ("Entity" )) {
989+ // Update it to the current settting
990+ if (npcTag .get ("Entity" ) == null ) {
991+ getLogger ("Taterzens" ).error ("[Taterzens]: In the SaveDataread." );
992+
993+ npcTag .putString ("Entity" , "PLAYER" );
994+ npcData .playerEntity .put ("Entity" , "PLAYER" );
995+ } else {
996+ getLogger ("Taterzens" ).info ("[Taterzens]: We have a valid Entity setting and are putting it in the Tag" );
997+ //
998+ // It's actually this we need to update since we have it stored, and the playerEntity hashmap is what we're using
999+ npcData .playerEntity .put ("Entity" , npcTag .getString ("Entity" ));
1000+ // And we need to override the other setting
1001+ npcTag .putString ("Entity" , npcTag .getString ("Entity" ));
1002+ }
1003+ }
1004+
8251005 this .setMinCommandInteractionTime (npcTag .getLong ("MinCommandInteractionTime" ));
8261006 }
8271007
@@ -929,6 +1109,15 @@ public void addAdditionalSaveData(CompoundTag tag) {
9291109
9301110 npcTag .putLong ("MinCommandInteractionTime" , this .npcData .minCommandInteractionTime );
9311111
1112+
1113+ getLogger ("Taterzens" ).info ("[Taterzens]: The Game is paused or saving. We're setting NPC entity to {}" , npcData .playerEntity .get ("Entity" ));
1114+
1115+ // We take whatever the npc has been changed to and shove it in the tag.
1116+ // Only end up in here on pausing or saving to quit
1117+ if (npcData .playerEntity .get ("Entity" ) != null ) {
1118+ npcTag .putString ("Entity" , npcData .playerEntity .get ("Entity" ));
1119+ }
1120+
9321121 tag .put ("TaterzenNPCTag" , npcTag );
9331122 }
9341123
@@ -1867,7 +2056,8 @@ public void setAllowSwimming(boolean allowSwimming) {
18672056 this .setTag ("AllowSwimming" , allowSwimming );
18682057 }
18692058
1870- private void setTag (String name , boolean value ) {
2059+ // Change this to public, since we want to use it elsewhere
2060+ public void setTag (String name , boolean value ) {
18712061 this .npcData .booleanTags .put (name , value );
18722062 }
18732063
@@ -1883,7 +2073,8 @@ private boolean getTag(String name, boolean defaultValue) {
18832073
18842074 @ Override
18852075 public EntityType <?> getPolymerEntityType (ServerPlayer player ) {
1886- return EntityType .PLAYER ;
2076+ // All that other work for such a pretty little line of code
2077+ return npcData .entityList .get (npcData .playerEntity .get ("Entity" ));
18872078 }
18882079
18892080 @ Override
0 commit comments