MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"make a spaner for a zombie with a bow using forged 19.2"
/* First, create a custom spawner class that extends the AbstractSpawner class and override the getOrCreateEntityInstance method to spawn a zombie with a bow */ public class ZombieBowSpawner extends AbstractSpawner { public ZombieBowSpawner(ServerLevel level) { super(level); } @Override protected Optional<Entity> getOrCreateEntityInstance() { Zombie zombie = EntityType.ZOMBIE.create(level); if (zombie != null) { zombie.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.BOW)); zombie.setPersistenceRequired(); } return Optional.ofNullable(zombie); } } /* Next, create a custom block that contains the spawner and implements the TickableBlockEntity interface to update the spawner every tick */ public class ZombieBowSpawnerBlock extends Block implements EntityBlock { public ZombieBowSpawnerBlock(AbstractBlock.Properties properties) { super(properties); } @Nullable @Override public BlockEntity newBlockEntity(BlockPos pos, BlockState state) { return new ZombieBowSpawnerBlockEntity(pos, state); } } /* Finally, create a custom block entity class that extends BlockEntity and implements TickableBlockEntity to update the spawner every tick */ public class ZombieBowSpawnerBlockEntity extends BlockEntity implements TickableBlockEntity { private final ZombieBowSpawner spawner; public ZombieBowSpawnerBlockEntity(BlockPos pos, BlockState state) { super(BlockEntityTypeInit.ZOMBIE_BOW_SPAWNER_BLOCK_ENTITY.get(), pos, state); this.spawner = new ZombieBowSpawner(level); } @Override public void tick() { if (level != null && !level.isClientSide) { spawner.tick(); } } }