IndustrialReborn

IndustrialReborn

150k Downloads

powered spawner spawning from invalid nbt

Linguardium opened this issue ยท 1 comments

commented

Optional<Entity> optionalEntity = EntityType.getEntityFromNbt(entityTag, world);
if (optionalEntity.isEmpty()) return false;
Entity entity = optionalEntity.get();
if (!world.getEntityCollisions(entity, entity.getBoundingBox()).isEmpty()) return false;
if (entity instanceof WardenEntity warden) {
warden.getBrain().remember(MemoryModuleType.DIG_COOLDOWN, null, 1200L);
}
//ent.setPos(spawnX, spawnY, spawnZ);
//entity.setPosition(pos.toCenterPos().add(world.random.nextBetween(-range + 1, range - 1), 0.2, world.random.nextBetween(-range + 1, range - 1)));
entity.setPosition(spawnX, spawnY, spawnZ);
entity.applyRotation(BlockRotation.random(random));
return world.spawnEntity(entity);

getEntityFromNbt is intended to be used for a saved entity in the world or a structure, where it is being recreated from the nbt. Soul vial does not store the entire nbt, only the entity type.

This creates issues with mobs like Orcs from Adventurez, for example.

a better option would be to do a lookup in the registry and spawn using the

create(ServerWorld world, @Nullable NbtCompound itemNbt, @Nullable Consumer<T> afterConsumer, BlockPos pos, SpawnReason reason, boolean alignPosition, boolean invertY)

method call, which calls initialize and other things to ensure the entity is fully set up the way it would have been if spawned naturally.

commented

Thank you for catching this. Wasn't aware this was problematic. Issue should be fixed in efcb74a