I am trying to spawn a warden, which works, but it instantly despawns. Any reasons why?
https://sourceb.in/fm7N8X2rGF
#Warden keeps despawning
18 messages · Page 1 of 1 (latest)
What do you mean by despawn?
@chilly owl the code works with husks, but not wardens 😭
Probably because the warden brain isn't updated
@elfin glacier I got the warden to not despawn but it doesn't target the lastHit
@elfin glacier fixed targeting lol
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
ItemStack stack = user.getStackInHand(hand);
user.setCurrentHand(hand);
if (world.isClient()) {
return TypedActionResult.pass(stack);
}
this.player = user;
WardenEntity protector = EntityType.WARDEN.create(world);
if (lastHit == null || protector == null) {
world.playSound(null, user.getX(), user.getY(), user.getZ(), SoundEvents.BLOCK_BEACON_DEACTIVATE, SoundCategory.PLAYERS, 1.0f, 1.0f);
return TypedActionResult.fail(stack);
}
protector.refreshPositionAndAngles(user.getBlockPos(), user.getYaw(), user.getPitch());
protector.setAiDisabled(false);
protector.getBrain().remember(MemoryModuleType.DIG_COOLDOWN, Unit.INSTANCE, 1200L);
world.spawnEntity(protector);
protector.updateAttackTarget(this.lastHit);
protector.increaseAngerAt(this.lastHit, Angriness.ANGRY.getThreshold() + 20, false);
user.getItemCooldownManager().set(this, COOLDOWN_TICKS);
world.playSound(null, user.getX(), user.getY(), user.getZ(), SoundEvents.BLOCK_BEACON_ACTIVATE, SoundCategory.PLAYERS, 1.0f, 1.0f);
return TypedActionResult.success(user.getStackInHand(hand), true);
}
However it doesn't work on other wardens
Warden works differently so try to do setTarget won't actually work
Why is why your previous method didn't work
Also you needed to make the warden remember its dig cooldown or it would start digging immediately
that's okay
let me test it
works pretty well!!