Skip to content

Commit

Permalink
Implement EntityTag id in spawn eggs (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zailer43 authored Jul 30, 2021
1 parent 6bbeba2 commit 44bc6c2
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;

import java.util.Optional;
import java.util.UUID;

public class SpawnEntityTooltipComponent extends EntityTooltipComponent {
private final Entity entity;
Expand All @@ -59,6 +59,19 @@ public static Optional<TooltipData> of(EntityType<?> entityType, NbtCompound ite
villagerData.putString("type", "minecraft:plains");
itemEntityNbt.put("VillagerData", villagerData);
}
if (itemEntityNbt.contains("id", NbtElement.STRING_TYPE)) {
var id = itemEntityNbt.getString("id");
id = id.replaceAll("[^a-z0-9/._-]", "");
itemEntityNbt.putString("id", id);
Optional<EntityType<?>> entityTypeOptional = EntityType.fromNbt(itemEntityNbt);
if (entityTypeOptional.isPresent()) {
var entity2 = entityTypeOptional.get().create(client.world);
if (entity2 != null) {
entity = entity2;
adjustEntity(entity, itemNbt, entitiesConfig);
}
}
}
var entityTag = entity.writeNbt(new NbtCompound());
var uuid = entity.getUuid();
entityTag.copyFrom(itemEntityNbt);
Expand Down

0 comments on commit 44bc6c2

Please sign in to comment.